Struct linfa::correlation::PearsonCorrelation
source · pub struct PearsonCorrelation<F> { /* private fields */ }
Expand description
Pearson Correlation Coefficients (or Bivariate Coefficients)
The PCCs indicate the linear correlation between variables. This type also supports printing the PCC as an upper triangle matrix together with the feature names.
Implementations§
source§impl<F: Float> PearsonCorrelation<F>
impl<F: Float> PearsonCorrelation<F>
sourcepub fn from_dataset<D: Data<Elem = F>, T>(
dataset: &DatasetBase<ArrayBase<D, Ix2>, T>,
num_iter: Option<usize>
) -> Self
pub fn from_dataset<D: Data<Elem = F>, T>( dataset: &DatasetBase<ArrayBase<D, Ix2>, T>, num_iter: Option<usize> ) -> Self
Calculate the Pearson Correlation Coefficients and optionally p-values from dataset
The PCC describes the linear correlation between two variables. It is the covariance divided by the product of the standard deviations, therefore essentially a normalised measurement of the covariance and in range (-1, 1). A negative coefficient indicates a negative correlation between both variables.
The p-value supports or reject the null hypthesis that two variables are not correlated. A small p-value indicates a strong evidence that two variables are correlated.
§Parameters
dataset
: Data for the correlation analysisnum_iter
: optionally number of iterations of the p-value test, if none then no p-value are calculate
§Example
let corr = linfa_datasets::diabetes()
.pearson_correlation_with_p_value(100);
println!("{}", corr);
The output looks like this (the p-value is in brackets behind the PCC):
age +0.17 (0.61) +0.18 (0.62) +0.33 (0.34) +0.26 (0.47) +0.22 (0.54) -0.07 (0.83) +0.20 (0.60) +0.27 (0.54) +0.30 (0.41)
sex +0.09 (0.74) +0.24 (0.59) +0.04 (0.91) +0.14 (0.74) -0.38 (0.28) +0.33 (0.30) +0.15 (0.74) +0.21 (0.58)
body mass index +0.39 (0.20) +0.25 (0.45) +0.26 (0.51) -0.37 (0.31) +0.41 (0.24) +0.45 (0.21) +0.39 (0.21)
blood pressure +0.24 (0.54) +0.19 (0.56) -0.18 (0.61) +0.26 (0.45) +0.39 (0.20) +0.39 (0.16)
t-cells +0.90 (0.00) +0.05 (0.89) +0.54 (0.05) +0.52 (0.10) +0.33 (0.37)
low-density lipoproteins -0.20 (0.53) +0.66 (0.04) +0.32 (0.42) +0.29 (0.42)
high-density lipoproteins -0.74 (0.02) -0.40 (0.21) -0.27 (0.42)
thyroid stimulating hormone +0.62 (0.04) +0.42 (0.21)
lamotrigine +0.47 (0.14)
blood sugar level
sourcepub fn get_coeffs(&self) -> &Array1<F>
pub fn get_coeffs(&self) -> &Array1<F>
Return the Pearson’s Correlation Coefficients
The coefficients are describing the linear correlation, normalized in range (-1, 1) between two variables. Because the correlation is commutative and PCC to the same variable is always perfectly correlated (i.e. 1), this function only returns the upper triangular matrix with (n-1)*n/2 elements.
sourcepub fn get_p_values(&self) -> Option<&Array1<F>>
pub fn get_p_values(&self) -> Option<&Array1<F>>
Return the p values supporting the null-hypothesis
This implementation estimates the p value with the permutation test. As null-hypothesis the non-correlation between two variables is chosen such that the smaller the p-value the stronger we can reject the null-hypothesis and conclude that they are linearily correlated.
Trait Implementations§
source§impl<F: Clone> Clone for PearsonCorrelation<F>
impl<F: Clone> Clone for PearsonCorrelation<F>
source§fn clone(&self) -> PearsonCorrelation<F>
fn clone(&self) -> PearsonCorrelation<F>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl<F: Debug> Debug for PearsonCorrelation<F>
impl<F: Debug> Debug for PearsonCorrelation<F>
source§impl<F: Float> Display for PearsonCorrelation<F>
impl<F: Float> Display for PearsonCorrelation<F>
Display the Pearson’s Correlation Coefficients as upper triangular matrix
This function prints the feature names for each row, the corresponding PCCs and optionally the p-values in brackets after the PCCs.
source§impl<F: PartialEq> PartialEq for PearsonCorrelation<F>
impl<F: PartialEq> PartialEq for PearsonCorrelation<F>
source§fn eq(&self, other: &PearsonCorrelation<F>) -> bool
fn eq(&self, other: &PearsonCorrelation<F>) -> bool
self
and other
values to be equal, and is used
by ==
.impl<F: Eq> Eq for PearsonCorrelation<F>
impl<F> StructuralPartialEq for PearsonCorrelation<F>
Auto Trait Implementations§
impl<F> RefUnwindSafe for PearsonCorrelation<F>where
F: RefUnwindSafe,
impl<F> Send for PearsonCorrelation<F>where
F: Send,
impl<F> Sync for PearsonCorrelation<F>where
F: Sync,
impl<F> Unpin for PearsonCorrelation<F>
impl<F> UnwindSafe for PearsonCorrelation<F>where
F: RefUnwindSafe,
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
source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.§impl<T> Pointable for T
impl<T> Pointable for 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).§unsafe fn to_subset_unchecked(&self) -> SS
unsafe 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.