Function kolmogorov_smirnov::ecdf::percentile [] [src]

pub fn percentile<T: Ord + Clone>(samples: &[T], p: u8) -> T

Calculate a one-time percentile for a given sample using the Nearest Rank method and Quick Select.

Computational running time of this function is O(n) but does not amortize across multiple calls like Ecdf::percentile. This function should only be used in the case that a small number of percentiles are required for the sample. Otherwise, Ecdf::new should be used to create a structure that takes the upfront O(n log n) sort cost but calculates percentiles in O(1).

Panics

The sample set must be non-empty.

The percentile requested must be between 1 and 100 inclusive. In particular, there is no 0-percentile.

Examples

extern crate kolmogorov_smirnov as ks;

let samples = vec!(9, 8, 7, 6, 5, 4, 3, 2, 1, 0);
let percentile = ks::percentile(&samples, 50);
assert_eq!(percentile, 4);