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>

source

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 analysis
  • num_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
source

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.

source

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>

source§

fn clone(&self) -> PearsonCorrelation<F>

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<F: Debug> Debug for PearsonCorrelation<F>

source§

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

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

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§

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

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

impl<F: PartialEq> PartialEq for PearsonCorrelation<F>

source§

fn eq(&self, other: &PearsonCorrelation<F>) -> 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<F: Eq> Eq for PearsonCorrelation<F>

source§

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> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where 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.

§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

impl<SS, SP> SupersetOf<SS> for SP
where 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).
§

unsafe 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 T
where 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> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for T
where 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 T
where 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 T
where V: MultiLane<T>,

§

fn vzip(self) -> V