.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/stats/oneWay_Manova_ERP.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note Click :ref:`here ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_stats_oneWay_Manova_ERP.py: ==================================================================== Manova for ERP data ==================================================================== .. GENERATED FROM PYTHON SOURCE LINES 7-31 .. code-block:: default # Authors: Alexandre Barachant # # License: BSD (3-clause) import seaborn as sns from time import time from matplotlib import pyplot as plt import mne from mne import io from mne.datasets import sample from pyriemann.stats import PermutationDistance, PermutationModel from pyriemann.estimation import XdawnCovariances from pyriemann.tangentspace import TangentSpace from sklearn.pipeline import make_pipeline from sklearn.linear_model import LogisticRegression print(__doc__) sns.set_style('whitegrid') data_path = sample.data_path() .. GENERATED FROM PYTHON SOURCE LINES 32-34 Set parameters and read data ############################################################################## .. GENERATED FROM PYTHON SOURCE LINES 34-58 .. code-block:: default raw_fname = data_path + '/MEG/sample/sample_audvis_filt-0-40_raw.fif' event_fname = data_path + '/MEG/sample/sample_audvis_filt-0-40_raw-eve.fif' tmin, tmax = -0., 1 event_id = dict(aud_l=1, aud_r=2, vis_l=3, vis_r=4) # Setup for reading the raw data raw = io.Raw(raw_fname, preload=True) raw.filter(2, None, method='iir') # replace baselining with high-pass events = mne.read_events(event_fname) raw.info['bads'] = ['MEG 2443'] # set bad channels picks = mne.pick_types(raw.info, meg='grad', eeg=False, stim=False, eog=False, exclude='bads') # Read epochs epochs = mne.Epochs(raw, events, event_id, tmin, tmax, proj=False, picks=picks, baseline=None, preload=True, verbose=False) labels = epochs.events[::5, -1] # get epochs epochs_data = epochs.get_data()[::5] n_perms = 100 .. GENERATED FROM PYTHON SOURCE LINES 59-61 Pairwise distance based permutation test ############################################################################## .. GENERATED FROM PYTHON SOURCE LINES 61-75 .. code-block:: default t_init = time() p_test = PermutationDistance(n_perms, metric='riemann', mode='pairwise', estimator=XdawnCovariances(2)) p, F = p_test.test(epochs_data, labels) duration = time() - t_init fig, axes = plt.subplots(1, 1, figsize=[6, 3], sharey=True) p_test.plot(nbins=10, axes=axes) plt.title('Pairwise distance - %.2f sec.' % duration) print('p-value: %.3f' % p) sns.despine() plt.tight_layout() plt.show() .. GENERATED FROM PYTHON SOURCE LINES 76-78 t-test distance based permutation test ############################################################################## .. GENERATED FROM PYTHON SOURCE LINES 78-93 .. code-block:: default t_init = time() p_test = PermutationDistance(n_perms, metric='riemann', mode='ttest', estimator=XdawnCovariances(2)) p, F = p_test.test(epochs_data, labels) duration = time() - t_init fig, axes = plt.subplots(1, 1, figsize=[6, 3], sharey=True) p_test.plot(nbins=10, axes=axes) plt.title('Pairwise distance - %.2f sec.' % duration) print('p-value: %.3f' % p) sns.despine() plt.tight_layout() plt.show() .. GENERATED FROM PYTHON SOURCE LINES 94-96 F-test distance based permutation test ############################################################################## .. GENERATED FROM PYTHON SOURCE LINES 96-111 .. code-block:: default t_init = time() p_test = PermutationDistance(n_perms, metric='riemann', mode='ftest', estimator=XdawnCovariances(2)) p, F = p_test.test(epochs_data, labels) duration = time() - t_init fig, axes = plt.subplots(1, 1, figsize=[6, 3], sharey=True) p_test.plot(nbins=10, axes=axes) plt.title('Pairwise distance - %.2f sec.' % duration) print('p-value: %.3f' % p) sns.despine() plt.tight_layout() plt.show() .. GENERATED FROM PYTHON SOURCE LINES 112-114 Classification based permutation test ############################################################################## .. GENERATED FROM PYTHON SOURCE LINES 114-130 .. code-block:: default clf = make_pipeline(XdawnCovariances(2), TangentSpace('logeuclid'), LogisticRegression()) t_init = time() p_test = PermutationModel(n_perms, model=clf, cv=3) p, F = p_test.test(epochs_data, labels) duration = time() - t_init fig, axes = plt.subplots(1, 1, figsize=[6, 3], sharey=True) p_test.plot(nbins=10, axes=axes) plt.title('Classification - %.2f sec.' % duration) print('p-value: %.3f' % p) sns.despine() plt.tight_layout() plt.show() .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 0.000 seconds) .. _sphx_glr_download_auto_examples_stats_oneWay_Manova_ERP.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: oneWay_Manova_ERP.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: oneWay_Manova_ERP.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_