Skip to content

Commit

Permalink
Configure t-test sigma value through the CONFIG
Browse files Browse the repository at this point in the history
  • Loading branch information
EtienneCmb committed Oct 20, 2020
1 parent 78f99b8 commit 5d7ba9f
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 8 deletions.
11 changes: 11 additions & 0 deletions docs/source/refs.bib
Expand Up @@ -128,4 +128,15 @@ @article{ding2006granger
author={Ding, Mingzhou and Chen, Yonghong and Bressler, SL},
journal={Handbook of Time Series Analysis [Internet]. Wiley, Wienheim},
year={2006}
}

@article{ridgway2012problem,
title={The problem of low variance voxels in statistical parametric mapping; a new hat avoids a ‘haircut’},
author={Ridgway, Gerard R and Litvak, Vladimir and Flandin, Guillaume and Friston, Karl J and Penny, Will D},
journal={Neuroimage},
volume={59},
number={3},
pages={2131--2141},
year={2012},
publisher={Elsevier}
}
7 changes: 7 additions & 0 deletions frites/config.py
Expand Up @@ -57,3 +57,10 @@
'R_PFrd', 'R_PFrm', 'R_OFCvl', 'R_OFCv', 'R_OFCvm', 'R_PFCvm', 'R_ACC',
'R_Insula', 'L_Thal', 'L_Cd', 'L_Put', 'L_GP', 'L_Hipp', 'L_Amyg', 'L_NAc',
'R_Thal', 'R_Cd', 'R_Put', 'R_GP', 'R_Hipp', 'R_Amyg', 'R_NAc']


"""
Default sigma for the hat correction when performing the t-test using
MNE-Python
"""
CONFIG['TTEST_MNE_SIGMA'] = 0.001
23 changes: 16 additions & 7 deletions frites/stats/stats_param.py
Expand Up @@ -12,7 +12,7 @@
trimmed=lambda x, axis=0: trim_mean(x, .2, axis=axis))


def ttest_1samp(x, pop_mean, axis=0, method='mne'):
def ttest_1samp(x, pop_mean, axis=0, method='mne', sigma=0.001):
"""One-sample t-test.
Parameters
Expand All @@ -25,11 +25,17 @@ def ttest_1samp(x, pop_mean, axis=0, method='mne'):
Axis along which to perform the t-test
method : {'mne', 'scipy'}
Use either the scipy or the mne t-test
sigma : float | 0.001
Hat adjustment method, a value of 1e-3 may be a reasonable choice
Returns
-------
tvalues : array_like
Array of t-values
References
----------
Ridgway et al., 2012 :cite:`ridgway2012problem`
"""
if method == 'scipy':
from scipy.stats import ttest_1samp as sp_ttest
Expand All @@ -38,7 +44,7 @@ def fcn(x, pop_mean, axis): # noqa
elif method == 'mne':
from mne.stats import ttest_1samp_no_p as mne_ttest
def fcn(x, pop_mean, axis): # noqa
return mne_ttest(np.moveaxis(x, axis, 0) - pop_mean, sigma=1e-3)
return mne_ttest(np.moveaxis(x, axis, 0) - pop_mean, sigma=sigma)

return fcn(x, pop_mean, axis)

Expand Down Expand Up @@ -97,13 +103,16 @@ def rfx_ttest(mi, mi_p, center=False, zscore=False, ttested=False):
# get the mean of surrogates
_merge_perm = np.r_[tuple([mi_p[k].ravel() for k in range(n_roi)])]
pop_mean_surr = np.mean(_merge_perm)
logger.info(f" T-test across subjects (pop_mean={pop_mean_surr}; "
f"center={center}; zscore={zscore})")
# perform the one sample t-test against the mean both on the true and
# permuted mi
t_obs = np.stack([ttest_1samp(mi[k], pop_mean_surr) for k in range(n_roi)])
t_obs_surr = np.stack([ttest_1samp(mi_p[k], pop_mean_surr,
axis=1) for k in range(n_roi)])
from frites.config import CONFIG
kw = dict(method='mne', sigma=CONFIG['TTEST_MNE_SIGMA'])
logger.info(f" T-test across subjects (pop_mean={pop_mean_surr}; "
f"center={center}; zscore={zscore}; sigma={kw['sigma']})")
t_obs = np.stack([ttest_1samp(
mi[k], pop_mean_surr, axis=0, **kw) for k in range(n_roi)])
t_obs_surr = np.stack([ttest_1samp(
mi_p[k], pop_mean_surr, axis=1, **kw) for k in range(n_roi)])
t_obs_surr = np.swapaxes(t_obs_surr, 0, 1)

return t_obs, t_obs_surr, pop_mean_surr
4 changes: 3 additions & 1 deletion frites/workflow/wf_stats_ephy.py
Expand Up @@ -128,7 +128,9 @@ def fit(self, effect, perms, inference='rfx', mcp='cluster', tail=1,
assert rfx_suj, "For RFX, `n_subjects` should be > 1"
# modelise how subjects are distributed
es, es_p, pop_mean = rfx_ttest(effect, perms)
self.update_cfg(ttest_pop_mean=pop_mean)
from frites.config import CONFIG
sigma = CONFIG['TTEST_MNE_SIGMA']
self.update_cfg(ttest_pop_mean=pop_mean, ttest_sigma=sigma)
tvalues = es

# ---------------------------------------------------------------------
Expand Down

0 comments on commit 5d7ba9f

Please sign in to comment.