R Package: eegwhiten
Published:
Package: eegwhiten (EEG Signal Whitening Toolkit)
Title: Whitening Transforms for EEG Covariance Matrices
Version: 0.1.0
Maintainer: Yiming Shen
License: MIT
Overview
eegwhiten provides whitening transforms with a simple fit/transform API for EEG covariance workflows. Data convention is rows as trials/epochs and columns as channels/features, with reusable model objects for cross-dataset transforms.
Key Methods (DESCRIPTION)
The package implements the following whitening transformations:
- PCA Whitening: Principal Component Analysis based whitening to maximize variance in orthogonal directions.
- PCA Whitening on Correlation Matrix: Correlation-standardized PCA variant.
- ZCA Whitening (Mahalanobis): Zero-phase Component Analysis, preserving the spatial arrangement of the original sensors while decorrelating them.
- ZCA Whitening on Correlation Matrix: Correlation-standardized ZCA variant.
- Cholesky Decomposition: Uses the Cholesky factor of the inverse covariance matrix for efficient whitening.
- SVD Whitening: Stable SVD-based whitening transformation.
Additional Utilities
- Reusable fitted whitening models for train/test consistency.
- Inverse transforms and basic diagnostics.
- Depends:
R (>= 3.6.0). - Suggests:
testthat (>= 3.0.0).
Installation & Usage
You can install the development version from GitHub:
# install.packages("devtools")
devtools::install_github("Yiming-S/eegwhiten")
Quick Start
library(eegwhiten)
# Apply ZCA whitening to an EEG epoch
# X is an [n_channels x n_timepoints] matrix
X_whitened <- eeg_whiten(X, method = "ZCA")
# Check correlation matrix (should be Identity)
print(round(cor(t(X_whitened)), 2))