Impulse predictors for epochs

epoch_impulse_predictor() generates predictor variables for reverse correlation in trial-based experiments with discrete events. The function generates one impulse per trial, and these impulsescan be of varaiable magnitude and have variable latency.

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 = 2
from eelbrain import *

ds = datasets.simulate_erp()
print(ds.summary())

Out:

Key         Type     Values
--------------------------------------------------------------------
eeg         NDVar    140 time, 65 sensor; -1.85296e-05 - 2.11533e-05
cloze       Var      0.00563694 - 0.997675
cloze_cat   Factor   high:40, low:40
n_chars     Var      0:2, 1:5, 2:6, 3:13, 4:23, 5:20, 6:7, 7:4
--------------------------------------------------------------------
Dataset: 80 cases

Discrete events

Computing a TRF for an impulse at trial onset is very similar to averaging:

any_trial = epoch_impulse_predictor('eeg', 1, ds=ds)
fit = boosting('eeg', any_trial, -0.100, 0.600, basis=0.050, ds=ds, partitions=2, delta=0.01)
average = ds['eeg'].mean('case')
trf = fit.h.sub(time=(average.time.tmin, average.time.tstop))
p = plot.TopoButterfly([fit.h_scaled, average], xlim=(-0.100, 0.600), axtitle=['Impulse response', 'Average'], t=0.400)
epoch impulse

Out:

Fitting models:   0%|          | 0/130 [00:00<?, ?it/s]
Fitting models:   1%|          | 1/130 [00:00<00:20,  6.31it/s]
Fitting models:   5%|5         | 7/130 [00:00<00:04, 30.61it/s]
Fitting models:   8%|8         | 11/130 [00:00<00:03, 33.48it/s]
Fitting models:  12%|#2        | 16/130 [00:00<00:02, 39.11it/s]
Fitting models:  17%|#6        | 22/130 [00:00<00:02, 43.23it/s]
Fitting models:  21%|##        | 27/130 [00:00<00:02, 42.24it/s]
Fitting models:  25%|##4       | 32/130 [00:00<00:02, 42.67it/s]
Fitting models:  30%|###       | 39/130 [00:00<00:01, 48.93it/s]
Fitting models:  35%|###5      | 46/130 [00:01<00:01, 54.10it/s]
Fitting models:  42%|####1     | 54/130 [00:01<00:01, 59.03it/s]
Fitting models:  47%|####6     | 61/130 [00:01<00:01, 59.27it/s]
Fitting models:  52%|#####2    | 68/130 [00:01<00:01, 60.14it/s]
Fitting models:  59%|#####9    | 77/130 [00:01<00:00, 66.36it/s]
Fitting models:  65%|######5   | 85/130 [00:01<00:00, 68.13it/s]
Fitting models:  72%|#######1  | 93/130 [00:01<00:00, 67.10it/s]
Fitting models:  78%|#######7  | 101/130 [00:01<00:00, 68.48it/s]
Fitting models:  83%|########3 | 108/130 [00:01<00:00, 64.24it/s]
Fitting models:  88%|########8 | 115/130 [00:02<00:00, 58.80it/s]
Fitting models:  93%|#########3| 121/130 [00:02<00:00, 54.45it/s]
Fitting models:  99%|#########9| 129/130 [00:02<00:00, 60.37it/s]

Categorial coding

Impulse predictors can be used like dummy codes in a regression model. Use one impulse to code for occurrence of any word (any_word), and a second impulse to code for unpredictable words only (cloze):

any_word = epoch_impulse_predictor('eeg', 1, ds=ds, name='any_word')
# effect code for cloze (1 for low cloze, -1 for high cloze)
cloze_code = Var.from_dict(ds['cloze_cat'], {'high': 0, 'low': 1})
low_cloze = epoch_impulse_predictor('eeg', cloze_code, ds=ds, name='low_cloze')

# plot the predictors for each trial
plot.UTS([any_word, low_cloze], '.case')
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79

Out:

<UTS: any_word, low_cloze ~ .case>

Estimate response functions for these two predictors. Based on the coding, any_word reflects the response to predictable words, and low_cloze reflects how unpredictable words differ from predictable words:

fit = boosting('eeg', [any_word, low_cloze], 0, 0.5, basis=0.050, model='cloze_cat', ds=ds, partitions=2, delta=0.01)
p = plot.TopoButterfly(fit.h, xlim=(-0.100, 0.600), t=0.400)
epoch impulse

Out:

Fitting models:   0%|          | 0/130 [00:00<?, ?it/s]
Fitting models:   1%|          | 1/130 [00:00<00:15,  8.24it/s]
Fitting models:   4%|3         | 5/130 [00:00<00:05, 24.90it/s]
Fitting models:   7%|6         | 9/130 [00:00<00:04, 28.99it/s]
Fitting models:   9%|9         | 12/130 [00:00<00:04, 27.97it/s]
Fitting models:  12%|#1        | 15/130 [00:00<00:04, 26.78it/s]
Fitting models:  15%|#5        | 20/130 [00:00<00:03, 31.37it/s]
Fitting models:  19%|#9        | 25/130 [00:00<00:03, 32.65it/s]
Fitting models:  23%|##3       | 30/130 [00:01<00:03, 31.40it/s]
Fitting models:  27%|##6       | 35/130 [00:01<00:02, 35.19it/s]
Fitting models:  32%|###1      | 41/130 [00:01<00:02, 39.39it/s]
Fitting models:  35%|###5      | 46/130 [00:01<00:02, 40.12it/s]
Fitting models:  39%|###9      | 51/130 [00:01<00:02, 39.16it/s]
Fitting models:  43%|####3     | 56/130 [00:01<00:01, 41.82it/s]
Fitting models:  48%|####7     | 62/130 [00:01<00:01, 45.92it/s]
Fitting models:  52%|#####2    | 68/130 [00:01<00:01, 47.04it/s]
Fitting models:  56%|#####6    | 73/130 [00:01<00:01, 46.87it/s]
Fitting models:  60%|######    | 78/130 [00:02<00:01, 46.24it/s]
Fitting models:  65%|######5   | 85/130 [00:02<00:00, 51.42it/s]
Fitting models:  70%|#######   | 91/130 [00:02<00:00, 51.44it/s]
Fitting models:  75%|#######4  | 97/130 [00:02<00:00, 52.55it/s]
Fitting models:  79%|#######9  | 103/130 [00:02<00:00, 52.41it/s]
Fitting models:  84%|########3 | 109/130 [00:02<00:00, 48.35it/s]
Fitting models:  88%|########7 | 114/130 [00:02<00:00, 47.75it/s]
Fitting models:  92%|#########1| 119/130 [00:02<00:00, 42.80it/s]
Fitting models:  95%|#########5| 124/130 [00:03<00:00, 43.66it/s]
Fitting models: 100%|##########| 130/130 [00:03<00:00, 47.24it/s]

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

Gallery generated by Sphinx-Gallery