netneurotools.stats.permtest_pearsonr

netneurotools.stats.permtest_pearsonr(a, b, axis=0, n_perm=1000, resamples=None, seed=0)[source]

Non-parametric equivalent of scipy.stats.pearsonr().

Generates two-tailed p-value for hypothesis of whether samples a and b are correlated using permutation tests

Parameters:
  • a ((N[, M]) array_like) – Sample observations. These arrays must have the same length and either an equivalent number of columns or be broadcastable

  • b ((N[, M]) array_like) – Sample observations. These arrays must have the same length and either an equivalent number of columns or be broadcastable

  • axis (int or None, optional) – Axis along which to compute test. If None, compute over whole arrays of a and b. Default: 0

  • n_perm (int, optional) – Number of permutations to assess. Unless a and b are very small along axis this will approximate a randomization test via Monte Carlo simulations. Default: 1000

  • resamples ((N, P) array_like, optional) – Resampling array used to shuffle a when generating null distribution of correlations. This array must have the same length as a and b and should have at least the same number of columns as n_perm (if it has more then only n_perm columns will be used. When not specified a standard permutation is used to shuffle a. Default: None

  • seed ({int, np.random.RandomState instance, None}, optional) – Seed for random number generation. Set to None for “randomness”. Default: 0

Returns:

  • corr (float or numpyndarray) – Correlations

  • pvalue (float or numpy.ndarray) – Non-parametric p-value

Notes

The lowest p-value that can be returned by this function is equal to 1 / (n_perm + 1).

Examples

>>> from netneurotools import datasets, stats
>>> np.random.seed(12345678)  # set random seed for reproducible results
>>> x, y = datasets.make_correlated_xy(corr=0.1, size=100)
>>> stats.permtest_pearsonr(x, y)  
(0.10032564626876286, 0.3046953046953047)
>>> x, y = datasets.make_correlated_xy(corr=0.5, size=100)
>>> stats.permtest_pearsonr(x, y)  
(0.500040365781984, 0.000999000999000999)

Also works with multiple columns by either broadcasting the smaller array to the larger:

>>> z = x + np.random.normal(loc=1, size=100)
>>> stats.permtest_pearsonr(x, np.column_stack([y, z]))
(array([0.50004037, 0.25843187]), array([0.000999  , 0.01098901]))

or by using matching columns in the two arrays (e.g., x and y vs a and b):

>>> a, b = datasets.make_correlated_xy(corr=0.9, size=100)
>>> stats.permtest_pearsonr(np.column_stack([x, a]), np.column_stack([y, b]))
(array([0.50004037, 0.89927523]), array([0.000999, 0.000999]))

Examples using netneurotools.stats.permtest_pearsonr

Non-parametric significance testing with permutations

Non-parametric significance testing with permutations