.. 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-lm.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-lm.py: .. _exa-lm: Multiple regression =================== Multiple regression designs apply to at least two scenarios. - Analyzing a single subject's data when trials are associated with one or multiple continuous variables. - Analyzing group data when subjects are associated with one or multiple individual difference variables. Here the analysis is illustrated for a simulated dataset from a single subject. Group analysis works analogously, except that each case in the datatset would represent a different subject rather than a different trial. For such group analysis, it is necessary to reduce each subject's data to a single case first because multiple regression assumes a fixed effects model. Such designs are described under :ref:`exa-two-stage`. Simulated data -------------- .. GENERATED FROM PYTHON SOURCE LINES 21-28 .. code-block:: Python # sphinx_gallery_thumbnail_number = 2 from eelbrain import * data = datasets.simulate_erp(snr=0.5) data.head() .. raw:: html
# cloze predictability n_chars
0 0.026139 low 4
1 0.99529 high 5
2 0.93062 high 3
3 0.82404 high 7
4 0.17041 low 4
5 0.18508 low 4
6 0.23345 low 4
7 0.80784 high 3
8 0.24979 low 7
9 0.26753 low 4
NDVars: eeg


.. GENERATED FROM PYTHON SOURCE LINES 29-30 The data represents 80 trials from a simulated word reading paradigm, where each word is associated with a word length (`n_chars`) and predictability (`cloze`). .. GENERATED FROM PYTHON SOURCE LINES 30-33 .. code-block:: Python p = plot.Scatter('cloze', 'n_chars', data=data, h=3) .. image-sg:: /auto_examples/mass-univariate-statistics/images/sphx_glr_sensor-lm_001.png :alt: sensor lm :srcset: /auto_examples/mass-univariate-statistics/images/sphx_glr_sensor-lm_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 34-35 Plot the average of each level on `n_chars` to illustrate the linear increase of the response around 130 ms with `n_char`. .. GENERATED FROM PYTHON SOURCE LINES 35-38 .. code-block:: Python p = plot.TopoButterfly('eeg', 'n_chars', data=data, t=.130, axh=2, w=6) .. image-sg:: /auto_examples/mass-univariate-statistics/images/sphx_glr_sensor-lm_002.png :alt: sensor lm :srcset: /auto_examples/mass-univariate-statistics/images/sphx_glr_sensor-lm_002.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 39-45 Multiple regression ------------------- Fit a multiple regression model. Estimate $p$-values using a cluster-based permuatation test, using a cluster-forming threshold of uncorrected $p$=.05. For this example, only 500 permutations are used. When accuracy counts, it is recommended to use 10,000 permutations (the default). .. GENERATED FROM PYTHON SOURCE LINES 45-48 .. code-block:: Python lm = testnd.LM('eeg', 'n_chars + cloze', data=data, tstart=0.050, tstop=0.500, pmin=0.05, samples=500) .. GENERATED FROM PYTHON SOURCE LINES 49-50 A quick plot suggests an early effect related to `n_chars` around 130 ms, and a later effect of `cloze` around 400 ms: .. GENERATED FROM PYTHON SOURCE LINES 50-53 .. code-block:: Python p = plot.TopoButterfly(lm, t=0.130, axh=2, w=6) .. image-sg:: /auto_examples/mass-univariate-statistics/images/sphx_glr_sensor-lm_003.png :alt: sensor lm :srcset: /auto_examples/mass-univariate-statistics/images/sphx_glr_sensor-lm_003.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 54-55 Detailed plots of the two effects show that the cluster is quite variable due to noise in the data. .. GENERATED FROM PYTHON SOURCE LINES 55-59 .. code-block:: Python p = plot.TopoArray(lm.masked_parameter_map('n_chars'), t=[0.110, 0.130, 0.150], title='N Chars') p = plot.TopoArray(lm.masked_parameter_map('cloze'), t=[0.380, 0.400, 0.420], title='Cloze') .. rst-class:: sphx-glr-horizontal * .. image-sg:: /auto_examples/mass-univariate-statistics/images/sphx_glr_sensor-lm_004.png :alt: N Chars :srcset: /auto_examples/mass-univariate-statistics/images/sphx_glr_sensor-lm_004.png :class: sphx-glr-multi-img * .. image-sg:: /auto_examples/mass-univariate-statistics/images/sphx_glr_sensor-lm_005.png :alt: Cloze :srcset: /auto_examples/mass-univariate-statistics/images/sphx_glr_sensor-lm_005.png :class: sphx-glr-multi-img .. GENERATED FROM PYTHON SOURCE LINES 60-61 To access some of the test results we need to know the index of different effects: .. GENERATED FROM PYTHON SOURCE LINES 61-64 .. code-block:: Python lm.effects .. rst-class:: sphx-glr-script-out .. code-block:: none ('intercept', 'n_chars', 'cloze') .. GENERATED FROM PYTHON SOURCE LINES 65-66 Create a plot that shows the spatial cluster extent across time. .. GENERATED FROM PYTHON SOURCE LINES 66-84 .. code-block:: Python EFFECTS = [ ('n_chars', (0.110, 0.150)), ('cloze', (0.380, 0.420)), ] t_maps = [] for effect, time in EFFECTS: # t-maps are retrieved by effect name t = lm.t(effect).mean(time=time) # p-maps are stored in a list, so we need to know the index of te effect index = lm.effects.index(effect) # We are interested in the maximal spatial cluster extent, i.e., any sensor that is part of the cluster at any time p = lm.p[index].min(time=time) # Create a masked average t map t_av = t.mask(p > 0.05) t_maps.append(t_av) p = plot.Topomap(t_maps, columns=2) .. image-sg:: /auto_examples/mass-univariate-statistics/images/sphx_glr_sensor-lm_006.png :alt: n_chars, cloze :srcset: /auto_examples/mass-univariate-statistics/images/sphx_glr_sensor-lm_006.png :class: sphx-glr-single-img .. _sphx_glr_download_auto_examples_mass-univariate-statistics_sensor-lm.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: sensor-lm.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: sensor-lm.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: sensor-lm.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_