Struct average::WeightedMeanWithError
[−]
[src]
pub struct WeightedMeanWithError { /* fields omitted */ }
Estimate the weighted and unweighted arithmetic mean and the unweighted variance of a sequence of numbers ("population").
This can be used to estimate the standard error of the weighted mean.
Example
use average::WeightedMeanWithError; let a: WeightedMeanWithError = (1..6).zip(1..6) .map(|(x, w)| (f64::from(x), f64::from(w))).collect(); println!("The weighted mean is {} ± {}.", a.weighted_mean(), a.error());
Methods
impl WeightedMeanWithError
[src]
fn new() -> WeightedMeanWithError
[src]
Create a new weighted and unweighted mean estimator.
fn add(&mut self, sample: f64, weight: f64)
[src]
Add an observation sampled from the population.
fn is_empty(&self) -> bool
[src]
Determine whether the sample is empty.
fn sum_weights(&self) -> f64
[src]
Return the sum of the weights.
Returns 0 for an empty sample.
fn sum_weights_sq(&self) -> f64
[src]
Return the sum of the squared weights.
Returns 0 for an empty sample.
fn weighted_mean(&self) -> f64
[src]
Estimate the weighted mean of the population.
Returns 0 for an empty sample.
fn unweighted_mean(&self) -> f64
[src]
Estimate the unweighted mean of the population.
Returns 0 for an empty sample.
fn len(&self) -> u64
[src]
Return the sample size.
fn effective_len(&self) -> f64
[src]
Calculate the effective sample size.
fn population_variance(&self) -> f64
[src]
Calculate the unweighted population variance of the sample.
This is a biased estimator of the variance of the population.
fn sample_variance(&self) -> f64
[src]
Calculate the unweighted sample variance.
This is an unbiased estimator of the variance of the population.
fn error(&self) -> f64
[src]
Estimate the standard error of the weighted mean of the population.
Returns 0 if the sum of weights is 0.
This unbiased estimator assumes that the samples were independently drawn from the same population with constant variance.
Trait Implementations
impl Debug for WeightedMeanWithError
[src]
impl Clone for WeightedMeanWithError
[src]
fn clone(&self) -> WeightedMeanWithError
[src]
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl Merge for WeightedMeanWithError
[src]
fn merge(&mut self, other: &WeightedMeanWithError)
[src]
Merge another sample into this one.
Example
use average::{WeightedMeanWithError, Merge}; let weighted_sequence: &[(f64, f64)] = &[ (1., 0.1), (2., 0.2), (3., 0.3), (4., 0.4), (5., 0.5), (6., 0.6), (7., 0.7), (8., 0.8), (9., 0.9)]; let (left, right) = weighted_sequence.split_at(3); let avg_total: WeightedMeanWithError = weighted_sequence.iter().map(|&x| x).collect(); let mut avg_left: WeightedMeanWithError = left.iter().map(|&x| x).collect(); let avg_right: WeightedMeanWithError = right.iter().map(|&x| x).collect(); avg_left.merge(&avg_right); assert!((avg_total.weighted_mean() - avg_left.weighted_mean()).abs() < 1e-15); assert!((avg_total.error() - avg_left.error()).abs() < 1e-15);
impl Default for WeightedMeanWithError
[src]
fn default() -> WeightedMeanWithError
[src]
Returns the "default value" for a type. Read more
impl FromIterator<(f64, f64)> for WeightedMeanWithError
[src]
fn from_iter<T>(iter: T) -> WeightedMeanWithError where
T: IntoIterator<Item = (f64, f64)>,
[src]
T: IntoIterator<Item = (f64, f64)>,
Creates a value from an iterator. Read more