Note
Go to the end to download the full example code
Construct a model RDM#
This example shows how to create RDMs from arbitrary data. A common use case for this is to construct a “model” RDM to RSA against the brain data. In this example, we will create a RDM based on the length of the words shown during an EEG experiment.
# Import required packages
import mne
import mne_rsa
MNE-Python contains a build-in data loader for the kiloword dataset, which is
used here as an example dataset. Since we only need the words shown during
the experiment, which are in the metadata, we can pass preload=False
to
prevent MNE-Python from loading the EEG data, which is a nice speed gain.
data_path = mne.datasets.kiloword.data_path(verbose=True)
epochs = mne.read_epochs(data_path / "kword_metadata-epo.fif", preload=False)
# Show the metadata of 10 random epochs
print(epochs.metadata.sample(10))
Reading C:\Users\wmvan\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 WordFrequency OrthographicDistance NumberOfLetters BigramFrequency ConsonantVowelProportion VisualComplexity
91 filth 4.050 2.004321 1.85 5.0 433.400000 0.800000 49.631810
425 embargo 4.950 1.568202 3.05 7.0 203.000000 0.571429 77.366752
110 crisis 3.650 3.022428 2.00 6.0 575.666667 0.666667 54.164593
90 felon 4.650 1.079181 1.85 5.0 436.600000 0.600000 60.050717
238 warranty 4.750 0.845098 2.80 8.0 686.375000 0.625000 64.544162
588 bottom 4.000 3.166726 2.35 6.0 430.500000 0.666667 68.942478
548 stone 6.350 2.868056 1.45 5.0 539.800000 0.600000 65.933265
168 courage 1.900 2.773786 2.30 7.0 841.142857 0.428571 69.928589
909 blunder 4.300 1.491362 1.80 7.0 683.571429 0.714286 65.055058
237 modality 3.125 0.301030 2.60 8.0 463.000000 0.500000 65.056680
Now we are ready to create the “model” RDM, which will encode the difference in length between the words shown during the experiment.
rdm = mne_rsa.compute_rdm(epochs.metadata.NumberOfLetters, metric="euclidean")
# Plot the RDM
fig = mne_rsa.plot_rdms(rdm, title="Word length RDM")
fig.set_size_inches(3, 3) # Make figure a little bigger to show axis properly
Total running time of the script: (0 minutes 0.993 seconds)