Struct average::WeightedMeanWithError [−][src]
pub struct WeightedMeanWithError { /* fields omitted */ }
Expand description
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());
Implementations
impl WeightedMeanWithError
[src]
impl WeightedMeanWithError
[src]pub fn new() -> WeightedMeanWithError
[src]
pub fn new() -> WeightedMeanWithError
[src]Create a new weighted and unweighted mean estimator.
pub fn sum_weights(&self) -> f64
[src]
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]
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]
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]
pub fn unweighted_mean(&self) -> f64
[src]Estimate the unweighted mean of the population.
Returns 0 for an empty sample.
pub fn effective_len(&self) -> f64
[src]
pub fn effective_len(&self) -> f64
[src]Calculate the effective sample size.
pub fn population_variance(&self) -> f64
[src]
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]
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 variance_of_weighted_mean(&self) -> f64
[src]
pub fn variance_of_weighted_mean(&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.
pub fn error(&self) -> f64
[src]
This is supported on crate features std
or libm
only.
pub fn error(&self) -> f64
[src]std
or libm
only.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 Clone for WeightedMeanWithError
[src]
impl Clone for WeightedMeanWithError
[src]fn clone(&self) -> 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]
fn clone_from(&mut self, source: &Self)
1.0.0[src]Performs copy-assignment from source
. Read more
impl Debug for WeightedMeanWithError
[src]
impl Debug for WeightedMeanWithError
[src]impl Default for WeightedMeanWithError
[src]
impl Default for WeightedMeanWithError
[src]fn default() -> WeightedMeanWithError
[src]
fn default() -> WeightedMeanWithError
[src]Returns the “default value” for a type. Read more
impl<'de> Deserialize<'de> for WeightedMeanWithError
[src]
impl<'de> Deserialize<'de> for WeightedMeanWithError
[src]fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
[src]
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
[src]Deserialize this value from the given Serde deserializer. Read more
impl<'a> FromIterator<&'a (f64, f64)> for WeightedMeanWithError
[src]
impl<'a> FromIterator<&'a (f64, f64)> for WeightedMeanWithError
[src]fn from_iter<T>(iter: T) -> WeightedMeanWithError where
T: IntoIterator<Item = &'a (f64, f64)>,
[src]
fn from_iter<T>(iter: T) -> WeightedMeanWithError where
T: IntoIterator<Item = &'a (f64, f64)>,
[src]Creates a value from an iterator. Read more
impl FromIterator<(f64, f64)> for WeightedMeanWithError
[src]
impl FromIterator<(f64, f64)> for WeightedMeanWithError
[src]fn from_iter<T>(iter: T) -> WeightedMeanWithError where
T: IntoIterator<Item = (f64, f64)>,
[src]
fn from_iter<T>(iter: T) -> WeightedMeanWithError where
T: IntoIterator<Item = (f64, f64)>,
[src]Creates a value from an iterator. Read more
impl Merge for WeightedMeanWithError
[src]
impl Merge for WeightedMeanWithError
[src]fn merge(&mut self, other: &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 Serialize for WeightedMeanWithError
[src]
impl Serialize for WeightedMeanWithError
[src]Auto Trait Implementations
impl RefUnwindSafe for WeightedMeanWithError
impl Send for WeightedMeanWithError
impl Sync for WeightedMeanWithError
impl Unpin for WeightedMeanWithError
impl UnwindSafe for WeightedMeanWithError
Blanket Implementations
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]pub fn borrow_mut(&mut self) -> &mut T
[src]
pub fn borrow_mut(&mut self) -> &mut T
[src]Mutably borrows from an owned value. Read more
impl<S, T> CastFloat<T> for S where
T: ConvFloat<S>,
[src]
impl<S, T> CastFloat<T> for S where
T: ConvFloat<S>,
[src]pub fn cast_trunc(self) -> T
[src]
pub fn cast_trunc(self) -> T
[src]Cast to integer, truncating Read more
pub fn cast_nearest(self) -> T
[src]
pub fn cast_nearest(self) -> T
[src]Cast to the nearest integer Read more
pub fn cast_floor(self) -> T
[src]
pub fn cast_floor(self) -> T
[src]Cast the floor to an integer Read more
pub fn try_cast_trunc(self) -> Result<T, Error>
[src]
pub fn try_cast_trunc(self) -> Result<T, Error>
[src]Try converting to integer with truncation Read more
pub fn try_cast_nearest(self) -> Result<T, Error>
[src]
pub fn try_cast_nearest(self) -> Result<T, Error>
[src]Try converting to the nearest integer Read more
pub fn try_cast_floor(self) -> Result<T, Error>
[src]
pub fn try_cast_floor(self) -> Result<T, Error>
[src]Try converting the floor to an integer Read more
pub fn try_cast_ceil(self) -> Result<T, Error>
[src]
pub fn try_cast_ceil(self) -> Result<T, Error>
[src]Try convert the ceiling to an integer Read more
impl<T> Pointable for T
impl<T> Pointable for T
impl<T> ToOwned for T where
T: Clone,
[src]
impl<T> ToOwned for T where
T: Clone,
[src]type Owned = T
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn to_owned(&self) -> T
[src]Creates owned data from borrowed data, usually by cloning. Read more
pub fn clone_into(&self, target: &mut T)
[src]
pub fn clone_into(&self, target: &mut T)
[src]🔬 This is a nightly-only experimental API. (toowned_clone_into
)
recently added
Uses borrowed data to replace owned data, usually by cloning. Read more
impl<T> DeserializeOwned for T where
T: for<'de> Deserialize<'de>,
[src]
T: for<'de> Deserialize<'de>,