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
- R. Jain, The Art of Computer Systems Performance Analysis, Wiley, 1991.
- Wikipedia article on paired difference test
- PennState. Stat 500. Lesson 7: Comparing Two Population Parameters. Online
Implementations§
source§impl<T: Float> Paired<T>
impl<T: Float> Paired<T>
sourcepub fn append_pair(&mut self, data_a: T, data_b: T) -> CIResult<()>
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 sampledata_b- the observation for the second sample
Errors
CIError::FloatConversionError- if the conversion toTfails
Examples
let mut stats = comparison::Paired::default();
stats.append_pair(1., 2.)?;sourcepub fn extend_tuple<I>(&mut self, iter: I) -> CIResult<()>where
I: IntoIterator<Item = (T, T)>,
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
CIError::FloatConversionError- if the conversion toTfails
Examples
let mut stats = comparison::Paired::default();
stats.extend_tuple([(1., 2.), (3., 4.)])?;sourcepub fn extend<I1, I2>(&mut self, data_a: I1, data_b: I2) -> CIResult<()>where
I1: IntoIterator<Item = T>,
I2: IntoIterator<Item = T>,
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 sampledata_b- an iterable collection of observations for the second sample
Errors
CIError::DifferentSampleSizes- if the two iterables have different lengthsCIError::FloatConversionError- if the conversion toTfails
Examples
let mut stats = comparison::Paired::default();
stats.extend([1., 3.], [2., 4.])?;sourcepub fn sample_mean(&self) -> T
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.);sourcepub fn sample_sem(&self) -> T
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.);sourcepub fn sample_count(&self) -> usize
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);sourcepub fn ci_mean(&self, confidence: Confidence) -> CIResult<Interval<T>>
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.)?);sourcepub fn ci(
confidence: Confidence,
data_a: &[T],
data_b: &[T]
) -> CIResult<Interval<T>>
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 leveldata_a- the first sampledata_b- the second sample
Returns
The confidence interval of the difference as a result.
Errors
CIError::DifferentSampleSizes- if the two samples do not have the same length
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
- R. Jain, The Art of Computer Systems Performance Analysis, Wiley, 1991.
- Wikipedia article on paired difference test
- PennState. Stat 500. Lesson 7: Comparing Two Population Parameters. Online
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> AddAssign<Paired<F>> for Paired<F>
impl<F: Float> AddAssign<Paired<F>> for Paired<F>
source§fn add_assign(&mut self, rhs: Self)
fn add_assign(&mut self, rhs: Self)
+= operation. Read moresource§impl<T: PartialEq + Float> PartialEq<Paired<T>> for Paired<T>
impl<T: PartialEq + Float> PartialEq<Paired<T>> for Paired<T>
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere SS: SubsetOf<SP>,
§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read more§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.