.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/mass-univariate-statistics/sensor-anova.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_mass-univariate-statistics_sensor-anova.py: .. _exa-mu-anova: ANOVA ===== .. currentmodule:: eelbrain This example performs mass-univariate ANOVA using :class:`testnd.ANOVA`. The example shows a 2 x 2 repeated measures ANOVA. For specifying different ANOVA type models see the :class:`test.ANOVA` documentation. The example uses simulated data meant to vaguely resemble data from an N400 experiment (not intended as a physiologically realistic simulation). .. contents:: Contents :local: .. GENERATED FROM PYTHON SOURCE LINES 20-22 .. code-block:: Python from eelbrain import * .. GENERATED FROM PYTHON SOURCE LINES 23-29 Simulated data -------------- Use :func:`datasets.simulate_erp` to generate a dataset simulating an N400 experiment, as in the :ref:`exa-cluster-based-mu` example. Set ``short_long=True`` to simulate word length as a second variable, resulting in a 2 x 2, *predictability* x *word length* design. .. GENERATED FROM PYTHON SOURCE LINES 29-44 .. code-block:: Python s_datasets = [] for subject in range(10): # generate data for one subject s_data = datasets.simulate_erp(seed=subject, short_long=True) # average across trials to get condition means s_data_agg = s_data.aggregate('predictability % length') # add the subject name as variable s_data_agg[:, 'subject'] = f'S{subject:02}' s_datasets.append(s_data_agg) data = combine(s_datasets) # Define subject as random factor (to treat it as random effect in the ANOVA) data['subject'].random = True data.head() .. raw:: html
# n cloze predictability n_chars length subject
0 20 0.87997 high 4.6 short S00
1 20 0.88104 high 8.2 long S00
2 20 0.17447 low 3.6 short S00
3 20 0.17035 low 8.9 long S00
4 20 0.88708 high 3.8 short S01
5 20 0.90223 high 8.4 long S01
6 20 0.11018 low 4.3 short S01
7 20 0.16538 low 8.25 long S01
8 20 0.90949 high 3.95 short S02
9 20 0.89482 high 8.25 long S02
NDVars: eeg


.. GENERATED FROM PYTHON SOURCE LINES 45-46 Re-reference the EEG data (i.e., subtract the mean of the two mastoid channels): .. GENERATED FROM PYTHON SOURCE LINES 46-48 .. code-block:: Python data['eeg'] -= data['eeg'].mean(sensor=['M1', 'M2']) .. GENERATED FROM PYTHON SOURCE LINES 49-53 Plot the data by condition to illustrate the effect. Note 2 effects in the simulation: an early ~130 ms peak determined by word `length`, simulating increased visual processing for longer words; and a later "N400" `predictability` peak, simulated to be larger for more surprising (less predictable) words. .. GENERATED FROM PYTHON SOURCE LINES 53-56 .. code-block:: Python p = plot.TopoButterfly('eeg', 'predictability % length', t=.400, data=data, axh=2, w=8, clip='circle') .. image-sg:: /auto_examples/mass-univariate-statistics/images/sphx_glr_sensor-anova_001.png :alt: sensor anova :srcset: /auto_examples/mass-univariate-statistics/images/sphx_glr_sensor-anova_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 57-63 Spatio-temporal test -------------------- :class:`testnd.ANOVA` provides an interface for mass-univariate ANOVA. The ANOVA function determines whether to perform a repeated measures or fixed effects ANOVA based on the model. Here, ``'predictability * length * subject'`` is a repeated measures ANOVA because we defined ``data['subject']`` as random effect above. Changing the model to ``'predictability * length'`` would perform a fixed effects ANOVA. .. GENERATED FROM PYTHON SOURCE LINES 63-73 .. code-block:: Python result = testnd.ANOVA( 'eeg', 'predictability * length * subject', data=data, pmin=0.05, # Use uncorrected p = 0.05 as threshold for forming clusters tstart=0.050, # Find clusters in the time window from 100 ... tstop=0.600, # ... to 600 ms samples=1000, # smaller number of permutations to speed up the example; use 10'000 when the exact p-value matters ) .. rst-class:: sphx-glr-script-out .. code-block:: none Permutation test: 0%| | 0/1000 [00:00, , ] .. GENERATED FROM PYTHON SOURCE LINES 88-89 Corresponding cluster statistics: .. GENERATED FROM PYTHON SOURCE LINES 89-91 .. code-block:: Python result.find_clusters(0.05) .. raw:: html
# id tstart tstop duration n_sensors v p sig effect
0 3 0.315 0.455 0.14 61 11800 0 *** predictability
1 2 0.075 0.185 0.11 53 12739 0 *** length


.. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 23.424 seconds) .. _sphx_glr_download_auto_examples_mass-univariate-statistics_sensor-anova.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: sensor-anova.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: sensor-anova.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: sensor-anova.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_