{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Evoked potentials/ERPs with MNE"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"
\n",
"Arguably one of the easiest and most common ways to analyse EEG data is to look at evoked/event-related potentials. ERPs are observed for most sensory or cognitive processes. They further may be significantly altered for people suffering from psychological disorders (Sur & Sinha1, 2009). For an overview of different ERPs see e.g. Event Related Potentials (ERP) – Components and Modalities. You can also follow the MNE tutorial: EEG processing and Event Related Potentials (ERPs) and the MNE tutorial on the Evoked data structure, which we'll use to store and manipulate our averaged EEG data.\n",
"\n",
"\n",
"\n",
"\n",
"**As the sample dataset provided by MNE involves the presentation of visual and auditory stimuli, we should be able to observe evoked potentials related to early sensory processing when we look at the average activity in our previously build epochs**. These sensory processess should further be constrained to specific regions in the brain by their modality, therefore we should be able to distinguish between e.g. visual and auditory information processing based on defined regions of interest."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"
\n",
"\n",
"**To calculate Evoked potentials/ERPs we first have to**\n",
"1. clean and subsequently separate the EEG data into epochs\n",
"2. calculate the signal average over epochs based on their condition for each channel\n",
"3. define our regions of interest (roi) (i.e. retain only data from electrodes of interest)\n",
"\n",
"Although steps 2. and 3. can be used interchangably, as it's more efficient to select only a subset of your channels based on the defined regions of interest to average over. To get a better overview of the overall channel activity we'll look at the averaged acitivity for all channels in this chapter.\n",
"\n",
"Afterwards we could use common statistical tools (such as ANOVAs or t-tests) to compare evoked potentials/ERPs based on condition, peak amplitude between conditions etc."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Setup\n",
"\n",
"As in the previous chapter we'll first import our necessary libraries and the sample dataset provided by MNE. "
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"# import necessary libraries/functions\n",
"import os\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"import pandas as pd\n",
"import scipy\n",
"\n",
"# this allows for interactive pop-up plots\n",
"#%matplotlib qt\n",
"\n",
"# allows for rendering in output-cell\n",
"%matplotlib inline\n",
"\n",
"# import mne library\n",
"import mne\n",
"from mne_bids import BIDSPath, write_raw_bids, print_dir_tree, make_report, read_raw_bids"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 1. Preprocessing and epoching"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"
\n",
"\n",
"As we've already preprocessed the sample-dataset and separated the continous raw data into epochs based on stimuli modality in the previous step we'll simply import the prepared Epochs object using the mne.read_epochs() function.\n"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"homedir = os.path.expanduser(\"~\") # find home diretory\n",
"input_path = (homedir + str(os.sep) + 'msc_05_example_bids_dataset' + \n",
" str(os.sep) + 'sub-test' + str(os.sep) + 'ses-001' + str(os.sep) + 'meg')"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Reading /home/michael/msc_05_example_bids_dataset/sub-test/ses-001/meg/sub-test_ses-001_sample_audiovis_eeg_data_epo.fif ...\n",
" Found the data of interest:\n",
" t = -299.69 ... 699.28 ms\n",
" 0 CTF compensation matrices available\n",
"0 bad epochs dropped\n",
"Not setting metadata\n",
"264 matching events found\n",
"No baseline correction applied\n",
"0 projection items activated\n"
]
}
],
"source": [
"epochs = mne.read_epochs(input_path + str(os.sep) + \"sub-test_ses-001_sample_audiovis_eeg_data_epo.fif\",\n",
" preload=True) # load data into memory"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"
\n",
"Looking at the output of our .info object reveals that we've previosuly applied a filter and kept only the EEG channels to create our epochs"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"
Measurement date | \n", " \n", "December 03, 2002 19:01:10 GMT | \n", " \n", "
---|---|
Experimenter | \n", " \n", "MEG | \n", " \n", "Participant | \n", " \n", "Unknown | \n", " \n", " \n", "
Digitized points | \n", " \n", "0 points | \n", " \n", "
Good channels | \n", "59 EEG | \n", "
Bad channels | \n", "None | \n", "
EOG channels | \n", "Not available | \n", "
ECG channels | \n", "Not available | \n", " \n", "
Sampling frequency | \n", "600.61 Hz | \n", "
Highpass | \n", "0.10 Hz | \n", "
Lowpass | \n", "40.00 Hz | \n", "
\n", " | time | \n", "EEG 001 | \n", "EEG 002 | \n", "EEG 003 | \n", "EEG 004 | \n", "EEG 005 | \n", "EEG 006 | \n", "EEG 007 | \n", "EEG 008 | \n", "EEG 009 | \n", "... | \n", "EEG 050 | \n", "EEG 051 | \n", "EEG 052 | \n", "EEG 054 | \n", "EEG 055 | \n", "EEG 056 | \n", "EEG 057 | \n", "EEG 058 | \n", "EEG 059 | \n", "EEG 060 | \n", "
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | \n", "-300 | \n", "-0.273486 | \n", "-0.705960 | \n", "-0.716901 | \n", "0.000873 | \n", "0.376220 | \n", "0.046862 | \n", "-0.481563 | \n", "-0.065211 | \n", "0.111456 | \n", "... | \n", "-0.123930 | \n", "-0.311101 | \n", "-0.491009 | \n", "0.542431 | \n", "-0.473025 | \n", "-0.709696 | \n", "0.420646 | \n", "0.116793 | \n", "-0.457120 | \n", "-0.270652 | \n", "
1 | \n", "-298 | \n", "-0.358799 | \n", "-0.656849 | \n", "-0.759258 | \n", "0.011594 | \n", "0.443271 | \n", "-0.063794 | \n", "-0.598507 | \n", "0.056031 | \n", "-0.014147 | \n", "... | \n", "-0.117610 | \n", "-0.325659 | \n", "-0.524114 | \n", "0.628147 | \n", "-0.435255 | \n", "-0.704167 | \n", "0.514167 | \n", "0.207106 | \n", "-0.386811 | \n", "-0.181919 | \n", "
2 | \n", "-296 | \n", "-0.421568 | \n", "-0.570382 | \n", "-0.803121 | \n", "0.007416 | \n", "0.462682 | \n", "-0.192772 | \n", "-0.722229 | \n", "0.148973 | \n", "-0.150639 | \n", "... | \n", "-0.110002 | \n", "-0.336857 | \n", "-0.550440 | \n", "0.711637 | \n", "-0.396294 | \n", "-0.689133 | \n", "0.608688 | \n", "0.297349 | \n", "-0.314539 | \n", "-0.085795 | \n", "
3 | \n", "-295 | \n", "-0.457549 | \n", "-0.456782 | \n", "-0.842626 | \n", "-0.008271 | \n", "0.439441 | \n", "-0.325556 | \n", "-0.838798 | \n", "0.207098 | \n", "-0.276764 | \n", "... | \n", "-0.102828 | \n", "-0.344320 | \n", "-0.570619 | \n", "0.789199 | \n", "-0.358065 | \n", "-0.666718 | \n", "0.699356 | \n", "0.382951 | \n", "-0.243442 | \n", "0.010825 | \n", "
4 | \n", "-293 | \n", "-0.465113 | \n", "-0.329720 | \n", "-0.868505 | \n", "-0.030309 | \n", "0.383933 | \n", "-0.447467 | \n", "-0.934531 | \n", "0.229226 | \n", "-0.372866 | \n", "... | \n", "-0.098432 | \n", "-0.348692 | \n", "-0.586340 | \n", "0.856297 | \n", "-0.323208 | \n", "-0.640448 | \n", "0.780274 | \n", "0.458829 | \n", "-0.177358 | \n", "0.100279 | \n", "
... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "
596 | \n", "693 | \n", "1.021945 | \n", "1.389569 | \n", "1.603583 | \n", "0.354900 | \n", "1.535488 | \n", "1.175721 | \n", "1.204013 | \n", "-0.398187 | \n", "0.979819 | \n", "... | \n", "-1.035178 | \n", "-1.492689 | \n", "-0.526998 | \n", "-1.865670 | \n", "-1.116604 | \n", "-0.717162 | \n", "-1.807308 | \n", "-1.885107 | \n", "-1.537620 | \n", "-0.355314 | \n", "
597 | \n", "694 | \n", "0.948624 | \n", "1.294110 | \n", "1.432409 | \n", "0.377047 | \n", "1.463960 | \n", "1.060179 | \n", "1.094829 | \n", "-0.255787 | \n", "0.829088 | \n", "... | \n", "-0.976875 | \n", "-1.429080 | \n", "-0.444614 | \n", "-1.737224 | \n", "-0.995170 | \n", "-0.623922 | \n", "-1.697016 | \n", "-1.763489 | \n", "-1.403196 | \n", "-0.248636 | \n", "
598 | \n", "696 | \n", "0.881483 | \n", "1.197141 | \n", "1.295577 | \n", "0.422118 | \n", "1.404105 | \n", "0.971797 | \n", "1.017964 | \n", "-0.066488 | \n", "0.696837 | \n", "... | \n", "-0.929177 | \n", "-1.378435 | \n", "-0.375621 | \n", "-1.615313 | \n", "-0.881996 | \n", "-0.535283 | \n", "-1.592202 | \n", "-1.651932 | \n", "-1.272434 | \n", "-0.162004 | \n", "
599 | \n", "698 | \n", "0.828058 | \n", "1.104750 | \n", "1.198133 | \n", "0.483204 | \n", "1.355620 | \n", "0.912522 | \n", "0.978644 | \n", "0.142922 | \n", "0.601567 | \n", "... | \n", "-0.895735 | \n", "-1.343722 | \n", "-0.325779 | \n", "-1.502037 | \n", "-0.783363 | \n", "-0.456373 | \n", "-1.495208 | \n", "-1.554227 | \n", "-1.150319 | \n", "-0.096405 | \n", "
600 | \n", "699 | \n", "0.794171 | \n", "1.022128 | \n", "1.139056 | \n", "0.549998 | \n", "1.314434 | \n", "0.879571 | \n", "0.975541 | \n", "0.342043 | \n", "0.553991 | \n", "... | \n", "-0.877960 | \n", "-1.325241 | \n", "-0.297244 | \n", "-1.399055 | \n", "-0.703607 | \n", "-0.390818 | \n", "-1.408314 | \n", "-1.472842 | \n", "-1.040961 | \n", "-0.051484 | \n", "
601 rows × 60 columns
\n", "