pearsonr_ci

mpsci.stats.pearsonr_ci(r, n, alpha, alternative='two-sided')

Confidence interval of Pearson’s correlation coefficient.

This function uses Fisher’s transformation to compute the confidence interval of Pearson’s correlation coefficient.

Examples

Imports:

>>> from mpmath import mp
>>> mp.dps = 20
>>> from mpsci.stats import pearsonr, pearsonr_ci

Sample data:

>>> a = [2, 4, 5, 7, 10, 11, 12, 15, 16, 20]
>>> b = [2.53, 2.41, 3.60, 2.69, 3.19, 4.05, 3.71, 4.65, 4.33, 4.70]

Compute the correlation coefficient:

>>> r, p = pearsonr(a, b)
>>> r
mpf('0.893060379514729854846')
>>> p
mpf('0.00050197523992669206603645')

Compute the 95% confidence interval for r:

>>> rlo, rhi = pearsonr_ci(r, n=len(a), alpha=0.05)
>>> rlo
mpf('0.60185206817708369265664')
>>> rhi
mpf('0.97464778383702233502275')