stats_tools.
perm_test
(X, Y, paired=None, useR=False, nperms=10000, tail='two', correction='maxT', get_dist=False, mth='t', verbose=True, fname=None, vars=None, g1str=None, g2str=None)[source]¶Perform permutation tests for paired/unpaired uni-/multi-variate two-sample problems
Parameters: | X : NumPy 2darray
X : NumPy 2darray
paired : bool
useR : bool
nperms : int
tail : str
correction : str
get_dist : bool
mth : str
verbose : bool
fname : str
vars : list or NumPy 1darray
g1str : str
g2str : str
|
---|---|
Returns: | stats_dict : dictionary
|
See also
printstats
flip
mne
Notes
This routine is merely a wrapper and does not do any heavy computational lifting. In case of paired data and useR = False the function permutation_t_test of the MNE package [R14] is called. If the samples are independent (paired = False) or useR = True the R library flip [R13] is loaded. Thus, this routine has a number of dependencies: for paired data at least the Python package mne is required, unpaired samples can only be tested if pandas as well as rpy2 (for R/Python conversion) and, of course, R and the R-library flip are installed (and in the search path). To show/save results the routine printstats (part of this module) is called.
References
[R13] | (1, 2, 3, 4) F. Pesarin. Multivariate Permutation Tests with Applications in Biostatistics. Wiley, New York, 2001. |
[R14] | (1, 2, 3) A. Gramfort, M. Luessi, E. Larson, D. Engemann, D. Strohmeier, C. Brodbeck, L. Parkkonen, M. Haemaelaeinen. MNE software for processing MEG and EEG data. NeuroImage 86, 446-460, 2014 |
Examples
Assume we want to analyze medical data of 200 healthy adult subjects collected before and after physical exercise. For each subject, we have measurements of heart-rate (HR), blood pressure (BP) and body temperature (BT) before and after exercise. Thus our data sets contain 200 observations of 3 variables. We want to test the data for a statistically significant difference in any of the three observed quantities (HR, BP, BT) after physical exercise compared to the measurements acquired before exercise.
Assume all samples are given as Python lists: HR_before, BP_before, BT_before, HR_after, BP_after, BT_after. To be able to use perm_test, we collect the data in NumPy arrays:
>>> import numpy as np
>>> X = np.zeros((200,3))
>>> X[:,0] = HR_before
>>> X[:,1] = BP_before
>>> X[:,2] = BT_before
>>> Y = np.zeros((200,3))
>>> Y[:,0] = HR_after
>>> Y[:,1] = BP_after
>>> Y[:,2] = BT_after
Our null-hypothesis is that physical exercise did not induce a significant change in any of the observed variables. As an alternative hypothesis, we assume that exercise induced an increase in heart rate, blood pressure and body temperature. To test our hypotheses we use the following command
>>> perm_test(X,Y,paired=True,nperms=20000,tail='less',fname='stats.csv',
>>> vars=['Heart Rate','Blood Pressure','Body Temperature'],
>>> g1str='Before Exercise',g2str='After Exercise')
which performs a lower-tailed paired permutation t-test with 20000 permutations, prints the results to the prompt and also saves them in the file stats.csv.