netneurotools.stats.efficient_pearsonr
- netneurotools.stats.efficient_pearsonr(a, b, ddof=1, nan_policy='propagate')[source]
Compute correlation of matching columns in a and b.
- Parameters:
a,b (array_like) – Sample observations. These arrays must have the same length and either an equivalent number of columns or be broadcastable
ddof (int, optional) – Degrees of freedom correction in the calculation of the standard deviation. Default: 1
nan_policy (bool, optional) – Defines how to handle when input contains nan. ‘propagate’ returns nan, ‘raise’ throws an error, ‘omit’ performs the calculations ignoring nan values. Default: ‘propagate’
- Returns:
corr (float or numpy.ndarray) – Pearson’s correlation coefficient between matching columns of inputs
pval (float or numpy.ndarray) – Two-tailed p-values
Notes
If either input contains nan and nan_policy is set to ‘omit’, both arrays will be masked to omit the nan entries.
Examples
>>> from netneurotools import stats
Generate some not-very-correlated and some highly-correlated data:
>>> np.random.seed(12345678) # set random seed for reproducible results >>> x1, y1 = stats.make_correlated_xy(corr=0.1, size=100) >>> x2, y2 = stats.make_correlated_xy(corr=0.8, size=100)
Calculate both correlations simultaneously:
>>> stats.efficient_pearsonr(np.c_[x1, x2], np.c_[y1, y2]) (array([0.10032565, 0.79961189]), array([3.20636135e-01, 1.97429944e-23]))