Event IDs to change based on behavioral data

Hi all,

I have an issue with changing the event ids based on behavioral data. I have two different experimental phases: during the first one, experimental manipulation takes place, and the second phase is a surprise memory task. I am trying to analyze the first phase based on correctly remembered and forgotten items from the second phase. I have tried several options to statistically test data with R and to plot it with MNE. However, I couldn’t come up with an easy solution. I am wondering what you would suggest.

Thanks in advance for your help!
Gözem

Hello Gözem,

I am also working with a quite complicated behavioral setup, for me the easiest solution was to append metadata while creating epochs.

df = pd.read_csv('alldata')

# remove trials where I started the EEG recording too late 

df.drop(df.index[(df["ID"] == 7) & (df["block"] == 2) & (df["trial"] == 1)], inplace=True)
df.drop(df.index[(df["ID"] == 8) & (df["block"] == 3) & (df["trial"] == 1)], inplace=True)

#loop over participants

for counter, id in enumerate(IDlist):

    # get only the rows from the dataframe that belong to the current participant

    df_sub = df[df.ID == counter]

    # load stimulus events

    events, event_dict = mne.events_from_annotations(raw, regexp='Stimulus/S  2')

    #create epochs and add metadata to the epochs structure

    epochs = mne.Epochs(raw, events, event_id=1, tmin=tmin, tmax=tmax,
                                         preload=True, baseline=None, detrend=1, metadata=df_sub)
   # access the metadata and index
   epochs_miss_low = epochs.__getitem__((epochs.metadata.isyes == 1) & (epochs.metadata.sayyes == 0) & (epochs.metadata.cue == 0.25))

’
You can then access the metadta simply by calling epochs.metadata and for indexing you can use the getitem attribute.

I hope this was helpful?

Best,

Carina

3 Likes

In addition to @CarinaFo’s example above: we have a tutorial about working with Epoch metadata, here: Working with Epoch metadata — MNE 1.1.0 documentation

Note also that the epochs.__getitem__ method is the under-the-hood implementation for the more commonly used square-bracket accessor (sometimes called “subsetting”). So in the last line of @CarinaFo’s code sample you can replace epochs.__getitem__(...) with epochs[...]

4 Likes

Thanks a lot @CarinaFo and @drammock for your help! I just tested your suggestion and it worked!

1 Like