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

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

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.

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

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

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.

Formats the value using the given formatter. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The resulting type after obtaining ownership.

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

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

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.