[med-svn] [python-mne] 47/52: ENH : add support for ND-array in FDR + Bonferroni
Yaroslav Halchenko
debian at onerussian.com
Fri Nov 27 17:23:49 UTC 2015
This is an automated email from the git hooks/post-receive script.
yoh pushed a commit to annotated tag v0.2
in repository python-mne.
commit 683de5c563018b82cb62f347f5c99f539a157391
Author: Alexandre Gramfort <alexandre.gramfort at inria.fr>
Date: Tue Nov 8 10:58:23 2011 -0500
ENH : add support for ND-array in FDR + Bonferroni
---
mne/stats/multi_comp.py | 8 ++++++--
mne/stats/tests/test_multi_comp.py | 11 ++++++++---
2 files changed, 14 insertions(+), 5 deletions(-)
diff --git a/mne/stats/multi_comp.py b/mne/stats/multi_comp.py
index 3e508c6..60d810a 100644
--- a/mne/stats/multi_comp.py
+++ b/mne/stats/multi_comp.py
@@ -48,6 +48,8 @@ def fdr_correction(pvals, alpha=0.05, method='indep'):
discovery rate. Neuroimage. 2002 Apr;15(4):870-8.
"""
pvals = np.asarray(pvals)
+ shape_init = pvals.shape
+ pvals = pvals.ravel()
pvals_sortind = np.argsort(pvals)
pvals_sorted = pvals[pvals_sortind]
@@ -61,7 +63,7 @@ def fdr_correction(pvals, alpha=0.05, method='indep'):
else:
raise ValueError("Method should be 'indep' and 'negcorr'")
- reject = pvals_sorted < ecdffactor * alpha
+ reject = pvals_sorted < (ecdffactor * alpha)
if reject.any():
rejectmax = max(np.nonzero(reject)[0])
else:
@@ -71,7 +73,9 @@ def fdr_correction(pvals, alpha=0.05, method='indep'):
pvals_corrected_raw = pvals_sorted / ecdffactor
pvals_corrected = np.minimum.accumulate(pvals_corrected_raw[::-1])[::-1]
pvals_corrected[pvals_corrected > 1.0] = 1.0
- return reject[sortrevind], pvals_corrected[sortrevind]
+ pvals_corrected = pvals_corrected[sortrevind].reshape(shape_init)
+ reject = reject[sortrevind].reshape(shape_init)
+ return reject, pvals_corrected
def bonferroni_correction(pval, alpha=0.05):
diff --git a/mne/stats/tests/test_multi_comp.py b/mne/stats/tests/test_multi_comp.py
index 34eb1b5..cd2ee77 100644
--- a/mne/stats/tests/test_multi_comp.py
+++ b/mne/stats/tests/test_multi_comp.py
@@ -10,22 +10,27 @@ def test_multi_pval_correction():
"""Test pval correction for multi comparison (FDR and Bonferroni)
"""
rng = np.random.RandomState(0)
- X = rng.randn(10, 10000)
- X[:, :50] += 4.0 # 50 significant tests
+ X = rng.randn(10, 1000, 10)
+ X[:, :50, 0] += 4.0 # 50 significant tests
alpha = 0.05
T, pval = stats.ttest_1samp(X, 0)
- n_samples, n_tests = X.shape
+ n_samples = X.shape[0]
+ n_tests = X.size / n_samples
thresh_uncorrected = stats.t.ppf(1.0 - alpha, n_samples - 1)
reject_bonferroni, pval_bonferroni = bonferroni_correction(pval, alpha)
thresh_bonferroni = stats.t.ppf(1.0 - alpha / n_tests, n_samples - 1)
+ assert_true(pval_bonferroni.ndim == 2)
+ assert_true(reject_bonferroni.ndim == 2)
fwer = np.mean(reject_bonferroni)
assert_almost_equal(fwer, alpha, 1)
reject_fdr, pval_fdr = fdr_correction(pval, alpha=alpha, method='indep')
+ assert_true(pval_fdr.ndim == 2)
+ assert_true(reject_fdr.ndim == 2)
thresh_fdr = np.min(np.abs(T)[reject_fdr])
assert_true(0 <= (reject_fdr.sum() - 50) <= 50 * 1.05)
assert_true(thresh_uncorrected <= thresh_fdr <= thresh_bonferroni)
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-med/python-mne.git
More information about the debian-med-commit
mailing list