my_code_base.stats.core

Functions

t_statistic(r, dof)

Calculate the t-statistic for a given correlation coefficient and number of effective samples.

tstats_p_value(t, dof)

Calculate the p-value for a given t-statistic and number of degrees of freedom.

Module Contents

my_code_base.stats.core.t_statistic(r, dof)[source]

Calculate the t-statistic for a given correlation coefficient and number of effective samples.

The formula is given by:

\[t_\text{score} = r \cdot \frac{ \sqrt{dof} }{ \sqrt{1 - r^2} } = r \cdot \frac{ \sqrt{n_\text{eff}-2} }{ \sqrt{1 - r^2} }\]

where $r$ is the Pearson correlation coefficient, $dof$ is the number of degrees of freedom, typicallyt he number of effective sample size - 2.

Source: https://en.wikipedia.org/wiki/Student%27s_t-test

Parameters:
r : float

The correlation coefficient.

dof : float

The degrees of freedom. Typically the number of effective samples - 2.

Returns:

The t-statistic.

Return type:

float

my_code_base.stats.core.tstats_p_value(t, dof)[source]

Calculate the p-value for a given t-statistic and number of degrees of freedom.

The formula is given by:

\[\begin{split}f_p &= 2 \cdot (1 - \text{cdf}(t, dof)) \\ &= 2 \cdot \text{sf}(t, dof)\end{split}\]

sf is the survival function of the t-distribution from scipy.stats.t and is equivalent to 1-cdf. The number of degrees of freedom (dof) is typically the number of effective samples - 2.

Parameters:
t : float

The t-statistic.

dof : float

The number of effective samples.

Returns:

The p-value.

Return type:

float