Struct stats_ci::comparison::Paired

source ·
pub struct Paired<T: Float> { /* private fields */ }
Expand description

Structure to collect statistics on two paired samples.

Paired observations are when each measurement in the first sample is paired with a measurement in the second sample. For instance, when measuring the performance of two algorithms, the same input data is used for both algorithms to yield a pair of related observations.

When observations cannot naturally be paired, the samples must be compared using unpaired observations (see Unpaired). Typically, unpaired observations require noticeably more observations to achieve the same statistical significance.

Examples

The example below considers the zinc concentration in water samples from a river. Each sample is taken at the same location, but one at the bottom of the river and the other at the surface. Thus, those measurements are paired (bottom and surface). See https://online.stat.psu.edu/stat500/lesson/7/7.3/7.3.2 for details on this example.

// Zinc concentration in water samples from a river
let data_bottom_water = [
    0.430, 0.266, 0.567, 0.531, 0.707, 0.716, 0.651, 0.589, 0.469, 0.723,
];
let data_surface_water = [
    0.415, 0.238, 0.390, 0.410, 0.605, 0.609, 0.632, 0.523, 0.411, 0.612,
];

let mut stats = comparison::Paired::default();
stats.extend(data_bottom_water, data_surface_water).unwrap();
let ci = stats.ci_mean(Confidence::new_two_sided(0.95)).unwrap();

References

Implementations§

source§

impl<T: Float> Paired<T>

source

pub fn append_pair(&mut self, data_a: T, data_b: T) -> CIResult<()>

Add a pair of observations to the two samples.

Arguments
  • data_a - the observation for the first sample
  • data_b - the observation for the second sample
Errors
Examples
let mut stats = comparison::Paired::default();
stats.append_pair(1., 2.)?;
source

pub fn extend_tuple<I>(&mut self, iter: I) -> CIResult<()>where I: IntoIterator<Item = (T, T)>,

Append multiple pairs of observations to the two samples.

Arguments
  • iter - an iterable collection of tuples to add to the data
Errors
Examples
let mut stats = comparison::Paired::default();
stats.extend_tuple([(1., 2.), (3., 4.)])?;
source

pub fn extend<I1, I2>(&mut self, data_a: I1, data_b: I2) -> CIResult<()>where I1: IntoIterator<Item = T>, I2: IntoIterator<Item = T>,

Append multiple observations to the two samples.

Arguments
  • data_a - an iterable collection of observations for the first sample
  • data_b - an iterable collection of observations for the second sample
Errors
Examples
let mut stats = comparison::Paired::default();
stats.extend([1., 3.], [2., 4.])?;
source

pub fn sample_mean(&self) -> T

Return the sample mean of the difference between the two samples.

Examples
let data_a = [1., 2., 3.];
let data_b = [4., 5., 6.];
let mut stats = comparison::Paired::default();
stats.extend(data_a, data_b)?;
let mean = stats.sample_mean();
assert_eq!(mean, -3.);
source

pub fn sample_sem(&self) -> T

Return the standard error of the difference between the two samples.

Examples
let data_a = [1., 2., 3.];
let data_b = [4., 5., 6.];
let mut stats = comparison::Paired::default();
stats.extend(data_a, data_b)?;
let sem = stats.sample_sem();
assert_eq!(sem, 0.);
source

pub fn sample_count(&self) -> usize

Return the number of sample pairs.

Examples
let data_a = [1., 2., 3.];
let data_b = [4., 5., 6.];
let mut stats = comparison::Paired::default();
stats.extend(data_a, data_b)?;
let count = stats.sample_count();
assert_eq!(count, 3);
source

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

Return the confidence interval of the difference between the means of the two samples.

Arguments
  • confidence - the confidence level
Returns

The confidence interval of the difference as a result.

Notes

If the interval includes zero, the difference is not significant. If the interval is strictly positive (resp. negative), the mean of the first sample is significantly greater (resp. smaller) than the mean of the second sample.

Examples
let data_a = [1., 2., 3.];
let data_b = [4., 5., 6.];
let mut stats = comparison::Paired::default();
stats.extend(data_a, data_b)?;
let confidence = Confidence::new_two_sided(0.95);
let ci = stats.ci_mean(confidence)?;
assert_eq!(ci, Interval::new(-3., -3.)?);
source

pub fn ci( confidence: Confidence, data_a: &[T], data_b: &[T] ) -> CIResult<Interval<T>>

Compute the confidence interval of the difference between the means of the two samples.

Arguments
  • confidence - the confidence level
  • data_a - the first sample
  • data_b - the second sample
Returns

The confidence interval of the difference as a result.

Errors
Notes

If the interval includes zero, the difference is not significant. If the interval is strictly positive (resp. negative), the mean of the first sample is significantly greater (resp. smaller) than the mean of the second sample.

This function provides a simple interface to obtain the confidence interval with a single call, when the samples are known a priori and there is no need to include additional observations, obtain the confidence intervals for other levels or access the sample statistics. For more refined use cases, it is recommended to use Paired::ci_mean instead.

References
Examples
let data_a = [1., 2., 3.];
let data_b = [4., 5., 6.];
let confidence = Confidence::new_two_sided(0.95);
let ci = comparison::Paired::ci(confidence, &data_a, &data_b)?;

Trait Implementations§

source§

impl<F: Float> Add<Paired<F>> for Paired<F>

§

type Output = Paired<F>

The resulting type after applying the + operator.
source§

fn add(self, rhs: Self) -> Self::Output

Performs the + operation. Read more
source§

impl<F: Float> AddAssign<Paired<F>> for Paired<F>

source§

fn add_assign(&mut self, rhs: Self)

Performs the += operation. Read more
source§

impl<T: Clone + Float> Clone for Paired<T>

source§

fn clone(&self) -> Paired<T>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<T: Debug + Float> Debug for Paired<T>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<T: Float> Default for Paired<T>

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl<T: PartialEq + Float> PartialEq<Paired<T>> for Paired<T>

source§

fn eq(&self, other: &Paired<T>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<T: Float> StructuralPartialEq for Paired<T>

Auto Trait Implementations§

§

impl<T> RefUnwindSafe for Paired<T>where T: RefUnwindSafe,

§

impl<T> Send for Paired<T>where T: Send,

§

impl<T> Sync for Paired<T>where T: Sync,

§

impl<T> Unpin for Paired<T>where T: Unpin,

§

impl<T> UnwindSafe for Paired<T>where T: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same<T> for T

§

type Output = T

Should always be Self
§

impl<SS, SP> SupersetOf<SS> for SPwhere SS: SubsetOf<SP>,

§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

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

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T, Right> ClosedAdd<Right> for Twhere T: Add<Right, Output = T> + AddAssign<Right>,

source§

impl<T> Scalar for Twhere T: 'static + Clone + PartialEq<T> + Debug,