pearsonr¶
- mpsci.stats.pearsonr(x, y, alternative='two-sided')¶
Pearson’s correlation coefficient.
Returns the correlation coefficient r and the p-value.
x and y must be one-dimensional sequences with the same lengths.
The function assumes all the values in x and y are finite (no inf, no nan).
Examples
>>> from mpsci.stats import pearsonr >>> from mpmath import mp >>> mp.dps = 25 >>> x = [1, 2, 3, 5, 8, 10] >>> y = [0.25, 2, 2, 2.5, 2.4, 5.5]
Compute the correlation coefficent and p-value.
>>> r, p = pearsonr(x, y) >>> r mpf('0.8645211772786436751458124677') >>> p mpf('0.02628844331049414042317641803')
Compute a one-sided p-value. The correlation coefficient is the same; only the p-value is different.
>>> r, p = pearsonr(x, y, alternative='greater') >>> r mpf('0.8645211772786436751458124677') >>> p mpf('0.01314422165524707021158820901')