How to plot ERP results of comparing groups with different subject numbers

Now I know how to plot ERP results with 95%CI, but how to plot How to plot ERP results of comparing groups with different subject numbers different as reported unequally length.
Hope anyone can solve the problems

Hello @VincentZeng and welcome to the forum!

mne.viz.plot_compare_evokeds() can readily deal with groups of unequal sizes. Heres an example I just cooked up for you:

# %%
from pathlib import Path
import numpy as np
import mne


sample_dir = Path(mne.datasets.sample.data_path())
sample_fname = sample_dir / 'MEG' / 'sample' / 'sample_audvis_raw.fif'

raw = mne.io.read_raw_fif(sample_fname)
raw.pick_types(eeg=True, stim=True)

events = mne.find_events(raw, stim_channel='STI 014')
event_id = {'auditory/left': 1, 'auditory/right': 2, 'visual/left': 3,
            'visual/right': 4, 'face': 5, 'buttonpress': 32}

epochs = mne.Epochs(raw, events=events, event_id=event_id,
                    tmin=-0.2, tmax=0.5, baseline=(None, 0),
                    preload=True)

# %%
# Create lists of evokeds with un-equal numbers of items
evokeds_a = []
for _ in range(10):
    evokeds_a.append(epochs['auditory'].average())

evokeds_b = []
for _ in range(8):
    evokeds_b.append(epochs['visual'].average())

# %%
# Add a bit of jitter …
jitter_min = 1e-6
jitter_max = 10e-6
for e in evokeds_a + evokeds_b:
    jitter = np.random.random_sample(size=e.data.shape)
    jitter = (jitter_max - jitter_min) * jitter + jitter_min
    e._data += jitter

# %%
mne.viz.plot_compare_evokeds(
    evokeds={
        'Group A': evokeds_a,
        'Group B': evokeds_b
    },
    picks='EEG 010'
)

This produces:
output

I hope this helps.

Best wishes,
Richard

1 Like