Analysing continuous features with binning and regression in sensor space

Predict single trial activity from a continuous variable. A single-trial regression is performed in each sensor and timepoint individually, resulting in an mne.Evoked object which contains the regression coefficient (beta value) for each combination of sensor and timepoint. Example shows the regression coefficient; the t and p values are also calculated automatically.

Here, we repeat a few of the analyses from [1] by accessing the metadata object, which contains word-level information about various psycholinguistically relevant features of the words for which we have EEG activity.

For the general methodology, see e.g. [2]

References

[1]Dufau, S., Grainger, J., Midgley, KJ., Holcomb, PJ. A thousand words are worth a picture: Snapshots of printed-word processing in an event-related potential megastudy. Psychological Science, 2015
[2]Hauk et al. The time course of visual word recognition as revealed by linear regression analysis of ERP data. Neuroimage, 2006
# Authors: Tal Linzen <linzen@nyu.edu>
#          Denis A. Engemann <denis.engemann@gmail.com>
#          Jona Sassenhagen <jona.sassenhagen@gmail.com>
#
# License: BSD (3-clause)

import pandas as pd
import mne
from mne.stats import linear_regression, fdr_correction
from mne.viz import plot_compare_evokeds
from mne.datasets import kiloword

# Load the data
path = kiloword.data_path() + '/kword_metadata-epo.fif'
epochs = mne.read_epochs(path)
print(epochs.metadata.head())

Out:

Reading /home/circleci/mne_data/MNE-kiloword-data/kword_metadata-epo.fif ...
Isotrak not found
    Found the data of interest:
        t =    -100.00 ...     920.00 ms
        0 CTF compensation matrices available
960 matching events found
No baseline correction applied
960 matching events found
No baseline correction applied
Adding metadata with 8 columns
0 projection items activated
   WORD  Concreteness  WordFrequency  OrthographicDistance  NumberOfLetters  \
0  film          5.45       3.189490                  1.75              4.0
1  cent          5.90       3.700704                  1.35              4.0
2  shot          4.60       2.858537                  1.20              4.0
3  cold          3.70       3.454540                  1.15              4.0
4  main          3.00       3.539076                  1.35              4.0

   BigramFrequency  ConsonantVowelProportion  VisualComplexity
0           343.25                      0.75         55.783710
1           546.75                      0.75         63.141553
2           484.75                      0.75         64.600033
3          1095.25                      0.75         63.657457
4           686.00                      0.50         68.945661

Psycholinguistically relevant word characteristics are continuous. I.e., concreteness or imaginability is a graded property. In the metadata, we have concreteness ratings on a 5-point scale. We can show the dependence of the EEG on concreteness by dividing the data into bins and plotting the mean activity per bin, color coded.

name = "Concreteness"
df = epochs.metadata
df[name] = pd.cut(df[name], 11, labels=False) / 10
colors = {str(val): val for val in df[name].unique()}
epochs.metadata = df.assign(Intercept=1)  # Add an intercept for later
evokeds = {val: epochs[name + " == " + val].average() for val in colors}
plot_compare_evokeds(evokeds, colors=colors, split_legend=True,
                     cmap=(name + " Percentile", "viridis"))
../../_images/sphx_glr_plot_sensor_regression_001.png

Out:

Replacing existing metadata with 9 columns
No picks, plotting the GFP ...
Float colors detected, mapping to percentiles ...

We observe that there appears to be a monotonic dependence of EEG on concreteness. We can also conduct a continuous analysis: single-trial level regression with concreteness as a continuous (although here, binned) feature. We can plot the resulting regression coefficient just like an Event-related Potential.

names = ["Intercept", name]
res = linear_regression(epochs, epochs.metadata[names], names=names)
for cond in names:
    res[cond].beta.plot_joint(title=cond, ts_args=dict(time_unit='s'),
                              topomap_args=dict(time_unit='s'))
  • ../../_images/sphx_glr_plot_sensor_regression_002.png
  • ../../_images/sphx_glr_plot_sensor_regression_003.png

Out:

Fitting linear model to epochs, (7424 targets, 2 regressors)
Done

Because the linear_regression function also estimates p values, we can – after applying FDR correction for multiple comparisons – also visualise the statistical significance of the regression of word concreteness. The mne.viz.plot_evoked_image() function takes a mask parameter. If we supply it with a boolean mask of the positions where we can reject the null hypothesis, points that are not significant will be shown transparently, and if desired, in a different colour palette and surrounded by dark contour lines.

reject_H0, fdr_pvals = fdr_correction(res["Concreteness"].p_val.data)
evoked = res["Concreteness"].beta
evoked.plot_image(mask=reject_H0, time_unit='s')
../../_images/sphx_glr_plot_sensor_regression_004.png

Total running time of the script: ( 0 minutes 3.911 seconds)

Gallery generated by Sphinx-Gallery