12.11: Exercise- Artificially Inflated Decoding with Unbalanced Classes

Applied Event-Related Potential Data Analysis 2e · LibreTexts

0%

Contents

    Text

    Size
    100%
    Theme
    Typeface
    Line length
    Spacing

    Read aloud

    How

    Speed: 1×
    Light up
    Highlight

    Symbols: Mulberry Symbols, © 2018–2026 Steve Lee, CC BY-SA 4.0 (licence, the set), the site's own copies.

    From LibreTexts, under CC BY-NC 4.0, as the source states it; its equations are written in TeX, which the PDF shows typeset. This page at LibreTexts.

    12.11: Exercise- Artificially Inflated Decoding with Unbalanced Classes

    In most experiments designed for decoding, each of the classes has the same probability. For example, the first experiment described in this chapter had 40 trials for each combination of face ID and emotional expression. If you throw out trials with behavioral errors (or perhaps trials with artifacts), you might not have exactly the same number of trials per class. But if you’ve excluded only a few trials, it’s not a big deal if you have to equate the number of trials per class (by selecting the Equal Trials, Equal AVGs and Across Classes options).

    Sometimes, however, the number of trials differs greatly across classes. This might happen if many more trials were excluded in one class than the others (e.g., because of more behavioral errors in one class). However, large imbalances mainly occur when the experimental design involves presenting one class less often than the others. For example, imagine that you’ve run an oddball experiment in which there are 100 targets and 900 nontargets, and you want to use decoding to see if the brain activity differs between targets and nontargets. If you decode the data using 10 folds, you would have 10 trials per average/pseudotrial for the targets and 90 trials per average/pseudotrial for the nontargets.

    Although this kind of imbalance is not a problem with conventional mean amplitude measures (see Chapter 9 in Luck, in preparation), it produces artificially inflated decoding accuracy. The reason for this artificial inflation is illustrated in Figure 12.3A. This is a simulation of what would happen if the single-trial brain activity was actually the same for targets and nontargets, but the averages for targets were noisier than the averages for the nontargets (because fewer trials were averaged together for the targets than for the nontargets). As you can see from the figure, the center of mass in the electrode space is the same for targets and nontargets, but the greater noise for the averaged targets tends to cause more extreme values. The decoder can then find a decision line that separates more extreme values from less extreme values, which will allow it to decode the classes better than chance. Note that there are no consistent differences between the voltage patterns for targets and nontargets on the individual trials in this imaginary example (except for random noise); the problem arises when we combine differences in the number of trials with averaging, which leads to different amounts of noise in the averages for targets and nontargets and therefore more extreme values for target averages than for nontarget averages.

    Examples of voltage pairs when 10 trials versus 90 trials are averaged together
    Figure 12.3. (A) Examples of voltage pairs when 10 trials versus 90 trials are averaged together, with no difference between the single-trial values for the two classes. (B) Grand average decoding accuracy from the simulation.

    Before I discuss a couple possible solutions for this problem, I’d like you to see the problem for yourself. To make that possible, I created a dataset in which there are no consistent differences between two classes in the single trials, but one class occurs on 10% of trials and the other class occurs on 90% of trials. Specifically, I took the data from the ERP CORE N170 experiment (including face trials, car trials, randomized-phase face trials, and randomized-phase car trials) and I replaced each event code with a 1 for a random 10% of the trials and with a 2 for the other 90% of trials. I then binned the trials according to these randomized event codes, with Bin 1 being the Simulated Frequent condition and Bin 2 being the Simulated Rare condition. The original datasets had 320 trials, and the simulated datasets had an average of 288 trials in Bin 1 and 32 trials in Bin 2. The actual stimuli in a given bin were just as likely to be faces, cars, randomized-phase faces, and randomized-phase cars, so the only differences between the two bins are random noise. In other words, this is a very realistic simulation of a null effect, in which the trials in the two bins are random samples from the same population of actual single trials of EEG data. If we see above-chance decoding in this null effect situation, this would indicate a problem with the decoding.

    The EEGsets with the scrambled event codes are in the folder N170_Data_Scrambled. I made averages for each of the 9 participants and put them in the folder N170_ERPs_Scrambled. The grand average across participants (for the PO8 electrode site, where the N170 was largest) is shown in Figure 12.3B. As you can see, the ERP for the Simulated Rare bin is much like the ERP for the Simulated Frequent bin, with each of the two waveforms falling well within the standard error of the other waveform. That’s what we’d expect given that trials were randomly assigned to these two bins. You can also see that the waveform for the Simulated Rare bin is noisier, with more up-and-down deflections in the baseline (and throughout the waveform). That’s what we’d expect given that only 10% of the stimuli were assigned to the Simulated Rare bin.

    Given that the trials were randomly assigned to the two bins, there was no consistent information in the single-trial EEG signal that could distinguish between the two bins. However, the fact that the averaged ERPs were noisier for the simulated rare bin than for the simulated frequent bin means that it should be possible, in theory, to determine whether an average came from the simulated rare bin/class or the simulated rare bin/class (as illustrated in Figure 12.3A).

    Let’s apply decoding to these datasets and see for ourselves. First, clear the existing BESTsets and MVPCsets from eStudio. I’ve already made the BESTsets for you, so go to the BESTsets panel in the Pattern Classification tab, click Load, navigate to the N170_BEST_Scrambled folder, and load all 9 BESTsets. Note that I did not apply any artifact rejection to these BESTsets. 

    Select all 9 of the BESTsets in the BESTsets panel and open the Multivariate Pattern Classification panel. Set up the top portion of the panel as shown in Screenshot 12.16. In the bottom portion, set the Number of trials and averages section to Max Trials, Equal AVGs. This sets up the cross-validation process to use all of the trials in each bin/class, with 5 averages per class (because the number of cross-validation folds is set to 5). You can see this by clicking Show Summary of trials and averages. For example, Subject 1 has 279 total trials in the Simulated Frequent bin/class, yielding 55 trials in each of the 5 averaged ERPs for that bin; by contrast, there are only 39 total trials in the Simulated Rare bin/class, yielding 7 trials in each of the 5 averaged ERPs for that bin. This is exactly the situation in which you are likely to get bogus above-chance decoding.

    Decoding Panel for Scrambled Data

    Screenshot 12.16

    Now close the summary window and go back to the decoding panel. Near the bottom of the panel, notice that the Metric is set to AUC (which stands for area under the curve). In the previous exercises, we used the ACC metric (accuracy, or proportion correct), but now that metric is grayed out and you can’t select it. This is because the Max Trials, Equal AVGs option is likely to produce artificially inflated decoding accuracy, and when we put together this software package, we wanted to make sure that people don’t use this inappropriate option. [The AUC metric is not inflated with this option, so we allow it.]

    I therefore created a special script to do the decoding in this invalid way (as if you had used the Max Trials, Equal AVGs option with the ACC metric). To see the results, go to the MVPCsets panel and load all 9 MVPCsets from the N170_MVPC_Scrambled_MaxTrials folder. Select all 9 of them and look at the plots of decoding accuracy in eStudio’s main plotting area. Notice that the decoding accuracy is above chance for almost every MVPCset at almost every time point. Now make a grand average using the Average Across MVPCsets panel. You should see something like Screenshot 12.17. 

    Grand Average Decoding for Scrambled Data

    Screenshot 12.17


    The decoding accuracy in the grand average is obviously well above chance at every time point, even during the prestimulus baseline. That's obviously bogus given that the trials were randomly assigned to the two bins/classes. This demonstrates that decoding is artificially inflated if the averages/pseudotrials are noisier for one class than the other(s). The usual cause of this is having fewer trials in one class, but anything that makes the data noisier for one class will inflate the decoding accuracy.

    By the way, just as I always look at the prestimulus baseline prior to the rest of the waveform when I am looking at conventional ERP plots, I always look at decoding accuracy during the prestimulus period first when looking at ERP decoding waveforms. If the prestimulus decoding is above chance, then something is wrong. Looking at the prestimulus decoding has allowed me to detect errors in the decoding methods of the trainees in my lab several times. And it has also allowed me to detect problems in the decoding methods of researchers from other labs. You should also pay close attention to decoding accuracy in the prestimulus period, whether you are looking at your own data or someone else's data.


    This page titled 12.11: Exercise- Artificially Inflated Decoding with Unbalanced Classes was last modified on Thu, 01 Oct 2026 18:52:51 GMT and is shared under a CC BY-NC 4.0 license and was authored, remixed, and/or curated by Steven J Luck.