bradyrx / esmtools

:octopus: a toolbox for Earth System Model analysis :octopus:
https://esmtools.readthedocs.io/en/latest/
MIT License
27 stars 4 forks source link

Compute critical value for pearson correlation #78

Open bradyrx opened 4 years ago

bradyrx commented 4 years ago

This might fit in xskillscore or climpred, but a useful calculation is the critical correlation coefficient (r) value for a Pearson correlation. This is the value that needs to be reached for statistical significance at a given alpha. It is computed by inverting the t statistic formula:

Screen Shot 2020-02-03 at 1 08 00 PM

A straight-forward approach:

from scipy.stats import t
p = 0.05 # two-tailed significance value
p = p /2 # formula here assuming one-tailed
df = 60
tval = t.ppf(p, df)
r_crit = tval / (np.sqrt(df + tval**2))

This aligns with values reported in various tables: https://www.radford.edu/~jaspelme/statsbook/Chapter%20files/Table_of_Critical_Values_for_r.pdf http://www.mun.ca/biology/scarr/Critical_Values_of_r.htm https://www.statisticssolutions.com/table-of-critical-values-pearson-correlation/