Stage 3 – Final preprocessing - kevmtan/EEG-ICA-pipeline GitHub Wiki

Stage 3 is the final stage of the pipeline. Like Stage 2, it takes PREP'd EEG data and performs high-pass filtering and epoching. Stage 3 imports the ICA weight matrices and IC dipole models generated during Stage 2. The processing in Stage 3 is optimized for experimental analyses, which is why it's done separately from Stage 2.

Table of Contents

Initial Setup

Stage 3 is implemented in procFinal.m, which is called by a wrapper function, procFinal_wrapper.m. All parameters are found in the wrapper function.

Path & Directories

The top of procFinal_wrapper.m contains path and directory parameters. The wrapper takes subject # as an input, and assumes that your directory and filename structure is based on subject #. This can be changed in the code.
  • Edit the "custom pathdef" directory to match the location of your custom path file
  • Edit the folders to match your directory structure
  • Edit the full path of:
    • PREP'd EEG data from Stage 1: *_PREP.set
    • AMICA matrices from Stage 2: *_ICAf.mat
    • DIPFIT models from Stage 2: *_dipfit.mat
    • Parameter values from Stage 2: *_preproc.mat

Epoch & Channel parameters

The channel parameters are optimized for CMU Psych's BioSemi. Epoch parmeters depend on your paradigm
  • p.epEvents - events (trigger numbers) to make epochs around
  • p.epMin - epoch start (seconds before trigger)
  • p.epMax - epoch end (seconds after trigger)

Remove channels removed in Stage 2

During Stage 2, AMICA was run on data with some channels removed. The resulting ICA weight matrices correspond to the channel order in Stage 2. To import the final AMICA matrices and DIPFIT models during Stage 3, channel order must (initially) correspond to that of Stage 2

High-pass filter at 0.1Hz or less

High-pass filter data at 0.1Hz or less to avoid filtering artifacts in experimental analyses (Rousselet et al., 2012). This is different from Stage 2, which filtered to optimize ICA decomposition.

Epoch without baseline correction

Epoch without baseline correction. Baseline correction should be done later, after artifactual IC subtraction and interpolation of removed channels.

Import trial data into epoch structure

If trial data (e.g. from Psychtoolbox) was saved for your task/experiment, you can import these as added fields in the EEG.epochs structure. The EEG.epoch index matches the last dimension of the EEG.data and EEG.icaact matrices. EEG.epoch contains epoch information, while EEG.data/EEG.icaact contains EEG activity in channel space and IC space, respectively.

Importing trial info should be done prior to epoch rejection, so that the epoch indices in EEGLAB will match trial number in your task/experiment.

Importing trial info is not implemented in the code, as this is highly experiment-dependent. Example code is included as comments in procFinal.m.

Generate ICs

ICs are generated by importing the weight matrices from the final AMICA run saved during Stage 2 (*_ICAf.mat).

Remove artifactual ICs

Remove artifactual ICs from Stage 2

Remove/subtract the artifactual ICs identified during stage Stage 2. This must be done as DIPFIT was only performed on the neurogenic ICs in Stage 2. The indices of artifactual ICs are stored in the preproc.mat file that was saved at the end of Stage 2. After removal of these ICs, the IC indices in EEGLAB and the DIPFIT struct will match.

Remove ICs with poor dipole model fit (optional)

Remove/subtract ICs whose DIPFIT models have high residual variance (RV). Neurogenic ICs have been shown to be dipolar, and can be fitted with 1 or 2 equivalent dipoles witb low RV (Delorme et al., 2012). ICs with high DIPFIT RV are likely artifactual, and thus can be subtracted from the data. In the wrapper, the RV cutoff is 20%+. This can be changed to be more or less conservative; lowering the % RV threshold will remove more ICs.
The high-RV ICs must be removed in both the EEG and DIPFIT data, so the EEGLAB and DIPFIT IC indices still match each other. This is performed in the procFinal.m function.

Interpolate removed channels

The scalp channels removed during Stage 2 can now be interpolated, producing data without any missing scalp channels. The mastoids should not be interpolated as they don't have standard positions to use for interpolation.

Baseline correction

Baseline correction is done on a per-epoch/per-channel basis. Usually, for a given channel and epoch, the average pre-event amplitude is calculated then subtracted from the entire epoch. Thus, the average pre-stimulus activation is used as a "baseline" for event-evoked activity in an epocb. This is standard for most epoch-based EEG analyses, such as ERP and ERSP.

For example, for an epoch consisting of -500 to 1000 ms relative to an event (e.g. stimulus onset), the average amplitude of a channel at -500 to 0 ms would be subtracted from that channel's activation for that specific epoch. A specific baseline period can also be used (e.g. -200 to 0 ms).

The start of the baseline period can be changed in the wrapper (in ms; negative values indicate pre-event, positive post-event).

Epoch rejection

Activity for the remaining ICs are used for epoch rejection. Epoch rejection uses statistical thresholding (z-score thresholds) for the following parameters. These are evaluated, using different parameter values, for individual ICs and all ICs. The all-IC thresholds should be more stringent, as anomalous activity in all ICs may more likely be artifactual than anomalous activity in a single IC.

  • Max and min amplitude (absolute threshold)
  • Amplitude improbability
  • Temporal kurtosis
  • Spectral power of ECG-associated frequencies

Import DIPFIT model into EEG structure

The DIPFIT .mat file contains dipole models of ICs that remained after artifactual IC subtraction in Stage 2. If no additional IC subtraction was done in Stage 3, the IC indices in EEGLAB (e.g. first dimension of EEG.icaact) and the dipfit struct should match. If additional IC subtraction was done in Stage 3 (e.g. remove high-RV ICs), the indexes of the removed ICs should be removed from the dipfit struct - this is done automatically in the code.

Separate epochs by condition

If you want to do experimental analyses using EEGLAB's study structure, epochs corresponding to each experimental condition must be saved as separate .set files.

Fields in the EEG.epochs struct can be used for separating epochs by condition. During epoching, a EEG.epoch(i).event field is generated, which contains the event type (e.g. Biosemi trigger) that that epoch was time-locked to. Additional trial data can be imported as fields in EEG.epoch (detailed above) for more flexible means of epoch separation and subsequent analyses.

Separating epochs per condition is not implemented in the supplied code as this is highly dependent on the needs of the researcher. However, example code for a specific experiment is included at the end of procFinal.m.

Notes

On the latest versions of EEGLAB, if you import the DIPFIT models before additional artifactual IC subtration (e.g. for high-RV ICs), doing additional IC subtraction may automatically remove the DIPFIT models associated with the removed ICs. Haven't tested this out though.

⚠️ **GitHub.com Fallback** ⚠️