Skip to main content

trimmed_mean

Function trimmed_mean 

Source
pub fn trimmed_mean(values: &[f64], trim_pct: f64) -> f64
Expand description

Compute trimmed mean (removes top and bottom trim_pct of values).

This provides a robust estimate of central tendency that is less affected by outliers than the arithmetic mean.

§Arguments

  • values - The values to analyze
  • trim_pct - Fraction to trim from each end (e.g., 0.1 = 10% from each end)

§Example

use codec_eval::stats::trimmed_mean;

// Outliers at ends don't affect trimmed mean much
let values = [1.0, 10.0, 11.0, 12.0, 13.0, 100.0];
let tm = trimmed_mean(&values, 0.2);  // Trim 20% from each end
assert!((tm - 11.5).abs() < 0.001);   // Average of middle values