Skip to contents

EEG Analysis Functions for PhysioExperiment Objects

PhysioEEG provides 79 exported functions covering the full electroencephalography analysis pipeline. Built on top of PhysioCore, it supports preprocessing, independent component analysis (ICA), event-related potential (ERP) extraction and measurement, source localization, microstate analysis, sleep staging, brain-computer interface (BCI) feature extraction, clinical EEG analysis, time-frequency decomposition, connectivity analysis, and publication-quality visualization – all operating directly on PhysioExperiment objects.

Installation

You can install PhysioEEG from r-universe:

install.packages("PhysioEEG",
  repos = c("https://x-biosignal.r-universe.dev", "https://cloud.r-project.org"))

Or install the development version from GitHub:

# install.packages("remotes")
remotes::install_github("x-biosignal/PhysioEEG")

Quick Start

library(PhysioEEG)

# Generate simulated EEG data with ERP components
pe <- make_eeg_erp(n_epochs = 40, n_channels = 19, sr = 250)

# Run full preprocessing pipeline (filter, re-reference, artifact rejection)
pe <- eegPreprocess(pe, lowcut = 1, highcut = 40, ref = "average")

# Detect and measure P300 component
erp <- eegERPdetect(pe, component = "P300")
measures <- eegERPmeasure(pe, component = "P300")

# Plot ERP waveform and topographic map
eegPlotERP(pe, channels = c("Fz", "Cz", "Pz"))
eegPlotTopomap(pe, time = 0.35)

# Inspect continuous channel traces and reference-dependent GFP together
continuous <- make_eeg(n_time = 2500, n_channels = 8, sr = 500)
eegPlotButterflyGFP(continuous, channels = c("Fz", "F3", "F4"))

Features

Preprocessing Pipeline

A complete, configurable preprocessing pipeline from raw recordings to analysis-ready data:

  • eegPreprocess() – full pipeline with configurable steps
  • eegFilter() – bandpass, highpass, lowpass, and notch filtering
  • eegMontage() – apply standard electrode montages (10-20, 10-10)
  • eegRereference() – re-reference to average, linked mastoids, or custom reference
  • eegBadChannels() – automatic bad channel detection by correlation, variance, and spectral criteria
  • eegInterpolate() – spherical spline interpolation of bad channels
  • eegEpoch() – segment continuous data into event-locked epochs
  • eegArtifactReject() – reject epochs by amplitude threshold, gradient, or statistical criteria

Independent Component Analysis (ICA)

Blind source separation for artifact removal and source identification:

  • eegICA() – decompose signals using FastICA, Infomax, or JADE algorithms
  • eegICAdetect() – automatic classification of artifact components (eye blinks, saccades, muscle, cardiac)
  • eegICAmix() – inspect mixing and unmixing matrices
  • eegICAremove() – remove selected components and reconstruct clean signals
  • eegPlotICA() – visualize component topographies, time courses, and spectra

End-to-end ERP component extraction, measurement, and statistical testing:

  • eegERPdetect() – detect standard components (N100, P300, N400, P600, MMN) with adaptive time windows
  • eegERPmeasure() – measure peak amplitude, peak latency, mean amplitude, and area
  • eegERPlatency() – fractional area latency and onset latency estimation
  • eegERPbaseline() – apply baseline correction with configurable windows
  • eegERPdifference() – compute difference waveforms between conditions
  • eegERPtest() – point-by-point and cluster-based permutation tests
  • eegERPgrandAverage() – compute grand average across subjects or sessions
  • eegPlotERP() – plot ERP waveforms with confidence intervals and condition overlays

Source Localization

Estimate the cortical sources underlying scalp EEG:

eegPlotGlassBrain() requires finite three-dimensional source coordinates; it never turns a bare amplitude vector into anatomical positions. Its shared type-8 threshold is computed from absolute amplitude before projection. Source-estimate orientation components are reduced by root-sum-square within time and RMS across time. The bundled outline is a schematic display frame, not MRI registration, patient anatomy, or validation of the inverse solution.

Microstate Analysis

Characterize the temporal dynamics of global brain states:

Sleep Staging and Event Detection

Automated sleep analysis following AASM guidelines:

Brain-Computer Interface (BCI) Features

Feature extraction and classification for BCI paradigms:

  • eegBCIfeatures() – extract multi-domain feature vectors (time, frequency, spatial)
  • eegCSP() – common spatial patterns for motor imagery discrimination
  • eegSSVEP() – steady-state visually evoked potential detection and classification
  • eegMotorImagery() – motor imagery feature extraction (mu/beta ERD/ERS)
  • eegBCIclassify() – classify BCI features with LDA, SVM, or random forest

Clinical EEG

Functions for clinical neurophysiology and QEEG:

Time-Frequency Analysis

Spectral decomposition with multiple methods:

  • eegMorletWavelet() – continuous wavelet transform with Morlet wavelets
  • eegSTFT() – short-time Fourier transform
  • eegMultitaper() – multitaper spectral estimation (DPSS tapers)
  • eegERSP() – event-related spectral perturbation
  • eegITC() – inter-trial coherence (phase-locking across trials)
  • eegPlotSpectrogram() – plot validated STFT, Morlet, ERSP, or legacy FFT grids with strictly aligned display masks

eegPlotSpectrogram() keeps numeric power unchanged when a mask is supplied: non-selected bins are dimmed with display alpha and logical boundaries are drawn without interpolating the mask. Logical masks and p-value matrices must match the complete pre-filter time and frequency axes exactly. Cluster masks require repeated, independent and exchangeable observations; the correction is for the maximum sign-separated four-neighbour cluster mass, so a corrected cluster is not bin-wise or mechanistic evidence.

Connectivity Analysis

Functional and effective connectivity between EEG channels:

  • eegCoherence() – magnitude-squared coherence
  • eegPLV() – phase-locking value
  • eegWPLI() – weighted phase lag index (robust to volume conduction)
  • eegGrangerCausality() – Granger causality for directed connectivity
  • eegConnectivityMatrix() – compute full connectivity matrices for any metric
  • eegPlotConnectivity() – legacy connectivity heatmaps and circle plots
  • eegPlotConnectogram() – deterministic directed/undirected circular views with anatomical or cluster ordering, module arcs, and optional edge bundling. Its strict absolute threshold is descriptive and does not imply corrected statistical significance.

Visualization

Publication-quality plots for every analysis stage:

Simulated Data Generators

Ready-to-use data for testing, demonstration, and teaching:

Dependencies

  • R (>= 4.2)
  • PhysioCore
  • SummarizedExperiment
  • S4Vectors
  • stats

PhysioExperiment Ecosystem

PhysioEEG is the EEG analysis layer of the PhysioExperiment ecosystem, a suite of R packages for multi-modal physiological signal analysis:

Package Description
PhysioCore Core data structures and accessors
PhysioIO File I/O (EDF, HDF5, BIDS, CSV, MAT)
PhysioPreprocess Preprocessing (filters, ICA, resampling)
PhysioAnalysis Analysis and visualization
PhysioEEG EEG analysis (ICA, ERP, source, BCI, sleep)
PhysioEMG EMG analysis (synergy, fatigue, onset)
PhysioECG ECG and HRV analysis

Visit the r-universe page to browse all available packages.

License

MIT License. See LICENSE for details.

Author

Yusuke Matsui

Governance & support

Part of the Physio ecosystem. Community and policy documents live in the umbrella repository: