ERP pipeline · PSYCH 390 step 11 / 11

Plotting and Scripting

How do you turn ten labs into one script?

Figure 1

The Ten Labs as One Script Looping Over Participants

The pipeline as a script

run not startedestimated time

    

Flags

Participants and channels to interpolate (one cell per participant)

The run is an animation with rough time estimates; no data are processed.

Figure 2

Building a Grand-Average N400 Figure Against the Plotting Rules

The figure

rules satisfied

    What to plot

    How to draw it

    Waveforms are a fixed true ERP plus noise that shrinks with the number of participants; the map inset is a schematic of the N400 distribution rather than a computed topography.

    What You Are Looking At

    Figure 1 is the whole lab sequence drawn as one program. Each block is a lab you have already done, in the order the data go through them, and the bracket on the left is a for loop; every block inside it runs once per participant. The three flags at the top of the script switch groups of blocks on and off, so after fixing one participant you can re-run only the grand average instead of importing everything again. The MATLAB skeleton on the right has the real shape of the lab script, and it updates as you add participants or channels to interpolate. One thing differs from the order of the labs: the script interpolates bad channels before the average reference is computed, so that a broken channel is not subtracted from every other one.

    Figure 2 builds the final figure of the project, the grand-average N400 at one electrode. The checklist next to it holds the plotting rules from Luck (2014, Chapter 1): a reader has to be able to see the prestimulus baseline, find time zero and 0 µV, read the voltage scale and polarity, tell the conditions apart, and see the difference wave, all without leaving the figure.

    Try This

    1. Press Run the script with two participants and watch the token loop through the chain twice before the grand average runs once. Add participants up to eight and run again. The code does not change, only the loop count and the time estimate.
    2. Turn off import_data and process_data and run again. Only the last block lights up. This is the normal way to redo a figure.
    3. Type P7 into the interpolation box of one participant and find the matching cell in chan_interpolate.
    4. In Figure 2, set Baseline shown to none and Calibration to none, and note how many rules go red. A waveform with no baseline gives the reader no way to judge whether the effect is real.
    5. Move the participant slider from 2 to 20. The waveforms smooth out and the N400 separates cleanly; turn on Map inset, 300–500 ms and it follows the same change.

    Why It Matters for the Pipeline

    A script is the record of an analysis. It runs the same way on every participant, it can be handed to someone else, and every parameter you chose in the earlier labs, the 0.1 Hz cutoff, the ±100 µV threshold, the 300–500 ms window, is written down where a reviewer can see it. The first draft comes from EEGLAB. Every menu action appends its command to EEG.history (Delorme & Makeig, 2004), so a script is mostly the history of one participant wrapped in a loop. The loop needs a predictable place to find each file, and the BIDS layout gives it one (Gorgolewski et al., 2016; Pernet et al., 2019). The path sub-001/eeg/sub-001_task-N400_eeg.set is built with fullfile so the same script runs on Windows and macOS. A cell array of participant IDs drives the loop, and a matching cell array of channels to interpolate keeps the one thing that differs between participants out of the code.

    The grand average, pop_gaverager, is the mean of the participants' averaged ERPs. With two participants it shows you whether the pipeline worked; with twenty it shows you the component. The statistics in the previous step are run on each participant's own measurement, and the grand average is the picture of what those numbers describe. pop_ploterps draws it (Lopez-Calderon & Luck, 2014). Luck's rule for the drawing is that a figure without a prestimulus baseline gives the reader no way to tell signal from drift or artifact, which is why the plotting checklist starts with the baseline. The checklist next to the figure spells that rule out.

    References

    Delorme, A., & Makeig, S. (2004). EEGLAB: An open source toolbox for analysis of single-trial EEG dynamics including independent component analysis. Journal of Neuroscience Methods, 134(1), 9–21. https://doi.org/10.1016/j.jneumeth.2003.10.009

    Gorgolewski, K. J., Auer, T., Calhoun, V. D., Craddock, R. C., Das, S., Duff, E. P., Flandin, G., Ghosh, S. S., Glatard, T., Halchenko, Y. O., Handwerker, D. A., Hanke, M., Keator, D., Li, X., Michael, Z., Maumet, C., Nichols, B. N., Nichols, T. E., Pellman, J., ... Poldrack, R. A. (2016). The brain imaging data structure, a format for organizing and describing outputs of neuroimaging experiments. Scientific Data, 3, Article 160044. https://doi.org/10.1038/sdata.2016.44

    Lopez-Calderon, J., & Luck, S. J. (2014). ERPLAB: An open-source toolbox for the analysis of event-related potentials. Frontiers in Human Neuroscience, 8, Article 213. https://doi.org/10.3389/fnhum.2014.00213

    Luck, S. J. (2014). An introduction to the event-related potential technique (2nd ed.). MIT Press.

    Pernet, C. R., Appelhoff, S., Gorgolewski, K. J., Flandin, G., Phillips, C., Delorme, A., & Oostenveld, R. (2019). EEG-BIDS, an extension to the brain imaging data structure for electroencephalography. Scientific Data, 6, Article 103. https://doi.org/10.1038/s41597-019-0104-8