.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/stats/plot_oneWay_Manova_time.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_stats_plot_oneWay_Manova_time.py: ==================================================================== One Way manova time ==================================================================== One way manova to compare Left vs Right in time. .. GENERATED FROM PYTHON SOURCE LINES 8-24 .. code-block:: Python from time import time import numpy as np from pylab import plt import seaborn as sns from mne import Epochs, pick_types, events_from_annotations from mne.io import concatenate_raws from mne.io.edf import read_raw_edf from mne.datasets import eegbci from pyriemann.stats import PermutationDistance from pyriemann.estimation import Covariances sns.set_style('whitegrid') .. GENERATED FROM PYTHON SOURCE LINES 25-27 Set parameters and read data ---------------------------- .. GENERATED FROM PYTHON SOURCE LINES 27-63 .. code-block:: Python # avoid classification of evoked responses by using epochs that start 1s after # cue onset. tmin, tmax = -2., 6. event_id = dict(hands=2, feet=3) subject = 1 runs = [6, 10, 14] # motor imagery: hands vs feet raw_files = [ read_raw_edf(f, preload=True, verbose=False) for f in eegbci.load_data(subject, runs) ] raw = concatenate_raws(raw_files) events, _ = events_from_annotations(raw, event_id=dict(T1=2, T2=3)) picks = pick_types( raw.info, meg=False, eeg=True, stim=False, eog=False, exclude='bads') raw.filter(7., 35., method='iir', picks=picks) epochs = Epochs( raw, events, event_id, tmin, tmax, proj=True, picks=picks, baseline=None, preload=True, verbose=False) labels = epochs.events[:, -1] - 2 # get epochs epochs_data = epochs.get_data(copy=False) .. rst-class:: sphx-glr-script-out .. code-block:: none Used Annotations descriptions: ['T1', 'T2'] Filtering raw data in 3 contiguous segments Setting up band-pass filter from 7 - 35 Hz IIR filter parameters --------------------- Butterworth bandpass zero-phase (two-pass forward and reverse) non-causal filter: - Filter order 16 (effective, after forward-backward) - Cutoffs at 7.00, 35.00 Hz: -6.02, -6.02 dB .. GENERATED FROM PYTHON SOURCE LINES 64-66 Pairwise distance based permutation test ---------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 66-107 .. code-block:: Python covest = Covariances() Fs = 160 window = 2 * Fs Nwindow = 20 Ns = epochs_data.shape[2] step = int((Ns - window) / Nwindow) time_bins = range(0, Ns - window, step) pv = [] Fv = [] # For each frequency bin, estimate the stats t_init = time() for t in time_bins: covmats = covest.fit_transform(epochs_data[:, ::1, t:(t + window)]) p_test = PermutationDistance(1000, metric='riemann', mode='pairwise') p, F = p_test.test(covmats, labels, verbose=False) pv.append(p) Fv.append(F[0]) duration = time() - t_init # plot result fig, axes = plt.subplots(1, 1, figsize=[6, 3], sharey=True) sig = 0.05 times = np.array(time_bins) / float(Fs) + tmin axes.plot(times, Fv, lw=2, c='k') plt.xlabel('Time (sec)') plt.ylabel('Score') a = np.where(np.diff(np.array(pv) < sig))[0] a = a.reshape(int(len(a) / 2), 2) st = (times[1] - times[0]) / 2.0 for p in a: axes.axvspan(times[p[0]] - st, times[p[1]] + st, facecolor='g', alpha=0.5) axes.legend(['Score', 'p<%.2f' % sig]) axes.set_title('Pairwise distance - %.1f sec.' % duration) sns.despine() plt.tight_layout() plt.show() .. image-sg:: /auto_examples/stats/images/sphx_glr_plot_oneWay_Manova_time_001.png :alt: Pairwise distance - 10.7 sec. :srcset: /auto_examples/stats/images/sphx_glr_plot_oneWay_Manova_time_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 11.704 seconds) .. _sphx_glr_download_auto_examples_stats_plot_oneWay_Manova_time.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_oneWay_Manova_time.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_oneWay_Manova_time.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_