{ "nbformat_minor": 0, "nbformat": 4, "cells": [ { "execution_count": null, "cell_type": "code", "source": [ "%matplotlib inline" ], "outputs": [], "metadata": { "collapsed": false } }, { "source": [ "\n# FDR correction on T-test on sensor data\n\n\nOne tests if the evoked response significantly deviates from 0.\nMultiple comparison problem is addressed with\nFalse Discovery Rate (FDR) correction.\n\n\n" ], "cell_type": "markdown", "metadata": {} }, { "execution_count": null, "cell_type": "code", "source": [ "# Authors: Alexandre Gramfort \n#\n# License: BSD (3-clause)\n\nimport numpy as np\nfrom scipy import stats\nimport matplotlib.pyplot as plt\n\nimport mne\nfrom mne import io\nfrom mne.datasets import sample\nfrom mne.stats import bonferroni_correction, fdr_correction\n\nprint(__doc__)" ], "outputs": [], "metadata": { "collapsed": false } }, { "source": [ "Set parameters\n\n" ], "cell_type": "markdown", "metadata": {} }, { "execution_count": null, "cell_type": "code", "source": [ "data_path = sample.data_path()\nraw_fname = data_path + '/MEG/sample/sample_audvis_filt-0-40_raw.fif'\nevent_fname = data_path + '/MEG/sample/sample_audvis_filt-0-40_raw-eve.fif'\nevent_id, tmin, tmax = 1, -0.2, 0.5\n\n# Setup for reading the raw data\nraw = io.read_raw_fif(raw_fname)\nevents = mne.read_events(event_fname)[:30]\n\nchannel = 'MEG 1332' # include only this channel in analysis\ninclude = [channel]" ], "outputs": [], "metadata": { "collapsed": false } }, { "source": [ "Read epochs for the channel of interest\n\n" ], "cell_type": "markdown", "metadata": {} }, { "execution_count": null, "cell_type": "code", "source": [ "picks = mne.pick_types(raw.info, meg=False, eog=True, include=include,\n exclude='bads')\nevent_id = 1\nreject = dict(grad=4000e-13, eog=150e-6)\nepochs = mne.Epochs(raw, events, event_id, tmin, tmax, picks=picks,\n baseline=(None, 0), reject=reject)\nX = epochs.get_data() # as 3D matrix\nX = X[:, 0, :] # take only one channel to get a 2D array" ], "outputs": [], "metadata": { "collapsed": false } }, { "source": [ "Compute statistic\n\n" ], "cell_type": "markdown", "metadata": {} }, { "execution_count": null, "cell_type": "code", "source": [ "T, pval = stats.ttest_1samp(X, 0)\nalpha = 0.05\n\nn_samples, n_tests = X.shape\nthreshold_uncorrected = stats.t.ppf(1.0 - alpha, n_samples - 1)\n\nreject_bonferroni, pval_bonferroni = bonferroni_correction(pval, alpha=alpha)\nthreshold_bonferroni = stats.t.ppf(1.0 - alpha / n_tests, n_samples - 1)\n\nreject_fdr, pval_fdr = fdr_correction(pval, alpha=alpha, method='indep')\nthreshold_fdr = np.min(np.abs(T)[reject_fdr])" ], "outputs": [], "metadata": { "collapsed": false } }, { "source": [ "Plot\n\n" ], "cell_type": "markdown", "metadata": {} }, { "execution_count": null, "cell_type": "code", "source": [ "times = 1e3 * epochs.times\n\nplt.close('all')\nplt.plot(times, T, 'k', label='T-stat')\nxmin, xmax = plt.xlim()\nplt.hlines(threshold_uncorrected, xmin, xmax, linestyle='--', colors='k',\n label='p=0.05 (uncorrected)', linewidth=2)\nplt.hlines(threshold_bonferroni, xmin, xmax, linestyle='--', colors='r',\n label='p=0.05 (Bonferroni)', linewidth=2)\nplt.hlines(threshold_fdr, xmin, xmax, linestyle='--', colors='b',\n label='p=0.05 (FDR)', linewidth=2)\nplt.legend()\nplt.xlabel(\"Time (ms)\")\nplt.ylabel(\"T-stat\")\nplt.show()" ], "outputs": [], "metadata": { "collapsed": false } } ], "metadata": { "kernelspec": { "display_name": "Python 2", "name": "python2", "language": "python" }, "language_info": { "mimetype": "text/x-python", "nbconvert_exporter": "python", "name": "python", "file_extension": ".py", "version": "2.7.13", "pygments_lexer": "ipython2", "codemirror_mode": { "version": 2, "name": "ipython" } } } }