pub fn p<T: Ord + Clone>(samples: &[T], proportion: f64) -> T
Expand description
Calculate a one-time proportion for a given sample using the Nearest Rank method and Quick Select.
Note, the p-proportion of an ECDF is the least number, n, for which at least ratio p of the values in the ECDF are less than or equal to n.
This definition means the p-proportion for p between 0 and the ecdf of the lowest value in the sample exists and is the lowest value itself. For instance in [0, 1] all the p-proportions between 0 and .5 are 0 even though 0 is greater than or equal to a larger proportion of the values than each p in (0, 50).
Computational running time of this function is O(n) but does not amortize
across multiple calls like Ecdf<T>::percentile
. This function should only
becused 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 proportion requested must be greater than 0 and less than or equal 1. In particular, there is no 0-proportion.
§Examples
extern crate kernel_density;
let samples = vec!(9, 8, 7, 6, 5, 4, 3, 2, 1, 0);
let percentile = kernel_density::ecdf::p(&samples, 0.5);
assert_eq!(percentile, 4);
let percentile = kernel_density::ecdf::p(&samples, 0.05);
assert_eq!(percentile, 0);