[][src]Struct average::WeightedMeanWithError

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]

pub fn new() -> WeightedMeanWithError[src]

Create a new weighted and unweighted mean estimator.

pub fn add(&mut self, sample: f64, weight: f64)[src]

Add an observation sampled from the population.

pub fn is_empty(&self) -> bool[src]

Determine whether the sample is empty.

pub fn sum_weights(&self) -> f64[src]

Return the sum of the weights.

Returns 0 for an empty sample.

pub fn sum_weights_sq(&self) -> f64[src]

Return the sum of the squared weights.

Returns 0 for an empty sample.

pub fn weighted_mean(&self) -> f64[src]

Estimate the weighted mean of the population.

Returns 0 for an empty sample.

pub fn unweighted_mean(&self) -> f64[src]

Estimate the unweighted mean of the population.

Returns 0 for an empty sample.

pub fn len(&self) -> u64[src]

Return the sample size.

pub fn effective_len(&self) -> f64[src]

Calculate the effective sample size.

pub 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.

pub fn sample_variance(&self) -> f64[src]

Calculate the unweighted sample variance.

This is an unbiased estimator of the variance of the population.

pub 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 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().collect();
let mut avg_left: WeightedMeanWithError = left.iter().collect();
let avg_right: WeightedMeanWithError = right.iter().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 Debug for WeightedMeanWithError[src]

impl FromIterator<(f64, f64)> for WeightedMeanWithError[src]

impl<'a> FromIterator<&'a (f64, f64)> for WeightedMeanWithError[src]

impl Clone for WeightedMeanWithError[src]

fn clone_from(&mut self, source: &Self)
1.0.0
[src]

Performs copy-assignment from source. Read more

impl Default for WeightedMeanWithError[src]

Auto Trait Implementations

Blanket Implementations

impl<T, U> TryFrom for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T> From for T[src]

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T> BorrowMut for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<Src, Dst> ValueInto for Src where
    Dst: ValueFrom<Src>, 
[src]

type Err = <Dst as ValueFrom<Src>>::Err

The error type produced by a failed conversion.

impl<Dst, Src, Scheme> ApproxInto for Src where
    Dst: ApproxFrom<Src, Scheme>,
    Scheme: ApproxScheme
[src]

type Err = <Dst as ApproxFrom<Src, Scheme>>::Err

The error type produced by a failed conversion.

impl<T, Dst> ConvAsUtil for T[src]

fn approx(self) -> Result<Dst, Self::Err> where
    Self: ApproxInto<Dst, DefaultApprox>, 
[src]

Approximate the subject with the default scheme.

fn approx_by<Scheme>(self) -> Result<Dst, Self::Err> where
    Scheme: ApproxScheme,
    Self: ApproxInto<Dst, Scheme>, 
[src]

Approximate the subject with a specific scheme.

impl<T> ConvUtil for T[src]

fn approx_as<Dst>(self) -> Result<Dst, Self::Err> where
    Self: ApproxInto<Dst, DefaultApprox>, 
[src]

Approximate the subject to a given type with the default scheme.

fn approx_as_by<Dst, Scheme>(self) -> Result<Dst, Self::Err> where
    Scheme: ApproxScheme,
    Self: ApproxInto<Dst, Scheme>, 
[src]

Approximate the subject to a given type with a specific scheme.

fn into_as<Dst>(self) -> Dst where
    Self: Into<Dst>, 
[src]

Convert the subject to a given type.

fn try_as<Dst>(self) -> Result<Dst, Self::Err> where
    Self: TryInto<Dst>, 
[src]

Attempt to convert the subject to a given type.

fn value_as<Dst>(self) -> Result<Dst, Self::Err> where
    Self: ValueInto<Dst>, 
[src]

Attempt a value conversion of the subject to a given type.

impl<Src, Scheme> ApproxFrom for Src where
    Scheme: ApproxScheme
[src]

type Err = NoError

The error type produced by a failed conversion.

impl<Src> ValueFrom for Src[src]

type Err = NoError

The error type produced by a failed conversion.

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<Src> TryFrom for Src[src]

type Err = NoError

The error type produced by a failed conversion.

impl<Src, Dst> TryInto for Src where
    Dst: TryFrom<Src>, 
[src]

type Err = <Dst as TryFrom<Src>>::Err

The error type produced by a failed conversion.