| Title: | Cross-Modal Coupling Analysis for PhysioExperiment Objects |
|---|---|
| Description: | Provides cross-modal coupling, connectivity, and synchrony analysis between physiological signals of different modalities (EEG, EMG, ECG, EDA, MoCap, fNIRS, etc.). Introduces a MultiPhysioExperiment container class for holding multiple PhysioExperiment objects at different sampling rates with temporal alignment. Includes spectral coherence, phase synchrony (PLV, PLI, wPLI), directed coupling (Granger causality), and time-domain coupling (cross-correlation) methods. |
| Authors: | Yusuke Matsui |
| Maintainer: | Yusuke Matsui <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.4.0 |
| Built: | 2026-05-16 05:38:52 UTC |
| Source: | https://github.com/x-biosignal/PhysioCrossModal |
Package on-load hook
.onLoad(libname, pkg).onLoad(libname, pkg)
libname |
Library path. |
pkg |
Package name. |
Provides flexible subsetting of MultiPhysioExperiment objects:
mpe[, "eeg"] – select modalities by name, returns a new MPE
mpe[c(1.0, 5.0), ] – select a time window in seconds across
all modalities, accounting for each modality's sampling rate
mpe[c(1.0, 5.0), "eeg"] – both time and modality subsetting
## S4 method for signature 'MultiPhysioExperiment,ANY,ANY,ANY' x[i, j, ..., drop = FALSE]## S4 method for signature 'MultiPhysioExperiment,ANY,ANY,ANY' x[i, j, ..., drop = FALSE]
x |
A |
i |
Numeric vector of length 2 specifying time range |
j |
Character vector of modality names, or missing. |
... |
Additional arguments (not used). |
drop |
Logical (not used). |
When i is a numeric vector of length 2, it is interpreted as a time
range [tmin, tmax] in seconds.
For each modality, the appropriate sample indices are computed from its
sampling rate:
start_idx = floor(tmin * sr) + 1, end_idx = floor(tmax * sr) + 1,
clamped to valid bounds.
A MultiPhysioExperiment object with the selected
modalities and/or time windows.
eeg_data <- matrix(rnorm(2500 * 4), nrow = 2500, ncol = 4) emg_data <- matrix(rnorm(5000 * 2), nrow = 5000, ncol = 2) pe_eeg <- PhysioExperiment( assays = list(raw = eeg_data), samplingRate = 500 ) pe_emg <- PhysioExperiment( assays = list(raw = emg_data), samplingRate = 1000 ) mpe <- MultiPhysioExperiment(EEG = pe_eeg, EMG = pe_emg) # Subset by modality mpe_eeg <- mpe[, "EEG"] modalities(mpe_eeg) # "EEG" # Subset by time range (seconds) mpe_win <- mpe[c(1.0, 3.0), ] # Combined mpe_sub <- mpe[c(1.0, 3.0), "EEG"]eeg_data <- matrix(rnorm(2500 * 4), nrow = 2500, ncol = 4) emg_data <- matrix(rnorm(5000 * 2), nrow = 5000, ncol = 2) pe_eeg <- PhysioExperiment( assays = list(raw = eeg_data), samplingRate = 500 ) pe_emg <- PhysioExperiment( assays = list(raw = emg_data), samplingRate = 1000 ) mpe <- MultiPhysioExperiment(EEG = pe_eeg, EMG = pe_emg) # Subset by modality mpe_eeg <- mpe[, "EEG"] modalities(mpe_eeg) # "EEG" # Subset by time range (seconds) mpe_win <- mpe[c(1.0, 3.0), ] # Combined mpe_sub <- mpe[c(1.0, 3.0), "EEG"]
Extract a single modality from a MultiPhysioExperiment
## S4 method for signature 'MultiPhysioExperiment,ANY,ANY' x[[i, j, ...]]## S4 method for signature 'MultiPhysioExperiment,ANY,ANY' x[[i, j, ...]]
x |
A |
i |
Modality name (character) or index (integer). |
j |
Not used. |
... |
Additional arguments (not used). |
A PhysioExperiment object.
eeg_data <- matrix(rnorm(500 * 2), nrow = 500, ncol = 2) pe_eeg <- PhysioExperiment( assays = list(raw = eeg_data), samplingRate = 250 ) mpe <- MultiPhysioExperiment(EEG = pe_eeg) mpe[["EEG"]]eeg_data <- matrix(rnorm(500 * 2), nrow = 500, ncol = 2) pe_eeg <- PhysioExperiment( assays = list(raw = eeg_data), samplingRate = 250 ) mpe <- MultiPhysioExperiment(EEG = pe_eeg) mpe[["EEG"]]
Get or set temporal alignment metadata
alignment(x) ## S4 method for signature 'MultiPhysioExperiment' alignment(x) alignment(x) <- value ## S4 replacement method for signature 'MultiPhysioExperiment' alignment(x) <- valuealignment(x) ## S4 method for signature 'MultiPhysioExperiment' alignment(x) alignment(x) <- value ## S4 replacement method for signature 'MultiPhysioExperiment' alignment(x) <- value
x |
A |
value |
A |
A DataFrame.
alignSignals(), experiments(), samplingRates()
eeg_data <- matrix(rnorm(500 * 2), nrow = 500, ncol = 2) pe_eeg <- PhysioExperiment( assays = list(raw = eeg_data), samplingRate = 250 ) mpe <- MultiPhysioExperiment(EEG = pe_eeg) alignment(mpe)eeg_data <- matrix(rnorm(500 * 2), nrow = 500, ncol = 2) pe_eeg <- PhysioExperiment( assays = list(raw = eeg_data), samplingRate = 250 ) mpe <- MultiPhysioExperiment(EEG = pe_eeg) alignment(mpe)
Takes two or more named PhysioExperiment objects and resamples them
so they all share a single sampling rate, then wraps the result in a
MultiPhysioExperiment.
alignSignals( ..., method = c("lowest_rate", "common_rate", "resample"), target_rate = NULL )alignSignals( ..., method = c("lowest_rate", "common_rate", "resample"), target_rate = NULL )
... |
Named |
method |
Character: one of |
target_rate |
Numeric scalar: required when |
Three alignment strategies are available:
"lowest_rate"(default) Resample all signals to the lowest sampling rate present.
"common_rate"Resample all signals to the highest sampling rate present.
"resample"Resample all signals to the rate given by
target_rate (which must be supplied).
If every input already shares the same sampling rate, no resampling is performed regardless of the chosen method.
A MultiPhysioExperiment containing the (possibly
resampled) input objects.
alignToRate(), mergePhysio(),
MultiPhysioExperiment(), couplingAnalysis()
eeg <- PhysioExperiment( assays = list(raw = matrix(rnorm(500 * 2), nrow = 500)), samplingRate = 500 ) emg <- PhysioExperiment( assays = list(raw = matrix(rnorm(1000 * 2), nrow = 1000)), samplingRate = 1000 ) mpe <- alignSignals(EEG = eeg, EMG = emg, method = "lowest_rate")eeg <- PhysioExperiment( assays = list(raw = matrix(rnorm(500 * 2), nrow = 500)), samplingRate = 500 ) emg <- PhysioExperiment( assays = list(raw = matrix(rnorm(1000 * 2), nrow = 1000)), samplingRate = 1000 ) mpe <- alignSignals(EEG = eeg, EMG = emg, method = "lowest_rate")
Resamples all assays in a PhysioExperiment object so that the
resulting data correspond to the specified target sampling rate. If the
PhysioPreprocess package is available and method = "linear",
its resample() function is used; otherwise an internal
interpolation is applied.
alignToRate(x, target_rate, method = c("linear", "spline", "fft"))alignToRate(x, target_rate, method = c("linear", "spline", "fft"))
x |
A |
target_rate |
Numeric scalar: desired sampling rate in Hz. |
method |
Character: resampling method. One of |
A new PhysioExperiment with resampled data and updated
samplingRate. The assay name is preserved from the original.
alignSignals(), mergePhysio(),
MultiPhysioExperiment()
eeg_data <- matrix(rnorm(1000 * 4), nrow = 1000, ncol = 4) pe <- PhysioExperiment( assays = list(raw = eeg_data), colData = S4Vectors::DataFrame( label = paste0("Ch", 1:4), type = rep("EEG", 4) ), samplingRate = 1000 ) pe500 <- alignToRate(pe, target_rate = 500) samplingRate(pe500) # 500eeg_data <- matrix(rnorm(1000 * 4), nrow = 1000, ncol = 4) pe <- PhysioExperiment( assays = list(raw = eeg_data), colData = S4Vectors::DataFrame( label = paste0("Ch", 1:4), type = rep("EEG", 4) ), samplingRate = 1000 ) pe500 <- alignToRate(pe, target_rate = 500) samplingRate(pe500) # 500
Computes a bootstrap confidence interval for the coupling statistic between two signals using the moving-block bootstrap (to preserve temporal autocorrelation).
bootstrapCI( x, y = NULL, sr = NULL, method, n_boot = 199L, ci = 0.95, block_len = NULL, modality_x = NULL, modality_y = NULL, channels_x = 1L, channels_y = 1L, cores = 1L, ... )bootstrapCI( x, y = NULL, sr = NULL, method, n_boot = 199L, ci = 0.95, block_len = NULL, modality_x = NULL, modality_y = NULL, channels_x = 1L, channels_y = 1L, cores = 1L, ... )
x |
Numeric vector, PhysioExperiment, or MultiPhysioExperiment. |
y |
Numeric vector or PhysioExperiment, or NULL when |
sr |
Numeric sampling rate in Hz (required when x/y are numeric). |
method |
Character coupling method (same options as
|
n_boot |
Integer number of bootstrap replicates (default 199). |
ci |
Numeric confidence level (default 0.95). |
block_len |
Integer block length for block bootstrap, or NULL for
automatic ( |
modality_x, modality_y
|
Character modality names for MPE input. |
channels_x, channels_y
|
Integer channel indices (default 1). |
cores |
Integer number of parallel cores to use (default |
... |
Additional arguments passed to the coupling function. |
A list with components:
The full coupling result from the original signals.
Numeric scalar: the extracted coupling statistic.
Numeric scalar: lower CI bound.
Numeric scalar: upper CI bound.
Numeric scalar: confidence level used.
Numeric vector of bootstrap statistics.
Efron, B., & Tibshirani, R. J. (1993). An Introduction to the Bootstrap. Chapman & Hall/CRC.
surrogateTest(), couplingAnalysis()
sr <- 500 t <- seq(0, 2, length.out = sr * 2) x <- sin(2 * pi * 10 * t) + 0.3 * rnorm(length(t)) y <- 0.8 * sin(2 * pi * 10 * t) + 0.3 * rnorm(length(t)) result <- bootstrapCI(x, y, sr = sr, method = "coherence", n_boot = 19, nperseg = 128L) c(result$ci_lower, result$ci_upper)sr <- 500 t <- seq(0, 2, length.out = sr * 2) x <- sin(2 * pi * 10 * t) + 0.3 * rnorm(length(t)) y <- 0.8 * sin(2 * pi * 10 * t) + 0.3 * rnorm(length(t)) result <- bootstrapCI(x, y, sr = sr, method = "coherence", n_boot = 19, nperseg = 128L) c(result$ci_lower, result$ci_upper)
Computes the magnitude-squared coherence between two signals, which quantifies the linear frequency-domain relationship between them. The coherence is defined as:
where is the cross-spectral density and ,
are the auto-spectral densities.
coherence( x, y = NULL, sr = NULL, freq_range = NULL, nperseg = 256L, noverlap = NULL, method = c("welch", "multitaper"), modality_x = NULL, modality_y = NULL, channels_x = 1L, channels_y = 1L )coherence( x, y = NULL, sr = NULL, freq_range = NULL, nperseg = 256L, noverlap = NULL, method = c("welch", "multitaper"), modality_x = NULL, modality_y = NULL, channels_x = 1L, channels_y = 1L )
x |
Numeric vector, PhysioExperiment, or MultiPhysioExperiment. |
y |
Numeric vector or PhysioExperiment, or NULL when |
sr |
Numeric sampling rate in Hz (required when x/y are numeric). |
freq_range |
Numeric vector of length 2 giving the frequency range
|
nperseg |
Integer segment length for Welch's method (default 256). |
noverlap |
Integer overlap between segments, or NULL for
|
method |
Character spectral estimation method. Currently only
|
modality_x |
Character modality name in MPE for the x signal. |
modality_y |
Character modality name in MPE for the y signal. |
channels_x |
Integer which channel to extract from x (default 1). |
channels_y |
Integer which channel to extract from y (default 1). |
Unlike the coherence() function in PhysioAnalysis (which computes
coherence across all channel pairs within a single PhysioExperiment),
this function is designed for cross-modal analysis: it takes two separate
signals (or PhysioExperiment / MultiPhysioExperiment objects) and computes
the pairwise coherence between them.
A named list with components:
Numeric vector of magnitude-squared coherence values
in at each frequency.
Numeric vector of corresponding frequencies in Hz.
Numeric scalar giving the 95\
threshold: 1 - alpha^(1 / (L - 1)) where alpha = 0.05 and
L is the number of segments (Halliday et al. 1995). Coherence
values above this limit are statistically significant.
Integer number of segments used in Welch estimation.
Carter, G. C. (1987). Coherence and time delay estimation. Proceedings of the IEEE, 75(2), 236–255.
Halliday, D. M., Rosenberg, J. R., Amjad, A. M., Breeze, P., Conway, B. A., & Farmer, S. F. (1995). A framework for the analysis of mixed time series/point process data – theory and application to the study of physiological tremor, single motor unit discharges and electromyograms. Progress in Biophysics and Molecular Biology, 64(2–3), 237–278.
crossSpectrum(), multitaperCoherence(),
coherenceMatrix(), couplingAnalysis()
# Two coupled 20 Hz sinusoids sr <- 500 t <- seq(0, 10, length.out = sr * 10) x <- sin(2 * pi * 20 * t) + 0.2 * rnorm(length(t)) y <- 0.8 * sin(2 * pi * 20 * t) + 0.2 * rnorm(length(t)) result <- coherence(x, y, sr = sr) plot(result$frequencies, result$coherence, type = "l", xlab = "Frequency (Hz)", ylab = "Coherence") abline(h = result$confidence_limit, lty = 2, col = "red")# Two coupled 20 Hz sinusoids sr <- 500 t <- seq(0, 10, length.out = sr * 10) x <- sin(2 * pi * 20 * t) + 0.2 * rnorm(length(t)) y <- 0.8 * sin(2 * pi * 20 * t) + 0.2 * rnorm(length(t)) result <- coherence(x, y, sr = sr) plot(result$frequencies, result$coherence, type = "l", xlab = "Frequency (Hz)", ylab = "Coherence") abline(h = result$confidence_limit, lty = 2, col = "red")
Computes magnitude-squared coherence for all pairs of channels between two sets of signals (or between all channels within a single set). Returns a matrix of peak coherence values plus the full spectra.
coherenceMatrix( x, y = NULL, sr = NULL, channels_x = NULL, channels_y = NULL, modality_x = NULL, modality_y = NULL, ... )coherenceMatrix( x, y = NULL, sr = NULL, channels_x = NULL, channels_y = NULL, modality_x = NULL, modality_y = NULL, ... )
x |
A PhysioExperiment or MultiPhysioExperiment object. |
y |
A PhysioExperiment, or NULL when |
sr |
Numeric sampling rate in Hz (used only for numeric inputs). |
channels_x |
Integer vector of channel indices for x, or NULL for all channels. |
channels_y |
Integer vector of channel indices for y, or NULL for all channels. |
modality_x, modality_y
|
Character modality names for MPE input. |
... |
Additional arguments passed to |
A list with components:
Numeric matrix of peak coherence values, with
dimensions [n_channels_x x n_channels_y].
List of lists containing the full coherence result for each pair.
Numeric vector of frequencies from the first pair.
Character vector of x channel names.
Character vector of y channel names.
Carter, G. C. (1987). Coherence and time delay estimation. Proceedings of the IEEE, 75(2), 236–255.
coherence(), couplingMatrix(), plotCouplingMatrix(),
surrogateMatrixTest()
sr <- 200; n <- sr * 2 pe1 <- PhysioExperiment( assays = list(raw = matrix(rnorm(n * 2), nrow = n)), samplingRate = sr ) pe2 <- PhysioExperiment( assays = list(raw = matrix(rnorm(n * 2), nrow = n)), samplingRate = sr ) result <- coherenceMatrix(pe1, pe2, nperseg = 64L) result$matrixsr <- 200; n <- sr * 2 pe1 <- PhysioExperiment( assays = list(raw = matrix(rnorm(n * 2), nrow = n)), samplingRate = sr ) pe2 <- PhysioExperiment( assays = list(raw = matrix(rnorm(n * 2), nrow = n)), samplingRate = sr ) result <- coherenceMatrix(pe1, pe2, nperseg = 64L) result$matrix
Dispatches to the appropriate coupling function based on the method
parameter. Accepts the same flexible inputs as the underlying functions:
two numeric vectors (with sr), two PhysioExperiment objects, or a
MultiPhysioExperiment with named modalities.
couplingAnalysis( x, y = NULL, mpe = NULL, modality_x = NULL, modality_y = NULL, channels_x = 1L, channels_y = 1L, method = c("coherence", "plv", "pli", "wpli", "granger", "crosscorrelation", "wavelet_coherence", "wavelet_plv", "multitaper_coherence"), sr = NULL, ... )couplingAnalysis( x, y = NULL, mpe = NULL, modality_x = NULL, modality_y = NULL, channels_x = 1L, channels_y = 1L, method = c("coherence", "plv", "pli", "wpli", "granger", "crosscorrelation", "wavelet_coherence", "wavelet_plv", "multitaper_coherence"), sr = NULL, ... )
x |
Numeric vector, PhysioExperiment, or MultiPhysioExperiment.
When |
y |
Numeric vector or PhysioExperiment (NULL when |
mpe |
A |
modality_x, modality_y
|
Character names of the modalities to extract
from |
channels_x, channels_y
|
Integer channel indices to extract (default 1). |
method |
Character string specifying the coupling method. One of:
|
sr |
Numeric sampling rate in Hz. Required when |
... |
Additional arguments passed to the specific coupling function
(e.g. |
The result from the dispatched coupling function. See individual function documentation for details:
"coherence": see coherence
"plv": see phaseLockingValue
"pli": see phaseLagIndex
"wpli": see weightedPLI
"granger": see grangerCausality
"crosscorrelation": see crossCorrelation
"wavelet_coherence": see waveletCoherence
"wavelet_plv": see waveletPLV
Carter, G. C. (1987). Coherence and time delay estimation. Proceedings of the IEEE, 75(2), 236–255.
Lachaux, J.-P., Rodriguez, E., Martinerie, J., & Varela, F. J. (1999). Measuring phase synchrony in brain signals. Human Brain Mapping, 8(4), 194–208.
Granger, C. W. J. (1969). Investigating causal relations by econometric models and cross-spectral methods. Econometrica, 37(3), 424–438.
coherence(), phaseLockingValue(), grangerCausality(),
crossCorrelation(), surrogateTest()
# Numeric vectors sr <- 500 t <- seq(0, 10, length.out = sr * 10) x <- sin(2 * pi * 20 * t) + 0.2 * rnorm(length(t)) y <- 0.8 * sin(2 * pi * 20 * t) + 0.2 * rnorm(length(t)) # Coherence res <- couplingAnalysis(x, y, method = "coherence", sr = sr) # Cross-correlation res <- couplingAnalysis(x, y, method = "crosscorrelation", sr = sr)# Numeric vectors sr <- 500 t <- seq(0, 10, length.out = sr * 10) x <- sin(2 * pi * 20 * t) + 0.2 * rnorm(length(t)) y <- 0.8 * sin(2 * pi * 20 * t) + 0.2 * rnorm(length(t)) # Coherence res <- couplingAnalysis(x, y, method = "coherence", sr = sr) # Cross-correlation res <- couplingAnalysis(x, y, method = "crosscorrelation", sr = sr)
Computes any coupling method for all pairs of channels between two
sets of signals, extracting a scalar statistic for each pair. This
is the multi-channel generalisation of couplingAnalysis.
couplingMatrix( x, y = NULL, sr = NULL, method, channels_x = NULL, channels_y = NULL, modality_x = NULL, modality_y = NULL, ... )couplingMatrix( x, y = NULL, sr = NULL, method, channels_x = NULL, channels_y = NULL, modality_x = NULL, modality_y = NULL, ... )
x |
A PhysioExperiment or MultiPhysioExperiment object. |
y |
A PhysioExperiment, or NULL when |
sr |
Numeric sampling rate in Hz. |
method |
Character coupling method, one of |
channels_x, channels_y
|
Integer vectors of channel indices, or NULL for all channels. |
modality_x, modality_y
|
Character modality names for MPE input. |
... |
Additional arguments passed to the coupling function. |
A list with components:
Numeric matrix of coupling values.
Character method used.
Character vector of x channel names.
Character vector of y channel names.
Carter, G. C. (1987). Coherence and time delay estimation. Proceedings of the IEEE, 75(2), 236–255.
couplingAnalysis(), coherenceMatrix(),
plotCouplingMatrix(), surrogateMatrixTest()
sr <- 200; n <- sr * 2 pe1 <- PhysioExperiment( assays = list(raw = matrix(rnorm(n * 2), nrow = n)), samplingRate = sr ) pe2 <- PhysioExperiment( assays = list(raw = matrix(rnorm(n * 2), nrow = n)), samplingRate = sr ) result <- couplingMatrix(pe1, pe2, method = "coherence", nperseg = 64L) result$matrixsr <- 200; n <- sr * 2 pe1 <- PhysioExperiment( assays = list(raw = matrix(rnorm(n * 2), nrow = n)), samplingRate = sr ) pe2 <- PhysioExperiment( assays = list(raw = matrix(rnorm(n * 2), nrow = n)), samplingRate = sr ) result <- couplingMatrix(pe1, pe2, method = "coherence", nperseg = 64L) result$matrix
Computes the cross-correlation between two signals at various lags,
measuring their time-domain coupling. Cross-correlation quantifies how
similar one signal is to a time-shifted version of another. A positive
peak lag indicates that y leads x (i.e., y must be shifted forward
to align with x), while a negative peak lag indicates x leads y.
crossCorrelation( x, y = NULL, sr = NULL, max_lag = NULL, normalize = TRUE, modality_x = NULL, modality_y = NULL, channels_x = 1L, channels_y = 1L )crossCorrelation( x, y = NULL, sr = NULL, max_lag = NULL, normalize = TRUE, modality_x = NULL, modality_y = NULL, channels_x = 1L, channels_y = 1L )
x |
Numeric vector, PhysioExperiment, or MultiPhysioExperiment. |
y |
Numeric vector or PhysioExperiment, or NULL when |
sr |
Numeric sampling rate in Hz (required when x/y are numeric). |
max_lag |
Integer maximum lag in samples. If NULL, defaults to
|
normalize |
Logical; if TRUE (default), compute normalized cross-correlation (Pearson-like, values in [-1, 1]). |
modality_x |
Character modality name in MPE for the x signal. |
modality_y |
Character modality name in MPE for the y signal. |
channels_x |
Integer which channel to extract from x (default 1). |
channels_y |
Integer which channel to extract from y (default 1). |
The function accepts numeric vectors, PhysioExperiment objects, or a
MultiPhysioExperiment with named modalities, using
.extract_signal_pair() internally for flexible input handling.
A named list with components:
Numeric vector of cross-correlation values at each lag.
Integer vector of lag values in samples.
Numeric vector of lag values in seconds.
Integer lag (in samples) at which the absolute correlation is maximised.
Numeric peak lag converted to seconds.
Numeric cross-correlation value at the peak lag.
Chatfield, C. (2004). The Analysis of Time Series: An Introduction (6th ed.). Chapman & Hall/CRC.
slidingCrossCorrelation(), coherence(),
couplingAnalysis()
# Simple example: y is a delayed copy of x sr <- 500 set.seed(1) x <- rnorm(1000) y <- c(rep(0, 10), x[1:990]) result <- crossCorrelation(x, y, sr = sr) result$peak_lag # should be 10 result$peak_lag_seconds# Simple example: y is a delayed copy of x sr <- 500 set.seed(1) x <- rnorm(1000) y <- c(rep(0, 10), x[1:990]) result <- crossCorrelation(x, y, sr = sr) result$peak_lag # should be 10 result$peak_lag_seconds
Computes the cross-spectral density (CSD) between two signals using Welch's method. The CSD captures both the magnitude and phase relationship between two signals as a function of frequency.
crossSpectrum( x, y = NULL, sr = NULL, nperseg = 256L, noverlap = NULL, modality_x = NULL, modality_y = NULL, channels_x = 1L, channels_y = 1L )crossSpectrum( x, y = NULL, sr = NULL, nperseg = 256L, noverlap = NULL, modality_x = NULL, modality_y = NULL, channels_x = 1L, channels_y = 1L )
x |
Numeric vector, PhysioExperiment, or MultiPhysioExperiment. |
y |
Numeric vector or PhysioExperiment, or NULL when |
sr |
Numeric sampling rate in Hz (required when x/y are numeric). |
nperseg |
Integer segment length for Welch's method (default 256). |
noverlap |
Integer overlap between segments, or NULL for
|
modality_x |
Character modality name in MPE for the x signal. |
modality_y |
Character modality name in MPE for the y signal. |
channels_x |
Integer which channel to extract from x (default 1). |
channels_y |
Integer which channel to extract from y (default 1). |
A named list with components:
Complex vector of cross-spectral density values.
Numeric vector of corresponding frequencies in Hz.
Numeric vector of CSD magnitude (Mod(csd)).
Numeric vector of CSD phase in radians (Arg(csd)).
Carter, G. C. (1987). Coherence and time delay estimation. Proceedings of the IEEE, 75(2), 236–255.
Halliday, D. M., Rosenberg, J. R., Amjad, A. M., Breeze, P., Conway, B. A., & Farmer, S. F. (1995). A framework for the analysis of mixed time series/point process data – theory and application to the study of physiological tremor, single motor unit discharges and electromyograms. Progress in Biophysics and Molecular Biology, 64(2–3), 237–278.
coherence(), multitaperCoherence(), couplingAnalysis()
sr <- 500 t <- seq(0, 5, length.out = sr * 5) x <- sin(2 * pi * 10 * t) + 0.1 * rnorm(length(t)) y <- cos(2 * pi * 10 * t) + 0.1 * rnorm(length(t)) result <- crossSpectrum(x, y, sr = sr) plot(result$frequencies, result$magnitude, type = "l", xlab = "Frequency (Hz)", ylab = "|CSD|")sr <- 500 t <- seq(0, 5, length.out = sr * 5) x <- sin(2 * pi * 10 * t) + 0.1 * rnorm(length(t)) y <- cos(2 * pi * 10 * t) + 0.1 * rnorm(length(t)) result <- crossSpectrum(x, y, sr = sr) plot(result$frequencies, result$magnitude, type = "l", xlab = "Frequency (Hz)", ylab = "|CSD|")
Get or set the experiments list
experiments(x) ## S4 method for signature 'MultiPhysioExperiment' experiments(x) experiments(x) <- value ## S4 replacement method for signature 'MultiPhysioExperiment' experiments(x) <- valueexperiments(x) ## S4 method for signature 'MultiPhysioExperiment' experiments(x) experiments(x) <- value ## S4 replacement method for signature 'MultiPhysioExperiment' experiments(x) <- value
x |
A |
value |
A named list of |
For the getter, a named list of PhysioExperiment objects.
For the setter, the modified MultiPhysioExperiment (returned
invisibly).
MultiPhysioExperiment(), modalities(), samplingRates()
eeg_data <- matrix(rnorm(500 * 2), nrow = 500, ncol = 2) pe_eeg <- PhysioExperiment( assays = list(raw = eeg_data), samplingRate = 250 ) mpe <- MultiPhysioExperiment(EEG = pe_eeg) experiments(mpe)eeg_data <- matrix(rnorm(500 * 2), nrow = 500, ncol = 2) pe_eeg <- PhysioExperiment( assays = list(raw = eeg_data), samplingRate = 250 ) mpe <- MultiPhysioExperiment(EEG = pe_eeg) experiments(mpe)
Computes directed coupling between two physiological signals using Granger causality. The method fits bivariate autoregressive (AR) models to quantify how much one signal helps predict the other beyond its own past. Both time-domain and spectral (frequency-resolved) Granger causality are supported.
grangerCausality( x, y = NULL, sr = NULL, order = 5L, freq_range = NULL, method = c("parametric", "nonparametric"), modality_x = NULL, modality_y = NULL, channels_x = 1L, channels_y = 1L )grangerCausality( x, y = NULL, sr = NULL, order = 5L, freq_range = NULL, method = c("parametric", "nonparametric"), modality_x = NULL, modality_y = NULL, channels_x = 1L, channels_y = 1L )
x |
Numeric vector, PhysioExperiment, or MultiPhysioExperiment. |
y |
Numeric vector or PhysioExperiment, or NULL when |
sr |
Numeric sampling rate in Hz (required when x/y are numeric vectors). |
order |
Integer AR model order (default 5). Higher order captures longer-range temporal dependencies but requires more data. |
freq_range |
Numeric vector of length 2 specifying the frequency band
in Hz over which to compute spectral Granger causality. If |
method |
Character; one of |
modality_x |
Character modality name in MultiPhysioExperiment for the x signal. |
modality_y |
Character modality name in MultiPhysioExperiment for the y signal. |
channels_x |
Integer channel index to extract from x (default 1). |
channels_y |
Integer channel index to extract from y (default 1). |
For the time-domain (parametric) method, Granger causality from x to y is defined as:
where the restricted model predicts y from its own past only, and the unrestricted model predicts y from both its own past and x's past.
For spectral Granger causality (when freq_range is specified), the AR
coefficients are transformed to the frequency domain via the transfer
function , and the spectral GC is computed as:
The returned values are then averaged over the specified frequency band.
Note: The spectral GC implementation uses separate restricted and
unrestricted univariate AR models, which is an approximation to the full
Geweke (1982) spectral decomposition based on a 2x2 bivariate VAR model.
Results may differ from toolboxes that implement the full Geweke decomposition
(e.g., MVGC, FieldTrip). For exact spectral GC, use the time-domain method
(freq_range = NULL) which correctly implements the Granger (1969)
log-ratio formulation.
A list with components:
Numeric Granger causality from x to y (x drives y). A positive value indicates that x's past helps predict y beyond y's own past.
Numeric Granger causality from y to x (y drives x).
Numeric net Granger causality (gc_xy - gc_yx).
Positive values indicate that x drives y more than y drives x.
Integer AR model order used.
Granger, C. W. J. (1969). Investigating causal relations by econometric models and cross-spectral methods. Econometrica, 37(3), 424-438.
Geweke, J. (1982). Measurement of linear dependence and feedback between multiple time series. Journal of the American Statistical Association, 77(378), 304-313.
coherence(), phaseLockingValue()
# Create directed signals: x drives y with a 5-sample lag set.seed(42) n <- 5000 x <- rnorm(n) y <- numeric(n) for (i in 6:n) y[i] <- 0.6 * x[i - 5] + 0.4 * rnorm(1) result <- grangerCausality(x, y, sr = 500, order = 10) result$gc_xy # Should be positive (x drives y) result$net_gc # Should be positive# Create directed signals: x drives y with a 5-sample lag set.seed(42) n <- 5000 x <- rnorm(n) y <- numeric(n) for (i in 6:n) y[i] <- 0.6 * x[i - 5] + 0.4 * rnorm(1) result <- grangerCausality(x, y, sr = 500, order = 10) result$gc_xy # Should be positive (x drives y) result$net_gc # Should be positive
Provides subsetting ([), length(), and names() methods for
MultiPhysioExperiment objects.
Length of a MultiPhysioExperiment
## S4 method for signature 'MultiPhysioExperiment' length(x)## S4 method for signature 'MultiPhysioExperiment' length(x)
x |
A |
Returns the number of modalities (same as nModalities).
Integer: number of modalities.
eeg_data <- matrix(rnorm(500 * 2), nrow = 500, ncol = 2) pe_eeg <- PhysioExperiment( assays = list(raw = eeg_data), samplingRate = 250 ) mpe <- MultiPhysioExperiment(EEG = pe_eeg) length(mpe) # 1eeg_data <- matrix(rnorm(500 * 2), nrow = 500, ncol = 2) pe_eeg <- PhysioExperiment( assays = list(raw = eeg_data), samplingRate = 250 ) mpe <- MultiPhysioExperiment(EEG = pe_eeg) length(mpe) # 1
Evaluates model transportability by training on all-but-one sites and
testing on the held-out site (LODO). Supports continuous outcomes
(family = "gaussian") and binary outcomes (family = "binomial").
lodoGeneralization( data, outcome, site, features = NULL, family = c("gaussian", "binomial"), positive_class = NULL, threshold = 0.5, min_train_rows = 20L, scale_features = TRUE )lodoGeneralization( data, outcome, site, features = NULL, family = c("gaussian", "binomial"), positive_class = NULL, threshold = 0.5, min_train_rows = 20L, scale_features = TRUE )
data |
Data frame containing outcome, site label, and features. |
outcome |
Outcome column name. |
site |
Site/facility column name used for LODO splitting. |
features |
Feature column names. If |
family |
Modeling family: |
positive_class |
Positive class label for binomial metrics.
If |
threshold |
Classification threshold for binomial predictions. |
min_train_rows |
Minimum training rows required per fold. |
scale_features |
Logical; z-score features using training statistics. |
A list with:
Per-site metrics.
Row-level held-out predictions.
Mean metrics across folds.
Benchmark settings and feature list.
couplingAnalysis(), surrogateTest()
set.seed(1) n <- 120 df <- data.frame( site_id = rep(c("A", "B", "C"), each = 40), f1 = rnorm(n), f2 = rnorm(n) ) df$y <- 0.8 * df$f1 - 0.4 * df$f2 + rnorm(n, sd = 0.2) res <- lodoGeneralization( data = df, outcome = "y", site = "site_id", family = "gaussian" ) head(res$fold_metrics)set.seed(1) n <- 120 df <- data.frame( site_id = rep(c("A", "B", "C"), each = 40), f1 = rnorm(n), f2 = rnorm(n) ) df$y <- 0.8 * df$f1 - 0.4 * df$f2 + rnorm(n, sd = 0.2) res <- lodoGeneralization( data = df, outcome = "y", site = "site_id", family = "gaussian" ) head(res$fold_metrics)
Creates a pair of sinusoidal signals with a shared oscillatory component at a specified coupling frequency and controllable noise level. Useful for demonstrating and testing spectral coherence, phase synchrony, and other cross-modal coupling measures.
make_coupled_signals( sr1 = 500, sr2 = 500, coupling_freq = 20, coupling_strength = 0.8, noise = 0.2, duration = 10 )make_coupled_signals( sr1 = 500, sr2 = 500, coupling_freq = 20, coupling_strength = 0.8, noise = 0.2, duration = 10 )
sr1 |
Numeric sampling rate in Hz for the first signal (default 500). |
sr2 |
Numeric sampling rate in Hz for the second signal (default 500). |
coupling_freq |
Numeric frequency in Hz of the shared oscillatory component (default 20). |
coupling_strength |
Numeric amplitude of the shared component (default 0.8). |
noise |
Numeric standard deviation of the additive Gaussian noise (default 0.2). |
duration |
Numeric duration in seconds (default 10). |
Both signals share the same sinusoidal component at coupling_freq,
scaled by coupling_strength, with additive Gaussian noise scaled by
noise.
A named list with components:
Numeric vector – first coupled signal.
Numeric vector – second coupled signal.
Numeric sampling rate of signal x.
Numeric sampling rate of signal y.
Numeric coupling frequency used.
Carter, G. C. (1987). Coherence and time delay estimation. Proceedings of the IEEE, 75(2), 236–255.
make_eeg_emg(), make_directed_signals(),
coherence(), couplingAnalysis()
signals <- make_coupled_signals(sr1 = 500, sr2 = 500, coupling_freq = 20, coupling_strength = 0.8, noise = 0.2, duration = 10) result <- coherence(signals$x, signals$y, sr = signals$sr_x)signals <- make_coupled_signals(sr1 = 500, sr2 = 500, coupling_freq = 20, coupling_strength = 0.8, noise = 0.2, duration = 10) result <- coherence(signals$x, signals$y, sr = signals$sr_x)
Creates a pair of signals where x drives y with a specified
lag and coupling strength. Signal x is white noise, and y
is a mixture of a lagged copy of x and independent noise. This is
useful for testing directed coupling measures such as Granger causality.
make_directed_signals(n = 5000, sr = 500, lag_samples = 10, coupling = 0.7)make_directed_signals(n = 5000, sr = 500, lag_samples = 10, coupling = 0.7)
n |
Integer number of samples (default 5000). |
sr |
Numeric sampling rate in Hz (default 500). |
lag_samples |
Integer number of samples by which |
coupling |
Numeric coupling strength in [0, 1] (default 0.7). |
The generating model is:
where .
A named list with components:
Numeric vector – driving signal (white noise).
Numeric vector – driven signal (lagged mixture).
Numeric sampling rate.
Integer lag used.
Granger, C. W. J. (1969). Investigating causal relations by econometric models and cross-spectral methods. Econometrica, 37(3), 424–438.
grangerCausality(), make_coupled_signals(),
crossCorrelation(), couplingAnalysis()
signals <- make_directed_signals(n = 5000, sr = 500, lag_samples = 10, coupling = 0.7) result <- grangerCausality(signals$x, signals$y, sr = signals$sr, order = 15) result$gc_xy # should be positive (x drives y) result$net_gc # should be positivesignals <- make_directed_signals(n = 5000, sr = 500, lag_samples = 10, coupling = 0.7) result <- grangerCausality(signals$x, signals$y, sr = signals$sr, order = 15) result$gc_xy # should be positive (x drives y) result$net_gc # should be positive
Creates a pair of PhysioExperiment objects simulating simultaneous
EEG and EMG recordings with corticomuscular coherence (CMC) at a specified
frequency. The first channel of each modality contains a shared oscillatory
component; remaining channels contain independent noise.
make_eeg_emg( n_sec = 10, n_eeg_ch = 3, n_emg_ch = 2, sr_eeg = 500, sr_emg = 1000, cmc_freq = 20 )make_eeg_emg( n_sec = 10, n_eeg_ch = 3, n_emg_ch = 2, sr_eeg = 500, sr_emg = 1000, cmc_freq = 20 )
n_sec |
Numeric recording duration in seconds (default 10). |
n_eeg_ch |
Integer number of EEG channels (default 3). |
n_emg_ch |
Integer number of EMG channels (default 2). |
sr_eeg |
Numeric EEG sampling rate in Hz (default 500). |
sr_emg |
Numeric EMG sampling rate in Hz (default 1000). |
cmc_freq |
Numeric corticomuscular coherence frequency in Hz (default 20). |
This function is useful for demonstrating and testing multi-channel and
multi-modal coupling analyses such as coherence matrices and
MultiPhysioExperiment workflows.
A named list with components:
A PhysioExperiment object with EEG data
(n_eeg_ch channels at sr_eeg Hz).
A PhysioExperiment object with EMG data
(n_emg_ch channels at sr_emg Hz).
Halliday, D. M., Rosenberg, J. R., Amjad, A. M., Breeze, P., Conway, B. A., & Farmer, S. F. (1995). A framework for the analysis of mixed time series/point process data – theory and application to the study of physiological tremor, single motor unit discharges and electromyograms. Progress in Biophysics and Molecular Biology, 64(2–3), 237–278.
make_coupled_signals(), make_directed_signals(),
MultiPhysioExperiment(), coherenceMatrix()
data <- make_eeg_emg(n_sec = 5, n_eeg_ch = 3, n_emg_ch = 2) mpe <- MultiPhysioExperiment(EEG = data$eeg, EMG = data$emg) modalities(mpe)data <- make_eeg_emg(n_sec = 5, n_eeg_ch = 3, n_emg_ch = 2) mpe <- MultiPhysioExperiment(EEG = data$eeg, EMG = data$emg) modalities(mpe)
Horizontally concatenates the channels (columns) of two
PhysioExperiment objects that share the same sampling rate.
Channel labels are prefixed to avoid name collisions.
mergePhysio(x, y, prefix = c("x_", "y_"))mergePhysio(x, y, prefix = c("x_", "y_"))
x |
A |
y |
A |
prefix |
Character vector of length 2: prefixes added to channel
labels from |
Both objects must have the same number of time points (rows) and the same sampling rate. Only the first assay of each object is merged.
A single PhysioExperiment with the columns of both inputs.
alignToRate(), alignSignals(),
MultiPhysioExperiment()
pe1 <- PhysioExperiment( assays = list(raw = matrix(rnorm(100 * 4), nrow = 100)), colData = S4Vectors::DataFrame(label = paste0("A", 1:4)), samplingRate = 500 ) pe2 <- PhysioExperiment( assays = list(raw = matrix(rnorm(100 * 4), nrow = 100)), colData = S4Vectors::DataFrame(label = paste0("B", 1:4)), samplingRate = 500 ) merged <- mergePhysio(pe1, pe2)pe1 <- PhysioExperiment( assays = list(raw = matrix(rnorm(100 * 4), nrow = 100)), colData = S4Vectors::DataFrame(label = paste0("A", 1:4)), samplingRate = 500 ) pe2 <- PhysioExperiment( assays = list(raw = matrix(rnorm(100 * 4), nrow = 100)), colData = S4Vectors::DataFrame(label = paste0("B", 1:4)), samplingRate = 500 ) merged <- mergePhysio(pe1, pe2)
Returns a character vector of the names of the modalities stored in the object.
modalities(x) ## S4 method for signature 'MultiPhysioExperiment' modalities(x)modalities(x) ## S4 method for signature 'MultiPhysioExperiment' modalities(x)
x |
A |
Character vector of modality names (e.g., c("EEG", "EMG")).
experiments(), nModalities(), samplingRates()
eeg_data <- matrix(rnorm(500 * 2), nrow = 500, ncol = 2) emg_data <- matrix(rnorm(1000 * 2), nrow = 1000, ncol = 2) pe_eeg <- PhysioExperiment( assays = list(raw = eeg_data), samplingRate = 250 ) pe_emg <- PhysioExperiment( assays = list(raw = emg_data), samplingRate = 1000 ) mpe <- MultiPhysioExperiment(EEG = pe_eeg, EMG = pe_emg) modalities(mpe)eeg_data <- matrix(rnorm(500 * 2), nrow = 500, ncol = 2) emg_data <- matrix(rnorm(1000 * 2), nrow = 1000, ncol = 2) pe_eeg <- PhysioExperiment( assays = list(raw = eeg_data), samplingRate = 250 ) pe_emg <- PhysioExperiment( assays = list(raw = emg_data), samplingRate = 1000 ) mpe <- MultiPhysioExperiment(EEG = pe_eeg, EMG = pe_emg) modalities(mpe)
Creates a container that holds multiple PhysioExperiment objects
recorded simultaneously at potentially different sampling rates.
MultiPhysioExperiment(..., experiments = list(), alignment = NULL)MultiPhysioExperiment(..., experiments = list(), alignment = NULL)
... |
Named |
experiments |
Alternatively, a named list of |
alignment |
Optional |
A MultiPhysioExperiment-class instance containing
the supplied experiments, alignment metadata, and an empty coupling
results cache.
Huber, W., et al. (2015). "Orchestrating high-throughput genomic analysis with Bioconductor." Nature Methods, 12(2), 115-121. doi:10.1038/nmeth.3252
experiments(), modalities(), samplingRates(),
alignSignals(), couplingAnalysis()
# Create two PhysioExperiment objects with different sampling rates eeg_data <- matrix(rnorm(500 * 4), nrow = 500, ncol = 4) emg_data <- matrix(rnorm(1000 * 2), nrow = 1000, ncol = 2) pe_eeg <- PhysioExperiment( assays = list(raw = eeg_data), colData = S4Vectors::DataFrame( label = c("Fz", "Cz", "Pz", "Oz"), type = rep("EEG", 4) ), samplingRate = 250 ) pe_emg <- PhysioExperiment( assays = list(raw = emg_data), colData = S4Vectors::DataFrame( label = c("EMG1", "EMG2"), type = rep("EMG", 2) ), samplingRate = 1000 ) # Construct MultiPhysioExperiment mpe <- MultiPhysioExperiment(EEG = pe_eeg, EMG = pe_emg) mpe# Create two PhysioExperiment objects with different sampling rates eeg_data <- matrix(rnorm(500 * 4), nrow = 500, ncol = 4) emg_data <- matrix(rnorm(1000 * 2), nrow = 1000, ncol = 2) pe_eeg <- PhysioExperiment( assays = list(raw = eeg_data), colData = S4Vectors::DataFrame( label = c("Fz", "Cz", "Pz", "Oz"), type = rep("EEG", 4) ), samplingRate = 250 ) pe_emg <- PhysioExperiment( assays = list(raw = emg_data), colData = S4Vectors::DataFrame( label = c("EMG1", "EMG2"), type = rep("EMG", 2) ), samplingRate = 1000 ) # Construct MultiPhysioExperiment mpe <- MultiPhysioExperiment(EEG = pe_eeg, EMG = pe_emg) mpe
The MultiPhysioExperiment class holds multiple PhysioExperiment objects
representing different signal modalities (e.g., EEG, EMG, ECG) recorded
simultaneously but potentially at different sampling rates. It provides
temporal alignment metadata and a cache for coupling analysis results.
experimentsNamed list of PhysioExperiment objects.
alignmentDataFrame with temporal alignment
metadata (one row per modality).
sampleMapDataFrame mapping samples across
modalities.
couplingResultsList of cached coupling analysis results.
Huber, W., et al. (2015). "Orchestrating high-throughput genomic analysis with Bioconductor." Nature Methods, 12(2), 115-121. doi:10.1038/nmeth.3252
MultiPhysioExperiment(), experiments(), modalities(),
alignSignals()
Computes magnitude-squared coherence using multitaper spectral estimation with Discrete Prolate Spheroidal Sequences (DPSS / Slepian tapers). Multitaper estimation provides lower variance than Welch's method for short signals or when frequency resolution is critical.
multitaperCoherence( x, y = NULL, sr = NULL, nw = 4, k = NULL, freq_range = NULL, modality_x = NULL, modality_y = NULL, channels_x = 1L, channels_y = 1L, ... )multitaperCoherence( x, y = NULL, sr = NULL, nw = 4, k = NULL, freq_range = NULL, modality_x = NULL, modality_y = NULL, channels_x = 1L, channels_y = 1L, ... )
x |
Numeric vector, PhysioExperiment, or MultiPhysioExperiment. |
y |
Numeric vector or PhysioExperiment, or NULL when |
sr |
Numeric sampling rate in Hz (required when x/y are numeric). |
nw |
Numeric time-bandwidth product (default 4). Controls the trade-off between frequency resolution and variance. |
k |
Integer number of tapers (default |
freq_range |
Optional numeric vector |
modality_x, modality_y
|
Character modality names for MPE input. |
channels_x, channels_y
|
Integer channel indices (default 1). |
... |
Currently unused. |
A list with components:
Numeric vector of magnitude-squared coherence values
in .
Numeric vector of corresponding frequencies in Hz.
Numeric scalar giving the 95\ threshold based on the number of tapers.
Thomson, D. J. (1982). Spectrum estimation and harmonic analysis. Proceedings of the IEEE, 70(9), 1055–1096.
Carter, G. C. (1987). Coherence and time delay estimation. Proceedings of the IEEE, 75(2), 236–255.
coherence(), crossSpectrum(), couplingAnalysis()
sr <- 500 t <- seq(0, 10, length.out = sr * 10) x <- sin(2 * pi * 20 * t) + 0.2 * rnorm(length(t)) y <- 0.8 * sin(2 * pi * 20 * t) + 0.2 * rnorm(length(t)) result <- multitaperCoherence(x, y, sr = sr)sr <- 500 t <- seq(0, 10, length.out = sr * 10) x <- sin(2 * pi * 20 * t) + 0.2 * rnorm(length(t)) y <- 0.8 * sin(2 * pi * 20 * t) + 0.2 * rnorm(length(t)) result <- multitaperCoherence(x, y, sr = sr)
Returns modality names (same as modalities).
## S4 method for signature 'MultiPhysioExperiment' names(x)## S4 method for signature 'MultiPhysioExperiment' names(x)
x |
A |
Character vector of modality names.
eeg_data <- matrix(rnorm(500 * 2), nrow = 500, ncol = 2) emg_data <- matrix(rnorm(1000 * 2), nrow = 1000, ncol = 2) pe_eeg <- PhysioExperiment( assays = list(raw = eeg_data), samplingRate = 250 ) pe_emg <- PhysioExperiment( assays = list(raw = emg_data), samplingRate = 1000 ) mpe <- MultiPhysioExperiment(EEG = pe_eeg, EMG = pe_emg) names(mpe) # c("EEG", "EMG")eeg_data <- matrix(rnorm(500 * 2), nrow = 500, ncol = 2) emg_data <- matrix(rnorm(1000 * 2), nrow = 1000, ncol = 2) pe_eeg <- PhysioExperiment( assays = list(raw = eeg_data), samplingRate = 250 ) pe_emg <- PhysioExperiment( assays = list(raw = emg_data), samplingRate = 1000 ) mpe <- MultiPhysioExperiment(EEG = pe_eeg, EMG = pe_emg) names(mpe) # c("EEG", "EMG")
Get number of modalities
nModalities(x) ## S4 method for signature 'MultiPhysioExperiment' nModalities(x)nModalities(x) ## S4 method for signature 'MultiPhysioExperiment' nModalities(x)
x |
A |
Integer scalar: the number of modalities stored in the object.
eeg_data <- matrix(rnorm(500 * 2), nrow = 500, ncol = 2) pe_eeg <- PhysioExperiment( assays = list(raw = eeg_data), samplingRate = 250 ) mpe <- MultiPhysioExperiment(EEG = pe_eeg) nModalities(mpe)eeg_data <- matrix(rnorm(500 * 2), nrow = 500, ncol = 2) pe_eeg <- PhysioExperiment( assays = list(raw = eeg_data), samplingRate = 250 ) mpe <- MultiPhysioExperiment(EEG = pe_eeg) nModalities(mpe)
Computes the Phase Lag Index between two signals. PLI measures the asymmetry of the distribution of phase differences and is insensitive to zero-lag (volume conduction) effects.
phaseLagIndex( x, y = NULL, sr = NULL, freq_band, modality_x = NULL, modality_y = NULL, channels_x = 1L, channels_y = 1L )phaseLagIndex( x, y = NULL, sr = NULL, freq_band, modality_x = NULL, modality_y = NULL, channels_x = 1L, channels_y = 1L )
x |
Numeric vector, PhysioExperiment, or MultiPhysioExperiment. |
y |
Numeric vector or PhysioExperiment (NULL when |
sr |
Numeric sampling rate in Hz (required when x/y are numeric). |
freq_band |
Numeric vector of length 2 specifying the frequency band
|
modality_x |
Character modality name in MPE for x signal. |
modality_y |
Character modality name in MPE for y signal. |
channels_x |
Integer channel index to extract from x (default 1). |
channels_y |
Integer channel index to extract from y (default 1). |
A PLI of 0 indicates either no coupling or symmetric (zero-lag) coupling. A PLI of 1 indicates perfect non-zero-lag phase locking.
A named list with components:
Numeric scalar in [0, 1] – the Phase Lag Index.
Numeric vector of instantaneous phase differences (radians).
Stam, C. J., Nolte, G., & Daffertshofer, A. (2007). Phase lag index: Assessment of functional connectivity from multi channel EEG and MEG with diminished bias from common sources. Human Brain Mapping, 28(11), 1178–1193.
phaseLockingValue(), weightedPLI(), couplingAnalysis()
sr <- 500 t <- seq(0, 2, length.out = sr * 2) x <- sin(2 * pi * 10 * t) y <- sin(2 * pi * 10 * t + pi / 3) result <- phaseLagIndex(x, y, sr = sr, freq_band = c(8, 12)) result$plisr <- 500 t <- seq(0, 2, length.out = sr * 2) x <- sin(2 * pi * 10 * t) y <- sin(2 * pi * 10 * t + pi / 3) result <- phaseLagIndex(x, y, sr = sr, freq_band = c(8, 12)) result$pli
Computes the Phase Locking Value between two signals, measuring the consistency of phase difference across time. A PLV of 1 indicates perfect phase locking; a PLV of 0 indicates no consistent phase relationship.
phaseLockingValue( x, y = NULL, sr = NULL, freq_band, method = c("hilbert", "wavelet"), modality_x = NULL, modality_y = NULL, channels_x = 1L, channels_y = 1L )phaseLockingValue( x, y = NULL, sr = NULL, freq_band, method = c("hilbert", "wavelet"), modality_x = NULL, modality_y = NULL, channels_x = 1L, channels_y = 1L )
x |
Numeric vector, PhysioExperiment, or MultiPhysioExperiment. |
y |
Numeric vector or PhysioExperiment (NULL when |
sr |
Numeric sampling rate in Hz (required when x/y are numeric). |
freq_band |
Numeric vector of length 2 specifying the frequency band
|
method |
Character; phase extraction method. Currently only
|
modality_x |
Character modality name in MPE for x signal. |
modality_y |
Character modality name in MPE for y signal. |
channels_x |
Integer channel index to extract from x (default 1). |
channels_y |
Integer channel index to extract from y (default 1). |
The signals are bandpass-filtered to freq_band and then Hilbert-
transformed to extract instantaneous phase. PLV is computed as:
A named list with components:
Numeric scalar in [0, 1] – the Phase Locking Value.
Numeric vector of instantaneous phase differences (radians, [-pi, pi]).
Lachaux, J.-P., Rodriguez, E., Martinerie, J., & Varela, F. J. (1999). Measuring phase synchrony in brain signals. Human Brain Mapping, 8(4), 194–208.
phaseLagIndex(), weightedPLI(), waveletPLV(),
couplingAnalysis()
# Two phase-locked sinusoids sr <- 500 t <- seq(0, 2, length.out = sr * 2) x <- sin(2 * pi * 10 * t) y <- sin(2 * pi * 10 * t + pi / 4) result <- phaseLockingValue(x, y, sr = sr, freq_band = c(8, 12)) result$plv# Two phase-locked sinusoids sr <- 500 t <- seq(0, 2, length.out = sr * 2) x <- sin(2 * pi * 10 * t) y <- sin(2 * pi * 10 * t + pi / 4) result <- phaseLockingValue(x, y, sr = sr, freq_band = c(8, 12)) result$plv
Displays the coherence as a function of frequency from the result of
coherence. Optionally draws the 95\
a horizontal dashed line.
plotCoherenceSpectrum( result, show_threshold = TRUE, title = "Coherence Spectrum", ... )plotCoherenceSpectrum( result, show_threshold = TRUE, title = "Coherence Spectrum", ... )
result |
A list returned by |
show_threshold |
Logical; if TRUE (default) and a confidence limit is available, draw it on the plot. |
title |
Character string for the plot title
(default |
... |
Additional arguments (currently unused). |
A ggplot object.
Wickham, H. (2016). ggplot2: Elegant Graphics for Data Analysis. Springer-Verlag New York. doi:10.1007/978-3-319-24277-4
coherence(), multitaperCoherence(),
plotCouplingMatrix()
sr <- 500 t <- seq(0, 10, length.out = sr * 10) x <- sin(2 * pi * 20 * t) + 0.2 * rnorm(length(t)) y <- 0.8 * sin(2 * pi * 20 * t) + 0.2 * rnorm(length(t)) res <- coherence(x, y, sr = sr) if (requireNamespace("ggplot2", quietly = TRUE)) { plotCoherenceSpectrum(res) }sr <- 500 t <- seq(0, 10, length.out = sr * 10) x <- sin(2 * pi * 20 * t) + 0.2 * rnorm(length(t)) y <- 0.8 * sin(2 * pi * 20 * t) + 0.2 * rnorm(length(t)) res <- coherence(x, y, sr = sr) if (requireNamespace("ggplot2", quietly = TRUE)) { plotCoherenceSpectrum(res) }
Displays a matrix of coupling values (e.g., coherence between all channel
pairs) as a colour-coded heatmap using ggplot2::geom_tile().
plotCouplingMatrix( mat, title = "Coupling Matrix", low_colour = "white", high_colour = "#2166AC", ... )plotCouplingMatrix( mat, title = "Coupling Matrix", low_colour = "white", high_colour = "#2166AC", ... )
mat |
Numeric matrix of coupling values. Row and column names, if present, are used as axis labels. |
title |
Character string for the plot title
(default |
low_colour |
Character colour for the low end of the scale
(default |
high_colour |
Character colour for the high end of the scale
(default |
... |
Additional arguments passed to |
A ggplot object.
Wickham, H. (2016). ggplot2: Elegant Graphics for Data Analysis. Springer-Verlag New York. doi:10.1007/978-3-319-24277-4
coherenceMatrix(), couplingMatrix(),
surrogateMatrixTest()
mat <- matrix(runif(16), nrow = 4, dimnames = list(paste0("Ch", 1:4), paste0("Ch", 1:4))) if (requireNamespace("ggplot2", quietly = TRUE)) { plotCouplingMatrix(mat) }mat <- matrix(runif(16), nrow = 4, dimnames = list(paste0("Ch", 1:4), paste0("Ch", 1:4))) if (requireNamespace("ggplot2", quietly = TRUE)) { plotCouplingMatrix(mat) }
Displays the peak cross-correlation over time from the result of
slidingCrossCorrelation.
plotCouplingTimecourse(result, title = "Coupling Time Course", ...)plotCouplingTimecourse(result, title = "Coupling Time Course", ...)
result |
A list returned by |
title |
Character string for the plot title
(default |
... |
Additional arguments (currently unused). |
A ggplot object.
Wickham, H. (2016). ggplot2: Elegant Graphics for Data Analysis. Springer-Verlag New York. doi:10.1007/978-3-319-24277-4
slidingCrossCorrelation(), crossCorrelation(),
plotCoherenceSpectrum()
sr <- 500 set.seed(1) x <- rnorm(5000) y <- c(rep(0, 10), x[1:4990]) res <- slidingCrossCorrelation(x, y, sr = sr, window_sec = 1, step_sec = 0.5) if (requireNamespace("ggplot2", quietly = TRUE)) { plotCouplingTimecourse(res) }sr <- 500 set.seed(1) x <- rnorm(5000) y <- c(rep(0, 10), x[1:4990]) res <- slidingCrossCorrelation(x, y, sr = sr, window_sec = 1, step_sec = 0.5) if (requireNamespace("ggplot2", quietly = TRUE)) { plotCouplingTimecourse(res) }
Displays wavelet coherence (or wavelet PLV) as a filled time-frequency heatmap with optional Cone of Influence (COI) overlay.
plotWaveletCoherence( result, show_coi = TRUE, title = "Wavelet Coherence", fill_label = "Coherence", ... )plotWaveletCoherence( result, show_coi = TRUE, title = "Wavelet Coherence", fill_label = "Coherence", ... )
result |
List returned by |
show_coi |
Logical; overlay COI boundary (default |
title |
Character plot title (default |
fill_label |
Character legend label (default |
... |
Additional arguments passed to |
A ggplot object.
Wickham, H. (2016). ggplot2: Elegant Graphics for Data Analysis. Springer-Verlag New York. doi:10.1007/978-3-319-24277-4
waveletCoherence(), waveletPLV(),
plotCoherenceSpectrum()
sr <- 200 t <- seq(0, 2, length.out = sr * 2) x <- sin(2 * pi * 10 * t) + 0.3 * rnorm(length(t)) y <- 0.8 * sin(2 * pi * 10 * t) + 0.3 * rnorm(length(t)) result <- waveletCoherence(x, y, sr = sr, frequencies = seq(5, 20)) if (requireNamespace("ggplot2", quietly = TRUE)) { plotWaveletCoherence(result) }sr <- 200 t <- seq(0, 2, length.out = sr * 2) x <- sin(2 * pi * 10 * t) + 0.3 * rnorm(length(t)) y <- 0.8 * sin(2 * pi * 10 * t) + 0.3 * rnorm(length(t)) result <- waveletCoherence(x, y, sr = sr, frequencies = seq(5, 20)) if (requireNamespace("ggplot2", quietly = TRUE)) { plotWaveletCoherence(result) }
Returns a named numeric vector of sampling rates, one per modality.
samplingRates(x) ## S4 method for signature 'MultiPhysioExperiment' samplingRates(x)samplingRates(x) ## S4 method for signature 'MultiPhysioExperiment' samplingRates(x)
x |
A |
Named numeric vector of sampling rates in Hz (e.g.,
c(EEG = 500, EMG = 1000)).
modalities(), experiments(), alignToRate()
eeg_data <- matrix(rnorm(500 * 2), nrow = 500, ncol = 2) emg_data <- matrix(rnorm(1000 * 2), nrow = 1000, ncol = 2) pe_eeg <- PhysioExperiment( assays = list(raw = eeg_data), samplingRate = 250 ) pe_emg <- PhysioExperiment( assays = list(raw = emg_data), samplingRate = 1000 ) mpe <- MultiPhysioExperiment(EEG = pe_eeg, EMG = pe_emg) samplingRates(mpe)eeg_data <- matrix(rnorm(500 * 2), nrow = 500, ncol = 2) emg_data <- matrix(rnorm(1000 * 2), nrow = 1000, ncol = 2) pe_eeg <- PhysioExperiment( assays = list(raw = eeg_data), samplingRate = 250 ) pe_emg <- PhysioExperiment( assays = list(raw = emg_data), samplingRate = 1000 ) mpe <- MultiPhysioExperiment(EEG = pe_eeg, EMG = pe_emg) samplingRates(mpe)
Displays a human-readable summary of the object.
## S4 method for signature 'MultiPhysioExperiment' show(object)## S4 method for signature 'MultiPhysioExperiment' show(object)
object |
A |
eeg_data <- matrix(rnorm(500 * 2), nrow = 500, ncol = 2) pe_eeg <- PhysioExperiment( assays = list(raw = eeg_data), samplingRate = 250 ) mpe <- MultiPhysioExperiment(EEG = pe_eeg) mpeeeg_data <- matrix(rnorm(500 * 2), nrow = 500, ncol = 2) pe_eeg <- PhysioExperiment( assays = list(raw = eeg_data), samplingRate = 250 ) mpe <- MultiPhysioExperiment(EEG = pe_eeg) mpe
Computes cross-correlation in sliding (overlapping) windows to track
how time-domain coupling varies over time. For each window position,
crossCorrelation is called and the results are assembled
into a matrix.
slidingCrossCorrelation( x, y = NULL, sr = NULL, window_sec = 1, step_sec = 0.5, max_lag = NULL, modality_x = NULL, modality_y = NULL, channels_x = 1L, channels_y = 1L )slidingCrossCorrelation( x, y = NULL, sr = NULL, window_sec = 1, step_sec = 0.5, max_lag = NULL, modality_x = NULL, modality_y = NULL, channels_x = 1L, channels_y = 1L )
x |
Numeric vector, PhysioExperiment, or MultiPhysioExperiment. |
y |
Numeric vector or PhysioExperiment, or NULL when |
sr |
Numeric sampling rate in Hz (required when x/y are numeric). |
window_sec |
Numeric window length in seconds (default 1). |
step_sec |
Numeric step size in seconds (default 0.5). |
max_lag |
Integer maximum lag in samples for each window. If NULL,
defaults to |
modality_x |
Character modality name in MPE for the x signal. |
modality_y |
Character modality name in MPE for the y signal. |
channels_x |
Integer which channel to extract from x (default 1). |
channels_y |
Integer which channel to extract from y (default 1). |
A named list with components:
Numeric matrix of dimensions (n_windows x n_lags) containing cross-correlation values.
Numeric vector of window centre times in seconds.
Integer vector of lag values in samples.
Numeric vector of peak lags (in samples) for each window.
Numeric vector of peak correlation values for each window.
Chatfield, C. (2004). The Analysis of Time Series: An Introduction (6th ed.). Chapman & Hall/CRC.
crossCorrelation(), plotCouplingTimecourse(),
couplingAnalysis()
sr <- 500 set.seed(1) x <- rnorm(5000) y <- c(rep(0, 10), x[1:4990]) result <- slidingCrossCorrelation(x, y, sr = sr, window_sec = 1, step_sec = 0.5) dim(result$correlations) result$peak_lagssr <- 500 set.seed(1) x <- rnorm(5000) y <- c(rep(0, 10), x[1:4990]) result <- slidingCrossCorrelation(x, y, sr = sr, window_sec = 1, step_sec = 0.5) dim(result$correlations) result$peak_lags
Tests each element of a coupling matrix for significance using surrogate testing, with correction for multiple comparisons (FDR or Bonferroni).
surrogateMatrixTest( x, y = NULL, method, n_surrogates = 199L, surrogate_type = c("phase", "timeshift"), correction = c("fdr", "bonferroni", "none"), alpha = 0.05, channels_x = NULL, channels_y = NULL, modality_x = NULL, modality_y = NULL, cores = 1L, ... )surrogateMatrixTest( x, y = NULL, method, n_surrogates = 199L, surrogate_type = c("phase", "timeshift"), correction = c("fdr", "bonferroni", "none"), alpha = 0.05, channels_x = NULL, channels_y = NULL, modality_x = NULL, modality_y = NULL, cores = 1L, ... )
x |
PhysioExperiment or MultiPhysioExperiment. |
y |
PhysioExperiment or NULL (when |
method |
Character coupling method (same options as
|
n_surrogates |
Integer number of surrogates (default 199). |
surrogate_type |
Character surrogate generation method:
|
correction |
Character correction method: |
alpha |
Numeric significance level (default 0.05). |
channels_x, channels_y
|
Integer vectors of channel indices, or NULL for all channels. |
modality_x, modality_y
|
Character modality names for MPE input. |
cores |
Integer number of parallel cores (default 1). |
... |
Additional arguments passed to the coupling function. |
A list with components:
Coupling matrix (observed values).
Matrix of raw p-values (same dimensions).
Matrix of corrected p-values.
Logical matrix indicating significance.
Character correction method used.
Numeric significance level.
Theiler, J., Eubank, S., Longtin, A., Galdrikian, B., & Farmer, J. D. (1992). Testing for nonlinearity in time series: the method of surrogate data. Physica D: Nonlinear Phenomena, 58(1–4), 77–94.
Benjamini, Y., & Hochberg, Y. (1995). Controlling the false discovery rate: a practical and powerful approach to multiple testing. Journal of the Royal Statistical Society: Series B (Methodological), 57(1), 289–300.
surrogateTest(), couplingMatrix(), coherenceMatrix()
Tests whether the observed coupling between two signals is statistically significant by comparing it against a null distribution generated from surrogate signals. Surrogates are created by randomising the phases (or circularly shifting) one signal, thereby destroying the cross-signal relationship while preserving the autocorrelation structure.
surrogateTest( x, y = NULL, sr = NULL, method, n_surrogates = 199L, surrogate_type = c("phase", "timeshift"), modality_x = NULL, modality_y = NULL, channels_x = 1L, channels_y = 1L, cores = 1L, ... )surrogateTest( x, y = NULL, sr = NULL, method, n_surrogates = 199L, surrogate_type = c("phase", "timeshift"), modality_x = NULL, modality_y = NULL, channels_x = 1L, channels_y = 1L, cores = 1L, ... )
x |
Numeric vector, PhysioExperiment, or MultiPhysioExperiment. |
y |
Numeric vector or PhysioExperiment, or NULL when |
sr |
Numeric sampling rate in Hz (required when x/y are numeric). |
method |
Character coupling method, one of |
n_surrogates |
Integer number of surrogates (default 199). |
surrogate_type |
Character surrogate generation method:
|
modality_x, modality_y
|
Character modality names for MPE input. |
channels_x, channels_y
|
Integer channel indices (default 1). |
cores |
Integer number of parallel cores to use (default |
... |
Additional arguments passed to the coupling function
(e.g. |
The p-value is computed as (sum(surr >= obs) + 1) / (n_surr + 1),
following the conservative correction of Phipson & Smyth (2010).
A list with components:
The full coupling result from the original signals.
Numeric scalar: the extracted coupling statistic.
Numeric scalar: surrogate p-value.
Numeric vector of surrogate statistics.
Numeric scalar: 95th percentile of surrogates.
Theiler, J., Eubank, S., Longtin, A., Galdrikian, B., & Farmer, J. D. (1992). Testing for nonlinearity in time series: the method of surrogate data. Physica D: Nonlinear Phenomena, 58(1–4), 77–94.
Phipson, B., & Smyth, G. K. (2010). Permutation P-values should never be zero: calculating exact P-values when permutations are randomly drawn. Statistical Applications in Genetics and Molecular Biology, 9(1), Article 39.
bootstrapCI(), surrogateMatrixTest(),
couplingAnalysis()
sr <- 500 t <- seq(0, 2, length.out = sr * 2) x <- sin(2 * pi * 10 * t) + 0.3 * rnorm(length(t)) y <- 0.8 * sin(2 * pi * 10 * t) + 0.3 * rnorm(length(t)) result <- surrogateTest(x, y, sr = sr, method = "coherence", n_surrogates = 19, nperseg = 128L) result$p_valuesr <- 500 t <- seq(0, 2, length.out = sr * 2) x <- sin(2 * pi * 10 * t) + 0.3 * rnorm(length(t)) y <- 0.8 * sin(2 * pi * 10 * t) + 0.3 * rnorm(length(t)) result <- surrogateTest(x, y, sr = sr, method = "coherence", n_surrogates = 19, nperseg = 128L) result$p_value
Computes wavelet coherence between two signals using complex Morlet
wavelets. The cross-wavelet spectrum and auto-spectra are smoothed
with a Gaussian temporal window (width proportional to
smoothing_cycles / frequency), and coherence is computed as:
waveletCoherence( x, y = NULL, sr = NULL, frequencies = seq(1, 40, by = 1), n_cycles = 7, smoothing_cycles = 3, modality_x = NULL, modality_y = NULL, channels_x = 1L, channels_y = 1L, ... )waveletCoherence( x, y = NULL, sr = NULL, frequencies = seq(1, 40, by = 1), n_cycles = 7, smoothing_cycles = 3, modality_x = NULL, modality_y = NULL, channels_x = 1L, channels_y = 1L, ... )
x |
Numeric vector, PhysioExperiment, or MultiPhysioExperiment. |
y |
Numeric vector or PhysioExperiment, or NULL when |
sr |
Numeric sampling rate in Hz (required when x/y are numeric). |
frequencies |
Numeric vector of centre frequencies in Hz
(default |
n_cycles |
Numeric number of wavelet cycles (default 7). |
smoothing_cycles |
Numeric number of cycles for the temporal smoothing Gaussian (default 3). |
modality_x, modality_y
|
Character modality names for MPE input. |
channels_x, channels_y
|
Integer channel indices (default 1). |
... |
Currently unused. |
A list with components:
Numeric matrix [time x frequency] of coherence
values in .
Numeric matrix [time x frequency] of phase differences
(radians).
Numeric vector of centre frequencies.
Numeric vector of time points (seconds from start).
Numeric vector of Cone of Influence frequencies. At each time point, frequencies below this value are affected by edge artifacts.
Torrence, C., & Compo, G. P. (1998). A practical guide to wavelet analysis. Bulletin of the American Meteorological Society, 79(1), 61–78.
Grinsted, A., Moore, J. C., & Jevrejeva, S. (2004). Application of the cross wavelet transform and wavelet coherence to geophysical time series. Nonlinear Processes in Geophysics, 11(5/6), 561–566.
waveletPLV(), coherence(), plotWaveletCoherence(),
couplingAnalysis()
sr <- 200 t <- seq(0, 2, length.out = sr * 2) x <- sin(2 * pi * 10 * t) + 0.3 * rnorm(length(t)) y <- 0.8 * sin(2 * pi * 10 * t) + 0.3 * rnorm(length(t)) result <- waveletCoherence(x, y, sr = sr, frequencies = seq(5, 20))sr <- 200 t <- seq(0, 2, length.out = sr * 2) x <- sin(2 * pi * 10 * t) + 0.3 * rnorm(length(t)) y <- 0.8 * sin(2 * pi * 10 * t) + 0.3 * rnorm(length(t)) result <- waveletCoherence(x, y, sr = sr, frequencies = seq(5, 20))
Computes Phase Locking Value in the time-frequency domain using complex Morlet wavelets. The phase difference between the two signals is computed at each time-frequency point, and PLV is the magnitude of the smoothed unit-phase vector:
waveletPLV( x, y = NULL, sr = NULL, frequencies = seq(1, 40, by = 1), n_cycles = 7, smoothing_cycles = 3, modality_x = NULL, modality_y = NULL, channels_x = 1L, channels_y = 1L, ... )waveletPLV( x, y = NULL, sr = NULL, frequencies = seq(1, 40, by = 1), n_cycles = 7, smoothing_cycles = 3, modality_x = NULL, modality_y = NULL, channels_x = 1L, channels_y = 1L, ... )
x |
Numeric vector, PhysioExperiment, or MultiPhysioExperiment. |
y |
Numeric vector or PhysioExperiment, or NULL when |
sr |
Numeric sampling rate in Hz (required when x/y are numeric). |
frequencies |
Numeric vector of centre frequencies in Hz
(default |
n_cycles |
Numeric number of wavelet cycles (default 7). |
smoothing_cycles |
Numeric number of cycles for the temporal smoothing Gaussian (default 3). |
modality_x, modality_y
|
Character modality names for MPE input. |
channels_x, channels_y
|
Integer channel indices (default 1). |
... |
Currently unused. |
A list with components:
Numeric matrix [time x frequency] of PLV values
in .
Numeric vector of centre frequencies.
Numeric vector of time points (seconds from start).
Numeric vector of Cone of Influence frequencies. At each time point, frequencies below this value are affected by edge artifacts.
Torrence, C., & Compo, G. P. (1998). A practical guide to wavelet analysis. Bulletin of the American Meteorological Society, 79(1), 61–78.
Lachaux, J.-P., Rodriguez, E., Martinerie, J., & Varela, F. J. (1999). Measuring phase synchrony in brain signals. Human Brain Mapping, 8(4), 194–208.
waveletCoherence(), phaseLockingValue(),
plotWaveletCoherence(), couplingAnalysis()
sr <- 200 t <- seq(0, 2, length.out = sr * 2) x <- sin(2 * pi * 10 * t) + 0.3 * rnorm(length(t)) y <- sin(2 * pi * 10 * t + pi/4) + 0.3 * rnorm(length(t)) result <- waveletPLV(x, y, sr = sr, frequencies = seq(5, 20))sr <- 200 t <- seq(0, 2, length.out = sr * 2) x <- sin(2 * pi * 10 * t) + 0.3 * rnorm(length(t)) y <- sin(2 * pi * 10 * t + pi/4) + 0.3 * rnorm(length(t)) result <- waveletPLV(x, y, sr = sr, frequencies = seq(5, 20))
Computes the weighted Phase Lag Index between two signals. wPLI weights each phase-difference sample by the magnitude of the imaginary component of the cross-spectrum, reducing the influence of noise sources that produce phase differences near 0 or pi.
weightedPLI( x, y = NULL, sr = NULL, freq_band, debiased = TRUE, modality_x = NULL, modality_y = NULL, channels_x = 1L, channels_y = 1L )weightedPLI( x, y = NULL, sr = NULL, freq_band, debiased = TRUE, modality_x = NULL, modality_y = NULL, channels_x = 1L, channels_y = 1L )
x |
Numeric vector, PhysioExperiment, or MultiPhysioExperiment. |
y |
Numeric vector or PhysioExperiment (NULL when |
sr |
Numeric sampling rate in Hz (required when x/y are numeric). |
freq_band |
Numeric vector of length 2 specifying the frequency band
|
debiased |
Logical; if TRUE (default), also compute the debiased wPLI estimator. |
modality_x |
Character modality name in MPE for x signal. |
modality_y |
Character modality name in MPE for y signal. |
channels_x |
Integer channel index to extract from x (default 1). |
channels_y |
Integer channel index to extract from y (default 1). |
When debiased = TRUE, the debiased estimator from Vinck et al. (2011) is
also returned:
A named list with components:
Numeric scalar in [0, 1] – the weighted PLI.
Numeric scalar – the debiased wPLI, or NULL if
debiased = FALSE.
Integer – number of time-domain samples used.
Vinck, M., Oostenveld, R., van Wingerden, M., Battaglia, F., & Pennartz, C. M. A. (2011). An improved index of phase-synchronization for electrophysiological data in the presence of volume-conduction, noise and sample-size bias. NeuroImage, 55(4), 1548–1565.
Lachaux, J.-P., Rodriguez, E., Martinerie, J., & Varela, F. J. (1999). Measuring phase synchrony in brain signals. Human Brain Mapping, 8(4), 194–208.
phaseLockingValue(), phaseLagIndex(), couplingAnalysis()
sr <- 500 t <- seq(0, 2, length.out = sr * 2) x <- sin(2 * pi * 10 * t) y <- sin(2 * pi * 10 * t + pi / 4) result <- weightedPLI(x, y, sr = sr, freq_band = c(8, 12)) result$wplisr <- 500 t <- seq(0, 2, length.out = sr * 2) x <- sin(2 * pi * 10 * t) y <- sin(2 * pi * 10 * t + pi / 4) result <- weightedPLI(x, y, sr = sr, freq_band = c(8, 12)) result$wpli