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.
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());
Create a new weighted and unweighted mean estimator.
Add an observation sampled from the population.
Determine whether the sample is empty.
Return the sum of the weights.
Returns 0 for an empty sample.
Return the sum of the squared weights.
Returns 0 for an empty sample.
Estimate the weighted mean of the population.
Returns 0 for an empty sample.
Estimate the unweighted mean of the population.
Returns 0 for an empty sample.
Calculate the effective sample size.
Calculate the unweighted population variance of the sample.
This is a biased estimator of the variance of the population.
Calculate the unweighted sample variance.
This is an unbiased estimator of the variance of the population.
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.
Merge another sample into this one.
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);
Formats the value using the given formatter. Read more
Performs copy-assignment from source
. Read more
Returns the "default value" for a type. Read more
🔬 This is a nightly-only experimental API. (try_from
)
The type returned in the event of a conversion error.
🔬 This is a nightly-only experimental API. (try_from
)
🔬 This is a nightly-only experimental API. (try_from
)
The type returned in the event of a conversion error.
🔬 This is a nightly-only experimental API. (try_from
)
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more
🔬 This is a nightly-only experimental API. (get_type_id
)
this method will likely be replaced by an associated static
Approximate the subject to a given type with the default scheme.
Approximate the subject to a given type with a specific scheme.
Convert the subject to a given type.
Attempt to convert the subject to a given type.
Attempt a value conversion of the subject to a given type.
The error type produced by a failed conversion.
Convert the subject into an approximately equivalent representation.
The error type produced by a failed conversion.
Convert the subject into an exactly equivalent representation.
The error type produced by a failed conversion.
Convert the given value into an exactly equivalent representation.
The error type produced by a failed conversion.
Convert the given value into an approximately equivalent representation.
Approximate the subject with the default scheme.
Approximate the subject with a specific scheme.
Creates owned data from borrowed data, usually by cloning. Read more
🔬 This is a nightly-only experimental API. (toowned_clone_into
)
recently added
Uses borrowed data to replace owned data, usually by cloning. Read more
The error type produced by a failed conversion.
Convert the given value into the subject type.
The error type produced by a failed conversion.
Convert the subject into the destination type.