Independent component analysis (ICA) is a crucial step in preprocessing EEG data, helping isolate different sources of signal and noise in the brain recordings. However, determining which ICA components to reject as noise after decomposition remains a manual task. To address this, I developed an automated post-ICA component helper rejection script in MATLAB.
Core Functionality
This function operates on EEG data structures post-ICA decomposition. Its primary aim is to automate the rejection of components likely representing artifacts. This is achieved through a series of steps:
Component Classification: Utilizing ICLabel, components are classified into categories such as 'Brain', 'Muscle', 'Eye', etc.
Variance Analysis: Each component's contribution to the dataset, measured by the variance accounted for (VAF), is calculated.
Threshold-Based Rejection: Components are selectively rejected based on a predefined variance threshold, ensuring only significant components are retained.
Optional Imaging: The function can optionally generate and save images of components marked for rejection using the viewprops EEGLAB plugin.
Data Cleaning: Post-rejection, the EEG data is cleaned, retaining only the relevant components.
The script has several key steps:
Classify components with ICLabel. This categorizes each component as brain signal, eye movement, heart signal, muscle noise etc.
Calculate variance accounted for by each component. This measures the contribution of the component to the overall EEG signal.
Identify components to remove based on preset criteria:
Variance threshold - components with very low variance are kept
Component categories - categories like eye, heart, muscle are rejected
Classification confidence - threshold on the ratio between the max and other classification scores
Save images of components marked for rejection. Useful for reviewing quality of rejection.
Remove marked components from the EEG to clean the data.
Emphasizing Low Variance Preservation
A feature of this function is its nuanced approach to component rejection. It specifically preserves components with low variance accounted for (PVAF), ensuring that only components above a certain variance threshold are considered for removal. This approach is critical in maintaining the integrity of the EEG data, particularly in preserving subtle but potentially significant neural signals.
Results Table
To enable customizable rejection criteria, component metrics are stored in data structures like matrices and tables:
compTable stores component number and variance accounted for
classification_table contains output of ICLabel
These are concatenated into ictable
ictable =
ComponentNumber | VarianceAccountedFor | Eye | Brain | Noise | Muscle | Remove?
-----------------------------------------------------------------------------
1 | 15 | 0.1 | 0.8 | 0.05 | 0.05 | false
2 | 25 | 0.8 | 0.1 | 0.05 | 0.05 | true
Additional columns are added for the maximum classification label, ratio of max-mean scores and finally the removal marking. Storing this in a table structure allows thresholding different metrics programmatically for flexible automated rejection. The pseudo-code checks each component's variance, category and classification confidence to determine if it should be kept or rejected. Image files are stored in the original data directory under the subfolder autopostcomps.
Usage
Like other functions in the VHTP pipeline, eeg_htpEegAutoPostComps takes in an EEG dataset that has already gone through some preprocessing steps, and outputs a modified EEG structure after performing automated post-ICA component rejection. The input EEG should be after ICA decomposition (containing ICA weights, component activations etc.) and ICLABEL but before manual component rejection. The output EEG_postcomps contains the cleaned EEG data with artifact components removed.
EEG_postcomps = eeg_htpEegAutoPostComps(EEG); % Apply automated rejection
The interface allows tweaking parameters like variance thresholds and categories for rejection. It also lets you toggle saving component images and whether to actually remove marked components.
ThresholdRatio
andVarianceThreshold
dictate the criteria for component rejection.PerformComponentRemoval
toggles the actual removal of identified components.SaveComponentImages
andRerunICLabel
offer additional control over the process.RemovalCategories
andBrainComponentOnlyMode
provide more targeted approaches to component rejection.
Dependencies
Under the hood, it utilizes established MATLAB toolboxes like EEGLAB, ICLabel and some helper functions. Key dependencies are - availability of ICA weights in the EEG structure, ICLabel for classification and variance calculations with viewprops.
This automated approach standardizes what is typically a tedious manual process. The ability to customize rejection criteria and select categories makes it adaptable to different study requirements. Saving component images enables quality checks to keep improving algorithm performance.
Conclusion
We are working on testing and validating the script, but the current source code is available on our vhtp github:
This automated approach standardizes what is typically a manual process. The ability to customize rejection criteria and select categories makes it adaptable to different study requirements. Saving component images enables quality checks to keep improving algorithm performance.