pub trait StatisticsOps<F: Float>: Default {
    // Required methods
    fn sample_mean(&self) -> F;
    fn sample_sem(&self) -> F;
    fn sample_count(&self) -> usize;
    fn ci_mean(&self, confidence: Confidence) -> CIResult<Interval<F>>;
    fn append(&mut self, x: F) -> CIResult<()>;
    fn ci<I>(confidence: Confidence, data: I) -> CIResult<Interval<F>>
       where I: IntoIterator<Item = F>;

    // Provided methods
    fn from_iter<I: IntoIterator<Item = F>>(data: I) -> CIResult<Self> { ... }
    fn extend<I: IntoIterator<Item = F>>(&mut self, data: I) -> CIResult<()> { ... }
}
Expand description

Trait for incremental statistics. This trait is implemented for the following statistics:

Example

use stats_ci::*;
let data = [1., 2., 3., 4., 5., 6., 7., 8., 9., 10.];
let stats = mean::Arithmetic::from_iter(data)?;
assert_eq!(stats.sample_count(), 10);
assert_eq!(stats.sample_mean(), 5.5);
assert_abs_diff_eq!(stats.sample_sem(), 1.0092, epsilon = 1e-4);
let confidence = Confidence::new_two_sided(0.95);
let ci = stats.ci_mean(confidence)?;
assert_abs_diff_eq!(ci, Interval::new(3.3341, 7.6659)?, epsilon = 1e-4);

Required Methods§

source

fn sample_mean(&self) -> F

Mean of the sample

Complexity: \( O(1) \)

source

fn sample_sem(&self) -> F

Standard error of the sample mean

Complexity: \( O(1) \)

source

fn sample_count(&self) -> usize

Number of samples

Complexity: \( O(1) \)

source

fn ci_mean(&self, confidence: Confidence) -> CIResult<Interval<F>>

Confidence interval of the sample mean

Complexity: \( O(1) \)

source

fn append(&mut self, x: F) -> CIResult<()>

Append a new sample to the data

Complexity: \( O(1) \)

source

fn ci<I>(confidence: Confidence, data: I) -> CIResult<Interval<F>>where I: IntoIterator<Item = F>,

Compute the confidence interval on the mean of a sample

Arguments
  • confidence - The confidence level of the interval
  • data - The data to compute the confidence interval on
Output
  • Ok(interval) - The confidence interval on the mean of the sample
Errors

Provided Methods§

source

fn from_iter<I: IntoIterator<Item = F>>(data: I) -> CIResult<Self>

Create a new state and “populates” it with data from an iterator

Complexity: \( O(n) \), where \( n \) is the number of elements in data

Arguments
  • data - The data to populate the state with
Errors
Example
use stats_ci::*;
let data = [1., 2., 3., 4., 5., 6., 7., 8., 9., 10.];
let stats = mean::Arithmetic::from_iter(data)?;
assert_eq!(stats.sample_count(), 10);
assert_eq!(stats.sample_mean(), 5.5);
assert_abs_diff_eq!(stats.sample_sem(), 1.0092, epsilon = 1e-4);
Note

This is simply a shortcut for Default::default and Self::extend:

let stats = mean::Arithmetic::new().extend(data)?;
source

fn extend<I: IntoIterator<Item = F>>(&mut self, data: I) -> CIResult<()>

Extend the data with additional sample data.

This is equivalent to calling Self::append for each value in data.

Complexity: \( O(n) \), where \( n \) is the number of elements in data

Arguments
  • data - The data to append as an array or an iterator
Output
  • Ok(()) - If the data was successfully appended
Errors

Implementors§