pub fn sample_variance(values: &[f64]) -> Result<f64, StatisticsError>Expand description
Returns the sample variance of values using Bessel’s correction.
§Errors
Returns StatisticsError::InsufficientData when fewer than two values are
provided, or StatisticsError::TooManyValues if the slice length cannot
be represented exactly in the internal floating-point count conversion.
Examples found in repository?
examples/basic_usage.rs (line 15)
5fn main() -> Result<(), use_statistics::StatisticsError> {
6 let values = [2.0, 4.0, 4.0, 4.0, 5.0, 5.0, 7.0, 9.0];
7
8 assert!((mean(&values)? - 5.0).abs() < 1.0e-12);
9 assert!((median(&values)? - 4.5).abs() < 1.0e-12);
10 assert!((population_variance(&values)? - 4.0).abs() < 1.0e-12);
11 assert!((population_std_dev(&values)? - 2.0).abs() < 1.0e-12);
12
13 let sample = [1.0, 2.0, 3.0, 4.0];
14
15 assert!((sample_variance(&sample)? - 1.666_666_666_666_666_7).abs() < 1.0e-12);
16 assert!((sample_std_dev(&sample)? - 1.290_994_448_735_805_6).abs() < 1.0e-12);
17
18 Ok(())
19}