Skip to content

Commit 4ef9f31

Browse files
committed
Tutorial page for ds004977: CARLA with its authors' settings on the recording of their Figure 5, against the common average; re-referencing figure no longer needs MATLAB R2023a (issue #9)
1 parent 069d954 commit 4ef9f31

6 files changed

Lines changed: 185 additions & 1 deletion

File tree

‎CHANGELOG.md‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,11 @@
9696
the repository's wiki at each change, for the EEGLAB website. The README
9797
follows the layout of the other EEGLAB plugin pages, with links to them, a
9898
quick start and images that also show outside GitHub.
99+
- **Tutorial page for ds004977** (`docs/5-CARLA-ds004977.md`): CARLA through
100+
the menus with its authors' settings on the recording of their Figure 5
101+
(sub-1 run 2, site RMO8-RMO9: the same 154 of 206 channels), the curve of
102+
that figure from the command line, and the common average of every channel
103+
for comparison.
99104

100105
### Changed
101106

@@ -267,6 +272,11 @@
267272
which became zero. Re-run varsubset analyses of datasets with removed
268273
channels; datasets imported before this version keep the old blocks unless
269274
re-imported.
275+
- **Re-referencing figure on MATLAB before R2023a** (issue #9): the
276+
before-and-after figure of preprocessing computed its error band with
277+
`std(..., 'omitmissing')`, an option added in R2023a; older releases stopped
278+
with "Invalid option. Option must be 'omitnan' or 'includenan'". It now uses
279+
`'omitnan'`.
270280

271281
## 1.2.0 (2026-10-25)
272282

‎README.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ window or figure that opens, and the same step from the command line.
7373
| [ECoG: cortico-cortical evoked potentials](https://github.com/sccn/iEEGLAB/wiki/2-ECoG-CCEP-ds004080): the same on fsaverage, with the common average and the N1 | ds004080 sub-ccepAgeUMCU02 |
7474
| [FieldTrip tutorial data](https://github.com/sccn/iEEGLAB/wiki/3-FieldTrip-tutorial-data): common average of the grids, bipolar depth leads, high-frequency activity, against FieldTrip | FieldTrip's SubjectUCI29 |
7575
| [Re-referencing compared](https://github.com/sccn/iEEGLAB/wiki/4-Re-referencing-compared): six schemes against the published CRP | ds004696 sub-02, full recording |
76+
| [CARLA on its authors' data](https://github.com/sccn/iEEGLAB/wiki/5-CARLA-ds004977): the recording of their Figure 5, against the common average | ds004977 sub-1, run 2 |
7677

7778
The first two run on small extracts of public recordings that ship with the
7879
plugin, at their native sampling rate (2048 Hz), each in one folder: the EEGLAB

‎docs/5-CARLA-ds004977.md‎

Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
# CARLA on its authors' data (ds004977)
2+
3+
CARLA (common average referencing by least anticorrelation; Huang et al., 2024) chooses, for each stimulation site,
4+
the channels whose common average carries no evoked response. This page applies it through the iEEGLAB menus to the
5+
recording of the paper's Figure 5, with the authors' settings: sub-1 of OpenNeuro ds004977, stereo-EEG at 4800 Hz,
6+
stimulation site RMO8-RMO9. The authors' code puts 154 of 206 channels in the common average there; iEEGLAB chooses the
7+
same 154. The page then compares CARLA with the common average of every channel.
8+
9+
Each step gives the menu, what you should get (*Expect*), and the same step from the command line. Install iEEGLAB
10+
first ([Installation](https://github.com/sccn/iEEGLAB#installation)).
11+
12+
## Data
13+
14+
Run 2 of sub-1, from OpenNeuro, with the [AWS command line](https://aws.amazon.com/cli/) (no account needed) or from
15+
[ds004977](https://openneuro.org/datasets/ds004977): 304 MB. Keep the folder structure. Reading it needs the **MEF3**
16+
plugin (**File > Manage EEGLAB extensions**).
17+
18+
```
19+
aws s3 sync --no-sign-request s3://openneuro.org/ds004977 ds004977 --exclude "*" --include "sub-1/ses-ieeg01/ieeg/*run-02*" --include "sub-1/ses-ieeg01/ieeg/*_electrodes.tsv" --include "sub-1/ses-ieeg01/ieeg/*_coordsystem.json" --include "dataset_description.json" --include "participants.tsv" --include "task-ccep_events.json"
20+
```
21+
22+
> **Note.** The public dataset holds only the samples behind the paper's Figures 1 to 6; the other samples are 0 (see
23+
> its README). In run 2, only the 12 pulses at RMO8-RMO9 have data: the other 9 sites import without an error but are
24+
> flat, so this page keeps RMO8-RMO9 only. The dataset has no pial surfaces (its FreeSurfer folder holds the T1 and
25+
> labels), so the page has no brain figure: **iEEGLAB > Visualize electrodes** would draw the contacts on a template
26+
> brain, which does not line up with these coordinates (ACPC, the participant's own space).
27+
28+
## Steps
29+
30+
Steps 1 to 4 take about a minute on a Windows laptop with 8 cores. The recording takes under 3 GB of memory.
31+
32+
### 1. Load the data
33+
34+
**iEEGLAB > Import raw recording**: select the `ds004977` folder, then sub-1's run 2
35+
(`sub-1_ses-ieeg01_task-ccep_run-02_ieeg.mefd`). Keep the defaults: the whole recording, brain channels only.
36+
37+
> **Expect.** About 25 seconds, with the progress in the command window and a progress bar: 255 stereo-EEG channels
38+
> at 4800 Hz, 9 minutes.
39+
40+
> **Note.** *Read only these stimulation sites* (RMO8-RMO9) in the import options reads 44 seconds instead of
41+
> 9 minutes. The high-pass filter of step 3 then works on that stretch, which changes the covariance of a few channels
42+
> a little: CARLA still chooses 154 channels, but RP17 instead of RP14, its 154th and 155th channels. Read the whole
43+
> recording to reproduce the paper exactly.
44+
45+
```matlab
46+
rec = fullfile('ds004977', 'sub-1', 'ses-ieeg01', 'ieeg', 'sub-1_ses-ieeg01_task-ccep_run-02_ieeg.mefd');
47+
EEG = ieeglab_import(rec);
48+
```
49+
50+
### 2. Coordinates and events
51+
52+
**iEEGLAB > Load electrode coordinates and events**: Ok in both windows. The sidecar files next to the recording are
53+
found automatically; the event type is the stimulation site, and the contacts marked bad in `channels.tsv` are marked
54+
here and removed during preprocessing.
55+
56+
> **Expect.** 228 of 255 contacts with coordinates, 43 bad (from `channels.tsv`), 120 stimulations at 10 sites. A
57+
> warning names the 27 contacts with no position in `electrodes.tsv`: 25 of them are bad, the other two are RP18 and
58+
> ROC14.
59+
60+
```matlab
61+
EEG = ieeglab_load(EEG, struct('event_field', 'electrical_stimulation_site'));
62+
```
63+
64+
### 3. Preprocess
65+
66+
**iEEGLAB > Preprocess iEEG data**, with the settings of the authors' code:
67+
68+
- *Choose which event types to analyse*: **Open selector**, RMO8-RMO9.
69+
- Untick *Remove electrodes with no XYZ coordinates*: RP18 and ROC14 are good contacts, and the authors keep them.
70+
- Untick *Blank the stimulation artifact*.
71+
- Tick *High-pass filter*, cutoff 0.5 Hz.
72+
- Untick *Remove line noise*: CARLA removes it from its own copy of the data before it ranks the channels, as the
73+
authors' code does; the re-referenced data keep it.
74+
- Untick *Remove the pre-stimulus baseline*.
75+
- Keep the rest: bad contacts removed, epochs -1 to 1 s.
76+
77+
> **Expect.** About 20 seconds: 212 contacts, 12 epochs.
78+
79+
> **Note.** The authors high-pass with a Butterworth filter, iEEGLAB with a FIR filter (both zero-phase). The
80+
> channels chosen at step 4 are the same.
81+
82+
```matlab
83+
EEG = ieeglab_preprocess(EEG, struct('event_filters', struct('type', {{'RMO8-RMO9'}}), ...
84+
'remove_no_coords', false, 'remove_bad_channels', true, 'apply_blank', false, ...
85+
'apply_highpass', true, 'highpass', 0.5, 'apply_notch', false, ...
86+
'apply_epoch', true, 'epoch_window', [-1000 1000], 'reject_trials', false, 'apply_baseline', false));
87+
EEGpre = EEG; % kept for step 6
88+
```
89+
90+
### 4. CARLA
91+
92+
**iEEGLAB > iEEG re-referencing**: CARLA, defaults. They are the authors' settings for real data: a response window
93+
of 10 to 300 ms, the sensitive cutoff, and the stimulated pair with 2 contacts on each side of it left out, as the bad
94+
contacts.
95+
96+
> **Expect.** About 10 seconds. The command window reads *154/212 channels in reference, 6 excluded* (RMO6 to RMO11): of
97+
> the 206 channels CARLA may use, it keeps 154, the same 154 as the authors' code (Huang et al., 2024, Figure 5). The
98+
> random draws use a fixed seed, so the result repeats from run to run.
99+
100+
```matlab
101+
EEG = pop_ieeglab_reref(EEG, 'method', 'carla');
102+
```
103+
104+
### 5. The curve of Figure 5
105+
106+
From the command line. CARLA ranks the channels by their covariance across trials, lowest first, and adds them to
107+
the common average one at a time. For each number of channels, it re-references the data with that average and finds
108+
the channel of the average most anticorrelated with the re-referenced channels: a channel that carries a response
109+
becomes anticorrelated with the others once its response is in the average. The curve is that channel's correlation
110+
(Fisher z, the paper's zeta), averaged over 100 bootstrap draws of the trials. CARLA keeps the number of channels at
111+
the top of the curve, before the first significant drop (the sensitive cutoff).
112+
113+
> **Expect.** The curve starts at -0.88 with 2 channels (1 channel has no value), rises to a plateau near -0.1 from
114+
> about 80 to 180 channels, peaks at -0.086 with 154 channels (the star), and falls to -0.29 with 200 channels and
115+
> -0.45 with all 206: the channels ranked last carry the response.
116+
117+
```matlab
118+
S = EEG.ieeglab.car.groups(1).stats; % CARLA's statistics for the site
119+
z = mean(S.zMinMean, 2); % one value per number of channels: mean of the 100 draws
120+
n = numel(S.chsUsed); % the number chosen
121+
figure; plot(z, 'k'); hold on; plot(n, z(n), 'p', 'MarkerSize', 14)
122+
xlabel('Channels in the common average'); ylabel('\zeta (Fisher z)')
123+
```
124+
125+
### 6. Common average, for comparison
126+
127+
In EEGLAB's **Datasets** menu, select the dataset that preprocessing made (before CARLA). Then **iEEGLAB > iEEG
128+
re-referencing**: *Common average (all good channels)*, with 2 in *Also leave out N contacts on each side*, so that both averages leave
129+
out the same contacts.
130+
131+
> **Expect.** 206 channels in the common average. Between 10 and 300 ms, its trial mean differs from CARLA's by up to
132+
> 23 uV, 134 ms after the pulse: the responses of the 52 channels that CARLA leaves out.
133+
134+
```matlab
135+
EEGcar = pop_ieeglab_reref(EEGpre, 'method', 'car', 'neighbors', 2);
136+
% the two common averages, trial mean
137+
G = EEG.ieeglab.car.groups(1); Gc = EEGcar.ieeglab.car.groups(1);
138+
avg = @(labels) mean(mean(EEGpre.data(ismember({EEGpre.chanlocs.labels}, labels), :, :), 3), 1);
139+
figure; plot(EEGpre.times, avg(Gc.reference) - avg(G.reference)); xlim([-100 500])
140+
xlabel('Time (ms)'); ylabel('Common average minus CARLA''s (uV)')
141+
```
142+
143+
### 7. CCEP analysis of both
144+
145+
**iEEGLAB > CCEP analysis**, defaults, once on the CARLA dataset and once on the common average dataset (select each
146+
in the **Datasets** menu). The response of each contact is described by the Canonical Response Parameterization (CRP;
147+
Miller et al., 2023), with a permutation test.
148+
149+
> **Expect.** A few seconds each. After CARLA, 89 of the 210 contacts respond; after the common average, 148 do. The common average subtracts the responses it carries from every contact, which can make contacts
150+
> without a response of their own look responsive (Huang et al., 2024).
151+
152+
```matlab
153+
opt = struct('run_n1', false, 'run_crp', true, 'run_matrix', true, 'matrix_source', 'crp');
154+
EEG = ieeglab_stats_subject(EEG, opt);
155+
EEGcar = ieeglab_stats_subject(EEGcar, opt);
156+
```
157+
158+
## Something differs?
159+
160+
If a result differs from *Expect*, a step fails, or a window is unclear, please open an
161+
[issue](https://github.com/sccn/iEEGLAB/issues) with the message and the MATLAB command window, and the MATLAB and
162+
EEGLAB versions and operating system.
163+
164+
## References
165+
166+
- Huang, H., Ojeda Valencia, G., Gregg, N. M., Osman, G. M., Montoya, M. N., Worrell, G. A., Miller, K. J., & Hermes,
167+
D. (2024). CARLA: Adjusted common average referencing for cortico-cortical evoked potential data. *Journal of
168+
Neuroscience Methods, 407*, 110153.
169+
- Miller, K. J., Müller, K.-R., Ojeda Valencia, G., Huang, H., Gregg, N. M., Worrell, G. A., & Hermes, D. (2023).
170+
Canonical response parameterization: Quantifying the structure of responses to single-pulse intracranial electrical
171+
brain stimulation. *PLOS Computational Biology, 19*(5), e1011105.

‎docs/Home.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ opens, and the same step from the command line.
1313
| [ECoG: cortico-cortical evoked potentials](2-ECoG-CCEP-ds004080.md) | ds004080 sub-ccepAgeUMCU02: an extract ships with the plugin, or one run from OpenNeuro | The same on fsaverage, with the common average and the N1 |
1414
| [FieldTrip tutorial data](3-FieldTrip-tutorial-data.md) | FieldTrip's SubjectUCI29 (205 MB download) | FieldTrip epochs, common average of the grids, bipolar depth leads, high-frequency activity tested against baseline, the comparison with FieldTrip |
1515
| [Re-referencing compared](4-Re-referencing-compared.md) | ds004696 sub-02, full recording | Six re-referencing schemes against the published CRP of this participant |
16+
| [CARLA on its authors' data](5-CARLA-ds004977.md) | ds004977 sub-1, run 2 (304 MB download) | CARLA with its authors' settings on the recording of their Figure 5, against the common average of every channel |
1617

1718
The same steps, with a checklist, are in `iEEGLAB_GUI_walkthrough.html` in the plugin folder (**Help > iEEGLAB
1819
documentation** in EEGLAB), and as one script in

‎docs/_Sidebar.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33
- [ECoG, CCEP (ds004080)](2-ECoG-CCEP-ds004080.md)
44
- [FieldTrip tutorial data](3-FieldTrip-tutorial-data.md)
55
- [Re-referencing compared](4-Re-referencing-compared.md)
6+
- [CARLA (ds004977)](5-CARLA-ds004977.md)
67
- [README](https://github.com/sccn/iEEGLAB#readme)

‎ieeglab_preprocess.m‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,7 @@
593593

594594
function local_plot_car_comparison(x, before, after, refName, chanLabel)
595595
mu = @(R) mean(R, 2, 'omitnan');
596-
sem = @(R) std(R, 0, 2, 'omitmissing') ./ sqrt(max(sum(~isnan(R), 2), 1));
596+
sem = @(R) std(R, 0, 2, 'omitnan') ./ sqrt(max(sum(~isnan(R), 2), 1)); % 'omitmissing' needs R2023a (issue #9)
597597
ieeglab_figure('Name','Re-referencing: before and after'); hold on
598598
ax = gca; co = ax.ColorOrder;
599599
band = @(m,s,c) fill([x; flipud(x)]', [m+s; flipud(m-s)]', c, 'FaceAlpha',0.2, 'EdgeColor', c);

0 commit comments

Comments
 (0)