netneurotools.stats.permtest_rel

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

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

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

Parameters:
  • a, b (array_like) – Sample observations. These arrays must have the same shape.

  • 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

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

Returns:

  • stat (float or numpy.ndarray) – Average difference between a and b

  • 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 stats
>>> np.random.seed(12345678)  # set random seed for reproducible results
>>> rvs1 = np.random.normal(loc=5, scale=10, size=500)
>>> rvs2 = (np.random.normal(loc=5, scale=10, size=500)
...         + np.random.normal(scale=0.2, size=500))
>>> stats.permtest_rel(rvs1, rvs2)  
(-0.16506275161572695, 0.8021978021978022)
>>> rvs3 = (np.random.normal(loc=8, scale=10, size=500)
...         + np.random.normal(scale=0.2, size=500))
>>> stats.permtest_rel(rvs1, rvs3)  
(2.40533726097883, 0.000999000999000999)

Examples using netneurotools.stats.permtest_rel

Non-parametric significance testing with permutations

Non-parametric significance testing with permutations