Skip to main content

percentile

Function percentile 

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

Compute percentile using linear interpolation (R-7 method).

This is the default method used by R, NumPy, and Excel. The percentile p should be in the range 0.0 to 1.0.

ยงExample

use codec_eval::stats::percentile;

let values = [1.0, 2.0, 3.0, 4.0, 5.0];
assert!((percentile(&values, 0.5) - 3.0).abs() < 0.001);  // median
assert!((percentile(&values, 0.25) - 2.0).abs() < 0.001); // Q1
assert!((percentile(&values, 0.75) - 4.0).abs() < 0.001); // Q3