pub fn boxplot_stats<F>(
x: &ArrayView1<'_, F>,
whis: Option<F>,
method: QuantileInterpolation,
) -> StatsResult<(F, F, F, F, F, Vec<F>)>
Expand description
Compute boxplot statistics for a dataset.
Boxplot statistics include the median, quartiles, and whiskers of the data. The whiskers extend to the most extreme data points within a certain range of the box (by default, 1.5 times the interquartile range).
§Arguments
x
- Input datawhis
- Range of whiskers as a factor of the IQR (default 1.5)method
- Interpolation method for quartiles
§Returns
- A tuple containing:
- q1: First quartile
- q2: Median (second quartile)
- q3: Third quartile
- whislo: Lower whisker
- whishi: Upper whisker
- outliers: Array of outliers
§Examples
use ndarray::array;
use scirs2_stats::boxplot_stats;
use scirs2_stats::QuantileInterpolation;
let data = array![1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 20.0]; // Note the outlier
let (q1, q2, q3, whislo, whishi, outliers) =
boxplot_stats(&data.view(), Some(1.5), QuantileInterpolation::Linear).unwrap();
assert_eq!(q1, 3.25); // 25th percentile
assert_eq!(q2, 5.5); // median
assert_eq!(q3, 7.75); // 75th percentile
assert_eq!(whislo, 1.0); // lowest value within 1.5*IQR of Q1
assert_eq!(whishi, 9.0); // highest value within 1.5*IQR of Q3
assert_eq!(outliers[0], 20.0); // outlier beyond the whiskers