EEG sample epochs

These are the EEG data used in Workflow Outline

Experimental design. These data are single-trial EEG epochs recorded at 250 digital samples per second from one individual in an auditory “oddball” paradigm. The stimuli are a random sequence of high and low pitched tones (tone: hi, lo) that are frequent or infrequent (stim: standard, target). Stimulus trials are presented in two blocks: the hi tones are the infrequent targets in the first block and frequent standards in the second. The task is to respond to the infrequent tones. In this type of paradigm, the average potentials recorded over central and posterior scalp after about 300 ms post-stimulus are typically more positive going for the rare targets than for the frequent standards, a P300 ERP effect.

from matplotlib import pyplot as plt
import pandas as pd
from fitgrid import DATA_DIR, sample_data


# download the epochs data and read into a pd.DataFrame
sample_data.get_file("sub000p3.ms1500.epochs.feather")
p3_epochs_df = pd.read_feather(DATA_DIR / "sub000p3.ms1500.epochs.feather")

# select the experimental stimulus trials for modeling
p3_epochs_df = p3_epochs_df.query("stim in ['standard', 'target']")

# look up the data QC flags and select the good epochs
good_epochs = p3_epochs_df.query("match_time == 0 and log_flags == 0")[
    "epoch_id"
]
p3_epochs_df = p3_epochs_df.query("epoch_id in @good_epochs")

# the original time stamp column name is obscure, rename for clarity
p3_epochs_df.rename(columns={"match_time": "time_ms"}, inplace=True)

# select columns of interest for modeling
indices = ["epoch_id", "time_ms"]
predictors = ["stim", "tone"]  # stim=standard, target; tone=hi, lo
channels = ["MiPf", "MiCe", "MiPa", "MiOc"]  # midline electrodes
p3_epochs_df = p3_epochs_df[indices + predictors + channels]

# set the epoch and time column index for fg.Epochs
p3_epochs_df.set_index(["epoch_id", "time_ms"], inplace=True)

# "baseline", i.e., center each epoch on the pre-stimulus interval
centered = []
for epoch_id, vals in p3_epochs_df.groupby("epoch_id"):
    centered.append(
        vals[channels] - vals[channels].query("time_ms < 0").mean()
    )
p3_epochs_df[channels] = pd.concat(centered)

# done ...
p3_epochs_df
stim tone MiPf MiCe MiPa MiOc
epoch_id time_ms
0 -748 target hi -6.157753 -25.526524 -44.994408 -23.116379
-744 target hi -8.157753 -32.354649 -48.095970 -20.686691
-740 target hi -7.157753 -31.596836 -40.935814 -16.553879
-736 target hi -12.157753 -30.837070 -35.212181 -14.124190
-732 target hi -8.657753 -24.260899 -26.385033 -13.397628
... ... ... ... ... ... ... ...
391 732 standard hi -21.056150 -5.361887 4.670756 1.208691
736 standard hi -15.056150 0.708426 10.639506 7.521191
740 standard hi -21.556150 -4.857981 4.912944 4.364941
744 standard hi -23.056150 -4.350168 4.912944 7.036816
748 standard hi -24.556150 -4.096262 4.194194 8.497753

125250 rows × 6 columns



These time-domain average ERPs can be computed with fitgrid, see Average ERPs with fitgrid.

fig, axs = plt.subplots(2, 1, figsize=(8, 8))
for axi, (condition, vals) in enumerate(p3_epochs_df.groupby("stim")):
    vals.groupby("time_ms").mean().plot(ax=axs[axi])
    axs[axi].set_title(f"{condition}")
standard, target

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

Gallery generated by Sphinx-Gallery