Getting Started with PhysioEEG
PhysioEEG provides comprehensive EEG analysis functions for PhysioExperiment objects. This vignette shows a quick tour of the main features.
Creating Test Data
PhysioEEG includes test data generators for quick exploration:
library(PhysioEEG)
# Basic 19-channel EEG (10-20 system)
pe <- make_eeg(n_time = 5000, n_channels = 19, sr = 500)
# EEG with embedded ERP components
pe_erp <- make_eeg_erp(n_epochs = 40, n_channels = 19, sr = 250)Independent Component Analysis (ICA)
Decompose EEG into independent components and remove artifacts:
# Run ICA
pe <- eegICA(pe, n_components = 19, method = "fastica")
# Detect artifact components automatically
artifacts <- eegICAdetect(pe, method = "kurtosis")
print(artifacts)
# Remove artifact components
artifact_idx <- artifacts$component[artifacts$type == "artifact"]
pe_clean <- eegICAremove(pe, components = artifact_idx)ERP Analysis
Detect and measure event-related potentials in epoched data:
pe_erp <- make_eeg_erp(n_epochs = 40, n_channels = 19, sr = 250)
# Detect P300 component
p300 <- eegERPdetect(pe_erp, component = "P300")
print(p300)
# Measure amplitude in a specific window
amp <- eegERPmeasure(pe_erp, window = c(250, 500), method = "mean",
polarity = "positive")
print(amp)Microstate Analysis
Segment EEG into discrete microstates:
pe <- make_eeg(n_time = 5000, n_channels = 19, sr = 500)
pe_ms <- eegMicrostates(pe, n_states = 4, method = "kmeans")
# Compute statistics
stats <- eegMicrostateStats(pe_ms)
print(stats)Brain-Computer Interface (BCI)
Motor imagery classification with CSP:
pe_bci <- make_eeg_bci(n_trials = 30, n_channels = 8, sr = 256)
labels <- metadata(pe_bci)$labels
# Extract CSP features
pe_csp <- eegCSP(pe_bci, labels = labels, n_filters = 3)
# Classify
features <- eegBCIfeatures(pe_bci, method = "bandpower")
results <- eegBCIclassify(pe_bci, features = features, labels = labels)
print(paste("Accuracy:", mean(results$predicted_class == labels)))Sleep Analysis
Automatic sleep staging and event detection:
pe_sleep <- make_eeg_sleep(n_time = 150000, n_channels = 2, sr = 500)
# Stage sleep
stages <- eegSleepStage(pe_sleep, epoch_sec = 30)
print(table(stages$stage))
# Detect spindles
spindles <- eegSpindleDetect(pe_sleep)
print(paste("Spindles detected:", nrow(spindles)))Clinical EEG Analysis
Spike detection, QEEG, and slowing assessment:
pe <- make_eeg(n_time = 5000, n_channels = 19, sr = 500)
# Detect EEG slowing
slowing <- eegSlowing(pe, method = "dtar")
print(slowing)
# Frontal alpha asymmetry
asym <- eegAsymmetry(pe)
print(asym)
# Burst-suppression detection
bs <- eegSuppression(pe, threshold = 10)
print(paste("BSR:", attr(bs, "bsr"), "%"))