[−][src]Function rv::misc::ks_test
pub fn ks_test<X, F>(xs: &[X], cdf: F) -> (f64, f64) where
X: Copy + PartialOrd,
F: Fn(X) -> f64,
Univariate one-sample Kolmogorov-Smirnov test.
Given a set of samples, xs
, and a distribution F
, the KS test
determines whether xs
were generated by F
.
Example
use rv::prelude::*; use rv::misc::ks_test; let gauss = Gaussian::standard(); let laplace = Laplace::new(0.0, 1.0).unwrap(); let gauss_cdf = |x: f64| gauss.cdf(&x); let laplace_cdf = |x: f64| laplace.cdf(&x); // Generate some samples from the Gaussian let mut rng = rand::thread_rng(); let xs = gauss.sample(1000, &mut rng); // Check the the samples came from the one that generated them let (_, p_gauss) = ks_test(&xs, gauss_cdf); assert!(p_gauss > 0.05); // They did not come from a Laplace let (_, p_laplace) = ks_test(&xs, laplace_cdf); assert!(p_laplace < 0.05);