非官方中文翻译
本页译自 MNE-Python 官方文档:
查看英文原文 ↗。
文档版权归 MNE Developers 所有(BSD-3-Clause)。
说明
转到末尾下载完整示例代码。
在传感器空间用分箱与回归分析连续特征#
用连续变量预测单试次活动。对每个传感器与时间点分别做单试次回归,得到一个 mne.Evoked 对象,其中包含每个传感器与时间点组合的回归系数(beta 值)。本示例展示回归系数;t 值与 p 值也会自动计算。
这里重复 [1] 中的部分分析。通过访问 metadata 对象即可轻松完成,其中包含与 EEG 活动对应词汇的各种心理语言学相关特征。
一般方法参见 [2]。
# Authors: Tal Linzen <linzen@nyu.edu>
# Denis A. Engemann <denis.engemann@gmail.com>
# Jona Sassenhagen <jona.sassenhagen@gmail.com>
#
# License: BSD-3-Clause
# Copyright the MNE-Python contributors.
import pandas as pd
import mne
from mne.datasets import kiloword
from mne.stats import fdr_correction, linear_regression
from mne.viz import plot_compare_evokeds
# Load the data
path = kiloword.data_path() / "kword_metadata-epo.fif"
epochs = mne.read_epochs(path)
print(epochs.metadata.head())
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
Adding metadata with 8 columns
960 matching events found
No baseline correction applied
0 projection items activated
WORD Concreteness ... ConsonantVowelProportion VisualComplexity
0 film 5.45 ... 0.75 55.783710
1 cent 5.90 ... 0.75 63.141553
2 shot 4.60 ... 0.75 64.600033
3 cold 3.70 ... 0.75 63.657457
4 main 3.00 ... 0.50 68.945661
[5 rows x 8 columns]
心理语言学相关的词汇特征是连续的,例如具体性或可想象性都是程度性属性。metadata 中提供了 5 点量表的具体性评分。将数据分箱并按箱绘制平均活动(用颜色编码),即可展示 EEG 对具体性的依赖关系。
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")
)

Replacing existing metadata with 9 columns
combining channels using GFP (eeg channels)
combining channels using GFP (eeg channels)
combining channels using GFP (eeg channels)
combining channels using GFP (eeg channels)
combining channels using GFP (eeg channels)
combining channels using GFP (eeg channels)
combining channels using GFP (eeg channels)
combining channels using GFP (eeg channels)
combining channels using GFP (eeg channels)
combining channels using GFP (eeg channels)
combining channels using GFP (eeg channels)
可以看到 EEG 似乎随具体性单调变化。我们也可以进行连续分析:以具体性作为连续特征(此处仍按箱处理)做单试次水平回归,并像绘制事件相关电位那样绘制得到的回归系数。
Fitting linear model to epochs, (7424 targets, 2 regressors)
Done
No projector specified for this dataset. Please consider the method self.add_proj.
No projector specified for this dataset. Please consider the method self.add_proj.
由于 linear_regression() 也会估计 p 值,我们可以在对多重比较做 FDR 校正后,进一步可视化词具体性回归的统计显著性。mne.viz.plot_evoked_image() 接受 mask 参数:若传入一个标记可拒绝零假设位置的布尔掩码,不显著的点将以透明方式显示,也可以选择使用不同的配色并用深色等高线包围。
reject_H0, fdr_pvals = fdr_correction(res["Concreteness"].p_val.data)
evoked = res["Concreteness"].beta
evoked.plot_image(mask=reject_H0, time_unit="s")

参考文献#
脚本总运行时间:(0 分 1.922 秒)

