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
sourceimpl<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
sourceimpl<F: Clone> Clone for PearsonCorrelation<F>
impl<F: Clone> Clone for PearsonCorrelation<F>
sourcefn clone(&self) -> PearsonCorrelation<F>
fn clone(&self) -> PearsonCorrelation<F>
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl<F: Debug> Debug for PearsonCorrelation<F>
impl<F: Debug> Debug for PearsonCorrelation<F>
sourceimpl<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.
sourceimpl<F: PartialEq> PartialEq<PearsonCorrelation<F>> for PearsonCorrelation<F>
impl<F: PartialEq> PartialEq<PearsonCorrelation<F>> for PearsonCorrelation<F>
sourcefn eq(&self, other: &PearsonCorrelation<F>) -> bool
fn eq(&self, other: &PearsonCorrelation<F>) -> bool
This method tests for self
and other
values to be equal, and is used
by ==
. Read more
sourcefn ne(&self, other: &PearsonCorrelation<F>) -> bool
fn ne(&self, other: &PearsonCorrelation<F>) -> bool
This method tests for !=
.
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
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more