Struct average::Average
[−]
[src]
pub struct Average { /* fields omitted */ }
Estimate the arithmetic mean and the variance of a sequence of numbers ("population").
This can be used to estimate the standard error of the mean.
Everything is calculated iteratively using constant memory, so the sequence of numbers can be an iterator. The used algorithms try to avoid numerical instabilities.
Example
use average::Average; let a: Average = (1..6).map(Into::into).collect(); println!("The average is {} ± {}.", a.mean(), a.error());
Methods
impl Average
[src]
fn new() -> Average
Create a new average estimator.
fn add(&mut self, sample: f64)
Add an element sampled from the population.
fn is_empty(&self) -> bool
Determine whether the samples are empty.
fn mean(&self) -> f64
Estimate the mean of the population.
fn len(&self) -> u64
Return the number of samples.
fn sample_variance(&self) -> f64
Calculate the sample variance.
This is an unbiased estimator of the variance of the population.
fn population_variance(&self) -> f64
Calculate the population variance of the sample.
This is a biased estimator of the variance of the population.
fn error(&self) -> f64
Estimate the standard error of the mean of the population.
fn merge(&mut self, other: &Average)
Merge another sample into this one.
Example
use average::Average; let sequence: &[f64] = &[1., 2., 3., 4., 5., 6., 7., 8., 9.]; let (left, right) = sequence.split_at(3); let avg_total: Average = sequence.iter().map(|x| *x).collect(); let mut avg_left: Average = left.iter().map(|x| *x).collect(); let avg_right: Average = right.iter().map(|x| *x).collect(); avg_left.merge(&avg_right); assert_eq!(avg_total.mean(), avg_left.mean()); assert_eq!(avg_total.sample_variance(), avg_left.sample_variance());
Trait Implementations
impl Debug for Average
[src]
impl Clone for Average
[src]
fn clone(&self) -> Average
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0
Performs copy-assignment from source
. Read more
impl Default for Average
[src]
impl FromIterator<f64> for Average
[src]
fn from_iter<T>(iter: T) -> Average where
T: IntoIterator<Item = f64>,
T: IntoIterator<Item = f64>,
Creates a value from an iterator. Read more