Two-stage test

When trials are associated with continuous predictor variables, averaging is often a poor solution that loses part of the data. In such cases, a two-stage design can be employed that allows using the continuous predictor variable to test hypotheses at the group level. A two-stage analysis involves:

  • Stage 1: fit a regression model to each individual subject’s data

  • Stage 2: test regression coefficients at the group level

The example uses simulated data meant to vaguely resemble data from an N400 experiment, but not intended as a physiologically realistic simulation.

# sphinx_gallery_thumbnail_number = 1
from eelbrain import *

Generate simulated data: each function call to datasets.simulate_erp() generates a dataset for one subject. For each subject, a regression model is fit using cloze probability as continuous predictor variables.

lms = []
for subject in range(10):
    # generate data for one subject
    ds = datasets.simulate_erp(seed=subject)
    # Re-reference EEG data
    ds['eeg'] -= ds['eeg'].mean(sensor=['M1', 'M2'])
    # Fit stage 1 model
    lm = testnd.LM('eeg', 'cloze', ds)

# Collect single-subject models for group analysis
stage2 = testnd.LMGroup(lms)

The testnd.LMGroup object allows quick access to t-tests of individual regression coefficients.

res = stage2.column_ttest('cloze', pmin=0.05, tstart=0.100, tstop=0.600)
p = plot.TopoButterfly(res, frame='t')
sensor two stage
id   tstart   tstop   duration   n_sensors   v        p   sig
1    0.35     0.455   0.105      53          1347.8   0   ***

Since this is a regression model, it also contains an intercept coefficient reflecting signal deflections shared in all trials.

res = stage2.column_ttest('intercept', pmin=0.05)
p = plot.TopoButterfly(res, frame='t')
sensor two stage

The regression coefficients themselves can be retrieved as Dataset:

coeffs = stage2.coefficients_dataset()
Key         Type     Values
intercept   NDVar    140 time, 65 sensor; -6.61165e-06 - 7.43409e-06
cloze       NDVar    140 time, 65 sensor; -7.33241e-06 - 8.92037e-06
subject     Factor   S000, S001, S002, S003, S004, S005, S006, S007, S008, S009 (random)
Dataset: 10 cases

Total running time of the script: ( 0 minutes 6.843 seconds)

Gallery generated by Sphinx-Gallery