| 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 [aut, cre] |
| Maintainer: | Yusuke Matsui <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.8.4 |
| Built: | 2026-10-03 13:42:46 UTC |
| Source: | https://github.com/x-biosignal/PhysioCrossModal |
Establishes row correspondence before positional multiblock analyses such as
jive() or multipleFactorAnalysis(). Keys may describe, for example,
participant, trial and cycle together. Their meaning and granularity must be
chosen by the caller; equality does not verify units, timing or independence.
alignObservationBlocks(blocks, keys, by, missing = c("error", "intersection"))alignObservationBlocks(blocks, keys, by, missing = c("error", "intersection"))
blocks |
Named list of at least two finite numeric matrices, with observations in rows and features in columns. |
keys |
Named list of data.frames in the same order as |
by |
Nonempty character vector naming the composite key columns. Columns must be plain character, integer, numeric or logical vectors, with identical types across blocks, without missing or non-finite values. |
missing |
Policy for unequal observation sets: |
A list with blocks aligned in first-block observation order,
observations containing their composite keys, row_index mapping output
rows to each input block, excluded_rows listing omitted input row indices,
and by and missing recording the chosen contract. Duplicate keys are
always errors. The caller should retain the input keys with this mapping.
a <- matrix(1:6, nrow = 3) b <- matrix(7:12, nrow = 3) ids <- data.frame(participant = c("P1", "P2", "P3")) aligned <- alignObservationBlocks( list(emg = a, motion = b[3:1, , drop = FALSE]), list(emg = ids, motion = ids[3:1, , drop = FALSE]), "participant")a <- matrix(1:6, nrow = 3) b <- matrix(7:12, nrow = 3) ids <- data.frame(participant = c("P1", "P2", "P3")) aligned <- alignObservationBlocks( list(emg = a, motion = b[3:1, , drop = FALSE]), list(emg = ids, motion = ids[3:1, , drop = FALSE]), "participant")
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", "elastic"), target_rate = NULL )alignSignals( ..., method = c("lowest_rate", "common_rate", "resample", "elastic"), 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).
"elastic"Resample to the lowest rate, then additionally
apply an elastic (SRVF) time warping of every object onto the first, so
that shared events line up in phase. The warping is computed from each
object's first channel and carried to all its channels; it is stored in
metadata()$elastic_warp. Objects whose duration differs from the
reference after rate alignment are left un-warped. See elasticAlign().
If every input already shares the same sampling rate, no resampling is performed regardless of the chosen method (elastic warping, if requested, is still applied).
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)
Finds the linear combinations of two modality blocks whose scores are maximally correlated – the directions in which the modalities co-vary. Ridge regularisation keeps it well-posed when a block has more features than observations.
cca(X, Y, ncomp = NULL, lambda_x = 0, lambda_y = 0)cca(X, Y, ncomp = NULL, lambda_x = 0, lambda_y = 0)
X, Y
|
Matrices with the same |
ncomp |
Number of canonical pairs (default: |
lambda_x, lambda_y
|
Ridge penalties; if |
a cca object: cor (canonical correlations, decreasing), xcoef,
ycoef (canonical vectors), xscores, yscores (canonical variates).
Hotelling H (1936); Vinod HD (1976) ridge CCA.
set.seed(1); z <- matrix(rnorm(50 * 2), 50, 2) X <- z %*% matrix(rnorm(2 * 5), 2, 5) + matrix(rnorm(50 * 5, 0, .3), 50, 5) Y <- z %*% matrix(rnorm(2 * 4), 2, 4) + matrix(rnorm(50 * 4, 0, .3), 50, 4) cca(X, Y)$corset.seed(1); z <- matrix(rnorm(50 * 2), 50, 2) X <- z %*% matrix(rnorm(2 * 5), 2, 5) + matrix(rnorm(50 * 5, 0, .3), 50, 5) Y <- z %*% matrix(rnorm(2 * 4), 2, 4) + matrix(rnorm(50 * 4, 0, .3), 50, 4) cca(X, Y)$cor
ciPLV (Bruna et al. 2018) corrects the imaginary part of the PLV for the size of its real part, giving a phase-synchrony estimate that is robust to zero-lag (volume-conduction) coupling.
ciPLV( x, y = NULL, sr = NULL, freq_band, order = 4L, modality_x = NULL, modality_y = NULL, channels_x = 1L, channels_y = 1L )ciPLV( x, y = NULL, sr = NULL, freq_band, order = 4L, modality_x = NULL, modality_y = NULL, channels_x = 1L, channels_y = 1L )
x, y
|
Signals (or a single object from which a pair is extracted). |
sr |
Sampling rate in Hz. |
freq_band |
Numeric |
order |
Butterworth filter order for the band-pass (default 4). |
modality_x, modality_y, channels_x, channels_y
|
Passed to the internal signal-pair extractor. |
A single ciPLV magnitude in [0, 1].
Bruna R, et al. (2018). Phase locking value revisited. J Neural Eng 15:056011.
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"), type = c("magnitude", "imaginary", "lagged"), 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"), type = c("magnitude", "imaginary", "lagged"), 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
|
type |
Character coherence type: |
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 coherence values at each frequency:
magnitude-squared coherence in for
type = "magnitude", or the (signed) imaginary / lagged coherence
for the other types.
The coherence type computed.
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.
Nolte, G., et al. (2004). Identifying true brain interaction from EEG data using the imaginary part of coherency. Clinical Neurophysiology, 115(10), 2292–2307. doi:10.1016/j.clinph.2004.04.029
Pascual-Marqui, R. D. (2007). Instantaneous and lagged measurements of linear and nonlinear dependence between groups of multivariate time series. arXiv:0711.1455.
crossSpectrum(), multitaperCoherence(), laggedCoherence(),
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
Computes phase-amplitude coupling over a grid of phase frequencies and amplitude frequencies, yielding a comodulogram matrix whose peak locates the dominant coupling.
comodulogram( x, y = NULL, sr = NULL, phase_freqs, amp_freqs, method = c("tort", "canolty", "ozkurt", "plv"), phase_bw = 2, amp_bw = 10, n_bins = 18L, order = 4L, modality_x = NULL, modality_y = NULL, channels_x = 1L, channels_y = 1L )comodulogram( x, y = NULL, sr = NULL, phase_freqs, amp_freqs, method = c("tort", "canolty", "ozkurt", "plv"), phase_bw = 2, amp_bw = 10, n_bins = 18L, order = 4L, modality_x = NULL, modality_y = NULL, channels_x = 1L, channels_y = 1L )
x, y, sr, method, n_bins, order, modality_x, modality_y, channels_x, channels_y
|
As in |
phase_freqs |
Numeric vector of phase centre frequencies in Hz. |
amp_freqs |
Numeric vector of amplitude centre frequencies in Hz. |
phase_bw |
Half-bandwidth of each phase band in Hz (default: 2). |
amp_bw |
Half-bandwidth of each amplitude band in Hz (default: 10). |
A list with the matrix (rows = phase frequencies, columns =
amplitude frequencies), phase_freqs, amp_freqs,
method, and peak (the (phase, amplitude) frequency of the
maximum and its value).
phaseAmplitudeCoupling(), plotComodulogram()
## Not run: set.seed(1); t <- (0:4999) / 500; ph <- 2 * pi * 6 * t sig <- sin(ph) + (0.1 + (1 + cos(ph - pi)) / 2) * sin(2 * pi * 50 * t) cm <- comodulogram(sig, sr = 500, phase_freqs = c(4, 6, 8), amp_freqs = c(30, 50, 70)) cm$peak ## End(Not run)## Not run: set.seed(1); t <- (0:4999) / 500; ph <- 2 * pi * 6 * t sig <- sin(ph) + (0.1 + (1 + cos(ph - pi)) / 2) * sin(2 * pi * 50 * t) cm <- comodulogram(sig, sr = 500, phase_freqs = c(4, 6, 8), amp_freqs = c(30, 50, 70)) cm$peak ## End(Not run)
Factorises two non-negative blocks that share the observation dimension into a
SHARED factor matrix W and modality-specific loadings Hx, Hy, minimising
||X - W Hx||^2 + ||Y - W Hy||^2. The shared W is the common latent drive
recovered jointly from both modalities.
coupledNMF( X, Y, rank, max_iter = 500L, tol = 1e-07, n_restart = 5L, seed = NULL )coupledNMF( X, Y, rank, max_iter = 500L, tol = 1e-07, n_restart = 5L, seed = NULL )
X, Y
|
Non-negative matrices with the same |
rank |
Number of shared factors. |
max_iter, tol
|
Iteration budget and convergence tolerance. |
n_restart |
Random restarts (best kept; default 5). |
seed |
Optional RNG seed. |
a coupled_nmf object: shared (n x rank shared factor W), Hx,
Hy (rank x p and rank x q loadings), vaf_x, vaf_y, vaf (combined),
iterations.
Lee & Seung (2001) NMF; Cichocki et al. (2009) coupled/joint NMF.
set.seed(1); W <- matrix(runif(50 * 2), 50, 2) # shared drive X <- W %*% matrix(runif(2 * 6), 2, 6); Y <- W %*% matrix(runif(2 * 4), 2, 4) fit <- coupledNMF(X, Y, rank = 2, n_restart = 2) fit$vafset.seed(1); W <- matrix(runif(50 * 2), 50, 2) # shared drive X <- W %*% matrix(runif(2 * 6), 2, 6); Y <- W %*% matrix(runif(2 * 4), 2, 4) fit <- coupledNMF(X, Y, rank = 2, n_restart = 2) fit$vaf
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", "dtf", "pdc", "transferentropy", "pac"), sr = NULL, ..., granger_method = c("parametric", "nonparametric") )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", "dtf", "pdc", "transferentropy", "pac"), sr = NULL, ..., granger_method = c("parametric", "nonparametric") )
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. |
granger_method |
Named-only estimator selector used when
|
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)
Wraps couplingAnalysis() with a per-object memoisation cache
held in the couplingResults slot of a
MultiPhysioExperiment. Results are keyed by a
digest of the analysis arguments (method, modalities,
channels, and any extra arguments), so a repeated identical request returns
the stored result without recomputing.
couplingAnalysisCached( mpe, method, modality_x = NULL, modality_y = NULL, channels_x = 1L, channels_y = 1L, ..., cache = TRUE )couplingAnalysisCached( mpe, method, modality_x = NULL, modality_y = NULL, channels_x = 1L, channels_y = 1L, ..., cache = TRUE )
mpe |
A |
method |
Character coupling method (see |
modality_x, modality_y
|
Character modality names to extract from |
channels_x, channels_y
|
Integer channel indices (default 1). |
... |
Additional arguments forwarded to |
cache |
Logical; if |
A list with result (the coupling result), mpe (the
object with its couplingResults cache updated) and cached
(TRUE when the result was served from the cache).
couplingAnalysis(), couplingResults()
eeg <- PhysioExperiment(assays = list(raw = matrix(rnorm(1000), 500, 2)), samplingRate = 250) emg <- PhysioExperiment(assays = list(raw = matrix(rnorm(1000), 500, 2)), samplingRate = 250) mpe <- MultiPhysioExperiment(EEG = eeg, EMG = emg) out <- couplingAnalysisCached(mpe, "coherence", "EEG", "EMG") out2 <- couplingAnalysisCached(out$mpe, "coherence", "EEG", "EMG") out2$cached # TRUEeeg <- PhysioExperiment(assays = list(raw = matrix(rnorm(1000), 500, 2)), samplingRate = 250) emg <- PhysioExperiment(assays = list(raw = matrix(rnorm(1000), 500, 2)), samplingRate = 250) mpe <- MultiPhysioExperiment(EEG = eeg, EMG = emg) out <- couplingAnalysisCached(mpe, "coherence", "EEG", "EMG") out2 <- couplingAnalysisCached(out$mpe, "coherence", "EEG", "EMG") out2$cached # TRUE
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
Returns the coupling results computed for x in this session by
couplingAnalysisCached.
couplingResults(x) ## S4 method for signature 'MultiPhysioExperiment' couplingResults(x) couplingResults(x) <- value ## S4 replacement method for signature 'MultiPhysioExperiment' couplingResults(x) <- valuecouplingResults(x) ## S4 method for signature 'MultiPhysioExperiment' couplingResults(x) couplingResults(x) <- value ## S4 replacement method for signature 'MultiPhysioExperiment' couplingResults(x) <- value
x |
A |
value |
A named list of results to cache for |
The cache is keyed on the signal values, the clock, the assay, the channels, the method and its parameters, so a result is only returned for inputs it was actually computed from. It is held for the session rather than stored inside the container: a cache carried inside a saved object outlives any evidence that it still matches its inputs.
A named list of cached results (empty when nothing is cached).
Fits a maximum-likelihood common-factor model to the pooled, standardised modality blocks and flags which latent factors are SHARED across modalities (load on more than one block) versus modality-specific – a latent-variable view of multi-modal integration.
crossBlockFactor(blocks, nfactors, load_threshold = 0.4)crossBlockFactor(blocks, nfactors, load_threshold = 0.4)
blocks |
A list of >= 2 matrices, each |
nfactors |
Number of common factors. |
load_threshold |
A factor is considered to load on a block if any of the
block's variables has |
a crossblock_factor object: loadings (variables x factors, with a
block attribute), shared (logical per factor: loads on >= 2 blocks),
n_shared, and the fitted factanal.
Spearman/Thurstone common-factor model; McDonald (1985).
jive(), multipleFactorAnalysis()
set.seed(1); f <- matrix(rnorm(80 * 1), 80, 1) a <- f %*% matrix(rnorm(4), 1, 4) + matrix(rnorm(80 * 4, 0, .4), 80, 4) b <- f %*% matrix(rnorm(3), 1, 3) + matrix(rnorm(80 * 3, 0, .4), 80, 3) crossBlockFactor(list(a = a, b = b), nfactors = 1)$sharedset.seed(1); f <- matrix(rnorm(80 * 1), 80, 1) a <- f %*% matrix(rnorm(4), 1, 4) + matrix(rnorm(80 * 4, 0, .4), 80, 4) b <- f %*% matrix(rnorm(3), 1, 3) + matrix(rnorm(80 * 3, 0, .4), 80, 3) crossBlockFactor(list(a = a, b = b), nfactors = 1)$shared
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|")
Computes the cross-wavelet transform of two signals
via the Morlet wavelet: its modulus is the common time-frequency power and its
argument is the phase lead/lag between the signals. Common power is tested
against an AR(1) red-noise background (Torrence & Compo 1998; Grinsted et al.
2004) by Monte-Carlo: AR(1) surrogates matched to each signal's lag-1
autocorrelation and variance are transformed identically, and the per-
frequency siglvl quantile of the surrogate cross-power sets the threshold.
crossWaveletTransform( x, y = NULL, sr = NULL, frequencies = seq(1, 40, by = 1), n_cycles = 7, significance = TRUE, n_surrogates = 100L, siglvl = 0.95, modality_x = NULL, modality_y = NULL, channels_x = 1L, channels_y = 1L )crossWaveletTransform( x, y = NULL, sr = NULL, frequencies = seq(1, 40, by = 1), n_cycles = 7, significance = TRUE, n_surrogates = 100L, siglvl = 0.95, modality_x = NULL, modality_y = NULL, channels_x = 1L, channels_y = 1L )
x, y
|
Signals (or a single object from which a pair is extracted). |
sr |
Sampling rate in Hz. |
frequencies |
Frequencies (Hz) to analyse (default |
n_cycles |
Morlet wavelet cycles (default 7). |
significance |
If |
n_surrogates |
Number of AR(1) surrogate pairs (default 100). |
siglvl |
Significance quantile (default 0.95). |
modality_x, modality_y, channels_x, channels_y
|
Passed to the pair extractor. |
An object of class "cross_wavelet": a list with power
(time x frequency cross-wavelet modulus), phase (relative phase, radians;
positive = x leads y), cross (complex XWT), frequencies, times,
coi (cone of influence), and — when significance — sig_level (per
frequency), sig_ratio (power / level), and significant (logical mask).
Torrence C, Compo GP (1998). A practical guide to wavelet analysis. Bull Amer Meteor Soc 79:61-78. Grinsted A, Moore JC, Jevrejeva S (2004). Application of the cross wavelet transform and wavelet coherence to geophysical time series. Nonlin Processes Geophys 11:561-566.
set.seed(1); sr <- 100; t <- seq(0, 20, by = 1 / sr) x <- sin(2 * pi * 10 * t) + rnorm(length(t), sd = 0.5) y <- sin(2 * pi * 10 * t - pi / 2) + rnorm(length(t), sd = 0.5) # y lags x xw <- crossWaveletTransform(x, y, sr = sr, frequencies = seq(4, 16, by = 1), n_surrogates = 50) mean(xw$significant)set.seed(1); sr <- 100; t <- seq(0, 20, by = 1 / sr) x <- sin(2 * pi * 10 * t) + rnorm(length(t), sd = 0.5) y <- sin(2 * pi * 10 * t - pi / 2) + rnorm(length(t), sd = 0.5) # y lags x xw <- crossWaveletTransform(x, y, sr = sr, frequencies = seq(4, 16, by = 1), n_surrogates = 50) mean(xw$significant)
Frequency-resolved directed connectivity via the Directed Transfer Function
(Kaminski & Blinowska 1991), computed from the transfer function of a
multivariate autoregressive model fitted with PhysioExperiment::mvarFit(). This
cross-modal implementation is numerically identical to PhysioEEG's
eegDTF on the same input. Because the transfer function inverts the
whole VAR system, DTF reflects both direct and indirect pathways.
directedTransferFunction( x, y = NULL, sr = NULL, order = 5L, freqs = NULL, normalized = TRUE, ffDTF = FALSE, band = NULL, mvar_method = "ols", modality_x = NULL, modality_y = NULL, channels_x = NULL, channels_y = NULL )directedTransferFunction( x, y = NULL, sr = NULL, order = 5L, freqs = NULL, normalized = TRUE, ffDTF = FALSE, band = NULL, mvar_method = "ols", modality_x = NULL, modality_y = NULL, channels_x = NULL, channels_y = NULL )
x |
A multichannel matrix (time x channels) or PhysioExperiment (with
|
y |
The second signal / PhysioExperiment of a pair, or |
sr |
Sampling rate in Hz (required for numeric-matrix input). |
order |
MVAR model order (default: 5), or |
freqs |
Frequencies in Hz (default: 128 points from 0 to the Nyquist frequency). |
normalized |
Row-normalize the DTF (default: |
ffDTF |
Use the full-frequency DTF normalization (default: |
band |
Optional length-2 band in Hz over which to average the returned matrix (default: all frequencies). |
mvar_method |
MVAR estimator (default: |
modality_x, modality_y, channels_x, channels_y
|
Passed to the shared
signal-pair extraction when |
A list with dtf (n x n x n_freqs array), the band-averaged
directed matrix (rows = targets, columns = sources),
frequencies, channels, and order. For a two-channel
input, dtf_xy and dtf_yx give the directional summaries.
Kaminski, M. J., & Blinowska, K. J. (1991). A new method of the description of the information flow in the brain structures. Biological Cybernetics, 65(3), 203-210.
partialDirectedCoherence(), transferEntropy(), grangerCausality()
set.seed(1) X <- matrix(rnorm(1500), ncol = 3) res <- directedTransferFunction(X, sr = 100, order = 4) dim(res$dtf)set.seed(1) X <- matrix(rnorm(1500), ncol = 3) res <- directedTransferFunction(X, sr = 100, order = 4) dim(res$dtf)
A dependence measure that captures NON-linear as well as linear cross-modal relationships and is zero if and only if the modalities are independent (Szekely et al. 2007). In [0, 1].
distanceCorrelation(X, Y, permutations = 0L, seed = NULL)distanceCorrelation(X, Y, permutations = 0L, seed = NULL)
X, Y
|
Matrices with the same |
permutations |
Row permutations for the null p-value (default 0). |
seed |
Optional RNG seed. |
a distance_correlation object: dcor, dcov, p_value, n.
Szekely GJ, Rizzo ML, Bakirov NK (2007) Ann Stat 35:2769-2794.
rvCoefficient(), representationalSimilarity()
set.seed(1); x <- rnorm(60); y <- x^2 + rnorm(60, 0, 0.3) # nonlinear distanceCorrelation(x, y)$dcorset.seed(1); x <- rnorm(60); y <- x^2 + rnorm(60, 0, 0.3) # nonlinear distanceCorrelation(x, y)$dcor
Aligns curve y to curve x by an optimal time warping computed in
the Square-Root Velocity Function representation, separating phase (the
warping) from amplitude (the residual shape difference). A pure-R
dynamic-programming solver is used by default; if the fdasrvf package is
available it is used for higher accuracy.
elasticAlign( x, y, t = NULL, lambda = 0, method = c("srvf"), max_step = 6L, smooth = FALSE, use_fdasrvf = NA )elasticAlign( x, y, t = NULL, lambda = 0, method = c("srvf"), max_step = 6L, smooth = FALSE, use_fdasrvf = NA )
x, y
|
Numeric curves of the same length. |
t |
Optional grid (defaults to an evenly spaced grid on 0..1). |
lambda |
Non-negative warping-roughness penalty (passed to fdasrvf when used; the pure-R solver ignores it beyond boundary/monotonicity). |
method |
Currently |
max_step |
Maximum DP step (bounds the local warping slope) for the pure-R solver (default: 6). |
smooth |
Smooth the pure-R warping with a monotone spline (default:
|
use_fdasrvf |
|
A list with gamma (the warping), aligned (y
warped to x), amplitude_distance, phase_distance, the
SRVFs, and the solver used.
Srivastava, A., Wu, W., Kurtek, S., Klassen, E., & Marron, J. S. (2011). Registration of functional data using Fisher-Rao metric. arXiv:1103.3817.
t <- seq(0, 1, length.out = 80) x <- exp(-((t - 0.5)^2) / (2 * 0.08^2)) y <- exp(-((t - 0.65)^2) / (2 * 0.08^2)) al <- elasticAlign(x, y) al$amplitude_distancet <- seq(0, 1, length.out = 80) x <- exp(-((t - 0.5)^2) / (2 * 0.08^2)) y <- exp(-((t - 0.65)^2) / (2 * 0.08^2)) al <- elasticAlign(x, y) al$amplitude_distance
Concatenates several modality blocks into a single design matrix for downstream (multi-view) machine learning, scaling each block so a large or high-variance modality does not dominate the fused features.
fuseBlocks(blocks, method = c("zscore", "mfa", "frobenius"))fuseBlocks(blocks, method = c("zscore", "mfa", "frobenius"))
blocks |
A list of matrices, each |
method |
Block scaling before concatenation: |
a fused_blocks object: matrix (n x sum(p_k)) and block_index
(column ranges per block).
multipleFactorAnalysis(), multimodalGaitIndex()
fuseBlocks(list(a = matrix(rnorm(20), 10, 2), b = matrix(rnorm(30) * 50, 10, 3)))$matrixfuseBlocks(list(a = matrix(rnorm(20), 10, 2), b = matrix(rnorm(30) * 50, 10, 3)))$matrix
Computes directed coupling between two physiological signals using either autoregressive prediction or nonparametric spectral factorization. Both scalar and 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, spectral_estimator = c("multitaper", "welch"), n_fft = NULL, segment_length = NULL, overlap = 0.5, time_bandwidth = 4, n_tapers = NULL, factor_tolerance = 1e-08, factor_max_iterations = 1000L, eigen_floor = 1e-10 )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, spectral_estimator = c("multitaper", "welch"), n_fft = NULL, segment_length = NULL, overlap = 0.5, time_bandwidth = 4, n_tapers = NULL, factor_tolerance = 1e-08, factor_max_iterations = 1000L, eigen_floor = 1e-10 )
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. With the
parametric method, |
method |
Character estimator. |
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). |
spectral_estimator |
Nonparametric cross-spectral estimator:
|
n_fft |
Even FFT length for the nonparametric estimator. |
segment_length |
Segment length for cross-spectral estimation. |
overlap |
Fractional segment overlap in |
time_bandwidth |
DPSS time-bandwidth product for multitaper estimation. |
n_tapers |
Number of DPSS tapers; |
factor_tolerance |
Relative Wilson-factor update tolerance. |
factor_max_iterations |
Maximum Wilson iterations. |
eigen_floor |
Relative positive eigenvalue floor used only for round-off-scale or ill-conditioned cross-spectral bins. |
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.
The parametric frequency-band path uses separate restricted and unrestricted univariate AR models and is an approximation to the full Geweke spectral decomposition. Its established output is retained for compatibility. The nonparametric path instead estimates a complete Hermitian 2x2 cross-spectral matrix with common windows/tapers, applies Wilson's minimum-phase factorization, and evaluates Geweke directional spectra. A scalar is the trapezoidal frequency mean over the selected band, with DC and Nyquist receiving endpoint half weights.
Cross-spectral eigenvalue adjustment is limited to the reported relative
eigen_floor; materially indefinite matrices fail. Wilson update
convergence and spectral reconstruction are checked separately. The
relative reconstruction limit is
min(0.05, max(0.02, 100 * factor_tolerance)), so it remains between 2%
and 5%; the observed error and limit are returned in the result.
Nonparametric estimation requires at least 32 paired samples and at least
two spectral realizations.
Granger causality is a stationary linear predictive-direction measure. It is not proof of physical, mechanistic, or interventional causality and does not resolve unmeasured confounding, common drivers, volume conduction, instantaneous mixing, or non-stationarity.
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, or NA for nonparametric
estimation.
Character estimator used.
Nonparametric results additionally contain the frequency grid, directional spectra, estimator/factorization metadata, innovation covariance, the factorization reconstruction limit, and regularization diagnostics.
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.
Wilson, G. T. (1972). The factorization of matricial spectral densities. SIAM Journal on Applied Mathematics, 23(4), 420-426.
Dhamala, M., Rangarajan, G., & Ding, M. (2008). Analyzing information flow in brain networks with nonparametric Granger causality. NeuroImage, 41(2), 354-362.
Dhamala, M., Rangarajan, G., & Ding, M. (2008). Estimating Granger causality from Fourier and wavelet transforms of time series data. Physical Review Letters, 100, 018701.
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
Decomposes several modality blocks that share an observation dimension into a low-rank JOINT structure common to all blocks, low-rank INDIVIDUAL structure specific to each, and residual noise (Lock et al. 2013). The joint scores are the integrated multi-modal representation; the per-block variance split tells you how much of each modality is shared versus idiosyncratic.
jive( blocks, rank_joint = 1L, rank_individual = 1L, center = TRUE, scale = TRUE, max_iter = 1000L, tol = 1e-08 )jive( blocks, rank_joint = 1L, rank_individual = 1L, center = TRUE, scale = TRUE, max_iter = 1000L, tol = 1e-08 )
blocks |
A list of >= 2 matrices, each |
rank_joint |
Rank of the joint structure. |
rank_individual |
Rank of each block's individual structure (a scalar, recycled, or a per-block vector). |
center, scale
|
Row-center each feature and scale each block to unit
Frobenius norm (so blocks contribute comparably); both default |
max_iter, tol
|
Iteration budget and convergence tolerance. |
a jive object: joint and individual (lists of n x p_k
matrices), joint_scores (n x rank_joint, the shared component scores),
variance (data frame of joint / individual / residual fraction per block),
ranks, iterations.
Lock EF, Hoadley KA, Marron JS, Nobel AB (2013) Ann Appl Stat 7:523-542.
multipleFactorAnalysis(), cca()
set.seed(1) shared <- matrix(rnorm(40 * 2), 40, 2) # common subject scores k <- shared %*% matrix(rnorm(2 * 6), 2, 6) + matrix(rnorm(40 * 6, 0, .3), 40, 6) e <- shared %*% matrix(rnorm(2 * 5), 2, 5) + matrix(rnorm(40 * 5, 0, .3), 40, 5) fit <- jive(list(kin = k, emg = e), rank_joint = 2, rank_individual = 1) fit$varianceset.seed(1) shared <- matrix(rnorm(40 * 2), 40, 2) # common subject scores k <- shared %*% matrix(rnorm(2 * 6), 2, 6) + matrix(rnorm(40 * 6, 0, .3), 40, 6) e <- shared %*% matrix(rnorm(2 * 5), 2, 5) + matrix(rnorm(40 * 5, 0, .3), 40, 5) fit <- jive(list(kin = k, emg = e), rank_joint = 2, rank_individual = 1) fit$variance
Convenience wrapper for coherence with type = "lagged",
the lagged (non-instantaneous) coherence of Pascual-Marqui (2007),
Im(C) / sqrt(1 - Re(C)^2) where C is the complex coherency. Like
the imaginary part of coherency it is insensitive to zero-lag /
volume-conduction coupling.
laggedCoherence( 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 )laggedCoherence( 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). |
A named list as returned by coherence, with
type = "lagged".
Pascual-Marqui, R. D. (2007). Instantaneous and lagged measurements of linear and nonlinear dependence between groups of multivariate time series. arXiv:0711.1455.
sr <- 200 t <- seq(0, 10, length.out = sr * 10) x <- sin(2 * pi * 10 * t) y <- sin(2 * pi * 10 * t + pi / 2) # 90-degree lag lc <- laggedCoherence(x, y, sr = sr, freq_range = c(8, 12)) max(abs(lc$coherence))sr <- 200 t <- seq(0, 10, length.out = sr * 10) x <- sin(2 * pi * 10 * t) y <- sin(2 * pi * 10 * t + pi / 2) # 90-degree lag lc <- laggedCoherence(x, y, sr = sr, freq_range = c(8, 12)) max(abs(lc$coherence))
Leading Eigenvector Dynamics Analysis (Cabral et al. 2017): at each time point the instantaneous phase-coherence matrix is reduced to its leading eigenvector; these are clustered over time into a small set of recurrent connectivity states. Complements state-resolved network analysis by finding the states data-drivenly rather than from external labels.
leidaStates( x, sr, freq_band, n_states = 4L, order = 4L, nstart = 10L, seed = NULL )leidaStates( x, sr, freq_band, n_states = 4L, order = 4L, nstart = 10L, seed = NULL )
x |
A numeric matrix, time (rows) by channels (columns). |
sr |
Sampling rate in Hz. |
freq_band |
Numeric |
n_states |
Number of clusters/states (default 4). |
order |
Butterworth filter order (default 4). |
nstart |
k-means restarts (default 10). |
seed |
Optional integer seed for reproducible clustering. |
An object of class "leida": a list with states (per-time cluster
labels), centroids (states x channels leading-eigenvector centroids),
occupancy (fraction of time in each state), dwell (mean run length in
samples per state), and n_states.
Cabral J, et al. (2017). Cognitive performance in healthy older adults relates to spontaneous switching between states of functional connectivity during rest. Sci Rep 7:5135.
set.seed(1); sr <- 100; n <- 2000; t <- seq_len(n) / sr # two regimes: channels 1-2 coherent first half, 3-4 coherent second half base <- sin(2 * pi * 10 * t) X <- cbind(base + rnorm(n, sd = .3), base + rnorm(n, sd = .3), sin(2 * pi * 10 * t + 1) + rnorm(n, sd = .3), sin(2 * pi * 10 * t + 1) + rnorm(n, sd = .3)) res <- leidaStates(X, sr = sr, freq_band = c(8, 12), n_states = 2, seed = 1) res$occupancyset.seed(1); sr <- 100; n <- 2000; t <- seq_len(n) / sr # two regimes: channels 1-2 coherent first half, 3-4 coherent second half base <- sin(2 * pi * 10 * t) X <- cbind(base + rnorm(n, sd = .3), base + rnorm(n, sd = .3), sin(2 * pi * 10 * t + 1) + rnorm(n, sd = .3), sin(2 * pi * 10 * t + 1) + rnorm(n, sd = .3)) res <- leidaStates(X, sr = sr, freq_band = c(8, 12), n_states = 2, seed = 1) res$occupancy
From a leidaStates() result, computes the state-to-state transition
probability matrix, the switching rate, fractional occupancy, mean dwell
time, and the occupancy-weighted transition entropy (predictability of the
next state).
leidaTransitions(x, sr = NULL)leidaTransitions(x, sr = NULL)
x |
A |
sr |
Optional sampling rate (Hz); if given, dwell times are returned in seconds and the switching rate additionally in Hz. |
An object of class "leida_transitions": a list with transition
(row-stochastic state x state matrix), counts (raw transition counts),
switching_rate (fraction of steps that change state), switching_rate_hz
(switches per second, or NA), occupancy, dwell, and entropy
(mean bits of uncertainty about the next state).
set.seed(1); sr <- 100; n <- 2000; t <- seq_len(n) / sr base <- sin(2 * pi * 10 * t) X <- cbind(base + rnorm(n, sd = .3), base + rnorm(n, sd = .3), sin(2 * pi * 10 * t + 1) + rnorm(n, sd = .3), sin(2 * pi * 10 * t + 1) + rnorm(n, sd = .3)) res <- leidaStates(X, sr = sr, freq_band = c(8, 12), n_states = 2, seed = 1) leidaTransitions(res, sr = sr)set.seed(1); sr <- 100; n <- 2000; t <- seq_len(n) / sr base <- sin(2 * pi * 10 * t) X <- cbind(base + rnorm(n, sd = .3), base + rnorm(n, sd = .3), sin(2 * pi * 10 * t + 1) + rnorm(n, sd = .3), sin(2 * pi * 10 * t + 1) + rnorm(n, sd = .3)) res <- leidaStates(X, sr = sr, freq_band = c(8, 12), n_states = 2, seed = 1) leidaTransitions(res, sr = sr)
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)
Computes Tort, Canolty, or Ozkurt phase-amplitude coupling over a declared frequency grid. Each surrogate amplitude-source signal produces one complete matrix, so cell-wise p-values share a coherent null replicate. P-values use the conservative Phipson-Smyth correction and are adjusted over the complete grid.
modulationIndex( x, phase_freqs, amp_freqs, sr = NULL, y = NULL, method = c("tort", "canolty", "ozkurt"), phase_bw = 2, amp_bw = 10, n_bins = 18L, order = 4L, n_surrogates = 199L, surrogate_type = c("timeshift", "phase", "iaaft", "aaft"), alpha = 0.05, p_adjust_method = "BH", seed = NULL, cores = 1L, modality_x = NULL, modality_y = NULL, channels_x = 1L, channels_y = 1L )modulationIndex( x, phase_freqs, amp_freqs, sr = NULL, y = NULL, method = c("tort", "canolty", "ozkurt"), phase_bw = 2, amp_bw = 10, n_bins = 18L, order = 4L, n_surrogates = 199L, surrogate_type = c("timeshift", "phase", "iaaft", "aaft"), alpha = 0.05, p_adjust_method = "BH", seed = NULL, cores = 1L, modality_x = NULL, modality_y = NULL, channels_x = 1L, channels_y = 1L )
x |
A numeric signal or PhysioExperiment providing the phase source, or a MultiPhysioExperiment. |
phase_freqs |
Strictly increasing phase-band centre frequencies in Hz. |
amp_freqs |
Strictly increasing amplitude-band centre frequencies in Hz. |
sr |
Sampling rate in Hz, required for numeric input. |
y |
Optional amplitude-source signal or PhysioExperiment. When
|
method |
|
phase_bw, amp_bw
|
Half-bandwidths in Hz. |
n_bins |
Number of phase bins for Tort MI. |
order |
Bandpass filter order. |
n_surrogates |
Number of full-grid surrogates. Use zero to disable inference explicitly. |
surrogate_type |
|
alpha |
Significance level. |
p_adjust_method |
A method from |
seed |
Optional non-negative integer seed. |
cores |
Positive integer number of worker processes. |
modality_x, modality_y, channels_x, channels_y
|
Passed to the shared signal-pair extractor. |
PAC is an association and can be produced by waveform shape, filter leakage,
edge transients, non-stationarity, or common inputs. A high or significant
value does not establish cross-frequency communication or a biological
mechanism. The returned threshold is the unadjusted cell-wise null quantile;
the significant mask is instead defined from adjusted p-values.
Benjamini-Hochberg controls the false discovery rate, not strong family-wise
error. Requested and exact realized pass bands are both retained; a
structured diagnostic records any adjustment at the filter's numerical
boundary.
A pac_comodulogram list containing the observed matrix,
grid and realized bands, peak, cell-wise p-values, adjusted p-values,
significance mask, null thresholds and summaries, surrogate settings, and
structured diagnostic strings. Inferential matrices are NULL when
n_surrogates = 0.
Tort, A. B. L., et al. (2010). Journal of Neurophysiology, 104, 1195-1210.
Canolty, R. T., et al. (2006). Science, 313, 1626-1628.
Ozkurt, T. E., & Schnitzler, A. (2011). Journal of Neuroscience Methods, 201, 438-443.
Phipson, B., & Smyth, G. K. (2010). Statistical Applications in Genetics and Molecular Biology, 9, Article 39.
comodulogram(), phaseAmplitudeCoupling(),
plotComodulogram()
## Not run: set.seed(1) t <- (0:4999) / 500 ph <- 2 * pi * 6 * t sig <- sin(ph) + (0.1 + (1 + cos(ph - pi)) / 2) * sin(2 * pi * 50 * t) mi <- modulationIndex(sig, c(4, 6, 8), c(40, 50, 60), sr = 500, n_surrogates = 99, seed = 1) plotComodulogram(mi) ## End(Not run)## Not run: set.seed(1) t <- (0:4999) / 500 ph <- 2 * pi * 6 * t sig <- sin(ph) + (0.1 + (1 + cos(ph - pi)) / 2) * sin(2 * pi * 50 * t) mi <- modulationIndex(sig, c(4, 6, 8), c(40, 50, 60), sr = 500, n_surrogates = 99, seed = 1) plotComodulogram(mi) ## End(Not run)
A Gait-Deviation-Index-style score (Schwartz & Rozumalski 2008) generalised across modalities: how far each subject's multi-modal gait feature vector lies from a normative reference cloud, scaled so a typical control scores ~100 and every 10 points is one standard deviation of deviation. Optionally broken down per modality to show which modality drives the deviation.
multimodalGaitIndex( features, reference, blocks = NULL, ve = 0.95, mean_index = 100, sd_index = 10 )multimodalGaitIndex( features, reference, blocks = NULL, ve = 0.95, mean_index = 100, sd_index = 10 )
features |
An |
reference |
An |
blocks |
Optional named list mapping each modality to its column indices
in |
ve |
Reference variance retained by the PCA whitening (default 0.95). |
mean_index, sd_index
|
Scaling (default 100 and 10, as for GDI). |
a multimodal_index object: index (per subject; ~100 = typical),
distance, reference_mean_index, and (if blocks given) by_modality
(subject x modality index matrix).
Schwartz MH, Rozumalski A (2008) Gait Posture 28:351-357.
set.seed(1); ctrl <- matrix(rnorm(60 * 8), 60, 8) subj <- rbind(matrix(rnorm(5 * 8), 5, 8), # typical matrix(rnorm(5 * 8, 3), 5, 8)) # deviant multimodalGaitIndex(subj, ctrl)$indexset.seed(1); ctrl <- matrix(rnorm(60 * 8), 60, 8) subj <- rbind(matrix(rnorm(5 * 8), 5, 8), # typical matrix(rnorm(5 * 8, 3), 5, 8)) # deviant multimodalGaitIndex(subj, ctrl)$index
PhysioCrossModal used to define its own MultiPhysioExperiment
class, holding experiments / alignment / sampleMap /
couplingResults. That class no longer exists here: the ecosystem has a
single multimodal container, defined in PhysioExperiment, and this
package is an analysis package that takes it as input.
The constructor and every accessor keep their names and return types, so
existing code runs unchanged:
MultiPhysioExperiment(), experiments(), modalities(),
samplingRates(), nModalities(), alignment(),
alignment<-, length(), names(), [, [[.
alignment() is now a view computed from the container's shared clock
rather than a separately stored table, so the alignment and the signals
cannot drift apart.
Containers saved under the old class are converted by
migrateContainer or read with
readPhysioRDS.
MultiPhysioExperiment,
couplingAnalysis, couplingResults
length(), names(), [ and [[ for the multimodal
container are defined once, in PhysioExperiment, and are imported from
there. They are not redefined here: two definitions of the
same method on the same class is exactly the divergence this package's own
container was unified away to prevent.
One behaviour changed in the move, deliberately. The [ defined here
selected a time window by computing floor(t * rate) + 1 from each
modality's sampling rate alone. That ignored each stream's start offset on
the shared clock, so a window taken from modalities that did not start
together returned mismatched spans; it also rebuilt the alignment table from
defaults, resetting every offset to zero, and discarded the sample map.
Selection is now made on each sample's actual time, the clock is preserved,
and each stream's offset is updated to its first retained sample. For windows
whose bounds land on sample times - including all simultaneously started data
with grid-aligned bounds - the selection is unchanged.
The cache accessors couplingResults() and
couplingResults<- are defined in coupling-wrapper.R, where the
cache itself lives.
timeWindow,
MultiPhysioExperiment
A global PCA over several blocks in which each block is first scaled by its leading singular value, so a large or high-variance modality cannot dominate the shared factors (Escofier & Pages 1994). Gives global factor scores on the shared observations, with each block's contribution to each factor.
multipleFactorAnalysis( blocks, ncomp = 2L, center = TRUE, scale_columns = FALSE )multipleFactorAnalysis( blocks, ncomp = 2L, center = TRUE, scale_columns = FALSE )
blocks |
A list of >= 2 matrices, each |
ncomp |
Number of global factors (default 2). |
center, scale_columns
|
Center (and, if |
an mfa object: scores (n x ncomp global factor scores),
eigenvalues, explained (proportion of variance per factor),
contributions (block x factor, each block's share of a factor's inertia),
block_weights.
Escofier B, Pages J (1994) Comput Stat Data Anal 18:121-140.
set.seed(1) s <- matrix(rnorm(30 * 2), 30, 2) b1 <- s %*% matrix(rnorm(2 * 5), 2, 5) + matrix(rnorm(30 * 5, 0, .3), 30, 5) b2 <- s %*% matrix(rnorm(2 * 4), 2, 4) + matrix(rnorm(30 * 4, 0, .3), 30, 4) multipleFactorAnalysis(list(kin = b1, grf = b2))$explainedset.seed(1) s <- matrix(rnorm(30 * 2), 30, 2) b1 <- s %*% matrix(rnorm(2 * 5), 2, 5) + matrix(rnorm(30 * 5, 0, .3), 30, 5) b2 <- s %*% matrix(rnorm(2 * 4), 2, 4) + matrix(rnorm(30 * 4, 0, .3), 30, 4) multipleFactorAnalysis(list(kin = b1, grf = b2))$explained
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)
Computes the mutual information (Shannon, 1948) between two signals – the
amount of information one signal carries about the other, a symmetric,
undirected, nonlinear measure of statistical dependence. It is the
information-theoretic complement of transferEntropy (directed):
, zero iff the two
signals are independent.
mutualInformation(x, y, bins = 16L)mutualInformation(x, y, bins = 16L)
x, y
|
Numeric vectors of equal length. |
bins |
Number of equal-width bins per signal (default 16). |
This is the histogram estimator: each signal is discretized into
bins equal-width bins and the mutual information of the resulting joint
distribution is returned, in nats (natural log), matching
sklearn.metrics.mutual_info_score on the same binning. The histogram
estimator has a positive finite-sample bias (a shuffled surrogate has non-zero
MI), so compare against a shuffled control or use more data / fewer bins for a
cleaner estimate.
A single numeric value, the mutual information in nats.
Shannon, C. E. (1948). "A mathematical theory of communication." Bell System Technical Journal, 27(3), 379–423.
transferEntropy for the directed (model-free) coupling,
coherence for frequency-domain coupling.
set.seed(1) a <- rnorm(1000); b <- a + rnorm(1000) mutualInformation(a, b) # > 0 (dependent) mutualInformation(a, rnorm(1000)) # near the finite-sample floorset.seed(1) a <- rnorm(1000); b <- a + rnorm(1000) mutualInformation(a, b) # > 0 (dependent) mutualInformation(a, rnorm(1000)) # near the finite-sample floor
Amplitude-envelope correlation after pairwise orthogonalisation (Hipp et al. 2012; Brookes et al. 2012): the instantaneous zero-lag (leakage) component is projected out before correlating band-limited amplitude envelopes, so shared instantaneous mixing does not create spurious coupling. Symmetrised over the two orthogonalisation directions.
orthogonalizedAEC( x, y = NULL, sr = NULL, freq_band, order = 4L, modality_x = NULL, modality_y = NULL, channels_x = 1L, channels_y = 1L )orthogonalizedAEC( x, y = NULL, sr = NULL, freq_band, order = 4L, modality_x = NULL, modality_y = NULL, channels_x = 1L, channels_y = 1L )
x, y
|
Signals (or a single object from which a pair is extracted). |
sr |
Sampling rate in Hz. |
freq_band |
Numeric |
order |
Butterworth filter order for the band-pass (default 4). |
modality_x, modality_y, channels_x, channels_y
|
Passed to the internal signal-pair extractor. |
A single leakage-corrected envelope correlation in [-1, 1].
Hipp JF, et al. (2012). Large-scale cortical correlation structure of spontaneous oscillatory activity. Nat Neurosci 15:884-890.
set.seed(1); sr <- 200; n <- 4000 x <- as.numeric(stats::filter(rnorm(n), rep(1/5, 5), sides = 2)); x[is.na(x)] <- 0 y <- c(rep(0, 10), x[seq_len(n - 10)]) + rnorm(n, sd = 0.5) orthogonalizedAEC(x, y, sr = sr, freq_band = c(8, 12))set.seed(1); sr <- 200; n <- 4000 x <- as.numeric(stats::filter(rnorm(n), rep(1/5, 5), sides = 2)); x[is.na(x)] <- 0 y <- c(rep(0, 10), x[seq_len(n - 10)]) + rnorm(n, sd = 0.5) orthogonalizedAEC(x, y, sr = sr, freq_band = c(8, 12))
The bias-free phase-synchrony estimator of Vinck et al. (2010):
. Unlike the PLV it is not
inflated by the sample size.
pairwisePhaseConsistency( x, y = NULL, sr = NULL, freq_band, order = 4L, modality_x = NULL, modality_y = NULL, channels_x = 1L, channels_y = 1L )pairwisePhaseConsistency( x, y = NULL, sr = NULL, freq_band, order = 4L, modality_x = NULL, modality_y = NULL, channels_x = 1L, channels_y = 1L )
x, y
|
Signals (or a single object from which a pair is extracted). |
sr |
Sampling rate in Hz. |
freq_band |
Numeric |
order |
Butterworth filter order for the band-pass (default 4). |
modality_x, modality_y, channels_x, channels_y
|
Passed to the internal signal-pair extractor. |
A single PPC value (approaches 1 for perfect locking, 0 for none).
Vinck M, et al. (2010). The pairwise phase consistency. NeuroImage 51:112-122.
Frequency-resolved directed connectivity via Partial Directed Coherence
(Baccala & Sameshima 2001), computed from the coefficient matrix of an MVAR
model (PhysioExperiment::mvarFit()); numerically identical to PhysioEEG's
eegPDC. Unlike DTF, PDC reflects only direct influences, so a purely
indirect pathway gives PDC near zero.
partialDirectedCoherence( x, y = NULL, sr = NULL, order = 5L, freqs = NULL, generalized = TRUE, band = NULL, mvar_method = "ols", modality_x = NULL, modality_y = NULL, channels_x = NULL, channels_y = NULL )partialDirectedCoherence( x, y = NULL, sr = NULL, order = 5L, freqs = NULL, generalized = TRUE, band = NULL, mvar_method = "ols", modality_x = NULL, modality_y = NULL, channels_x = NULL, channels_y = NULL )
x |
A multichannel matrix (time x channels) or PhysioExperiment (with
|
y |
The second signal / PhysioExperiment of a pair, or |
sr |
Sampling rate in Hz (required for numeric-matrix input). |
order |
MVAR model order (default: 5), or |
freqs |
Frequencies in Hz (default: 128 points from 0 to the Nyquist frequency). |
generalized |
Use generalized PDC (inverse-noise weighting; default
|
band |
Optional length-2 band in Hz over which to average the returned matrix (default: all frequencies). |
mvar_method |
MVAR estimator (default: |
modality_x, modality_y, channels_x, channels_y
|
Passed to the shared
signal-pair extraction when |
A list as in directedTransferFunction() with a pdc array and
band-averaged matrix; for a two-channel input, pdc_xy and
pdc_yx.
Baccala, L. A., & Sameshima, K. (2001). Partial directed coherence: a new concept in neural structure determination. Biological Cybernetics, 84(6), 463-474.
directedTransferFunction(), transferEntropy()
set.seed(1) X <- matrix(rnorm(1500), ncol = 3) res <- partialDirectedCoherence(X, sr = 100, order = 4) dim(res$pdc)set.seed(1) X <- matrix(rnorm(1500), ncol = 3) res <- partialDirectedCoherence(X, sr = 100, order = 4) dim(res$pdc)
Quantifies how the amplitude of a fast oscillation (in amp_band) is
modulated by the phase of a slow oscillation (in phase_band). The
phase is taken from x and the amplitude envelope from y (or
from x itself when y is NULL), each via a bandpass filter
and the Hilbert transform. Supported measures are the Tort modulation index
(a normalized Kullback-Leibler distance of the phase-amplitude distribution
from uniform, in 0..1), the Canolty mean vector length (raw), the Ozkurt
normalized mean vector length (in 0..1), and a phase-locking value.
phaseAmplitudeCoupling( x, y = NULL, sr = NULL, phase_band = c(4, 8), amp_band = c(30, 80), method = c("tort", "canolty", "ozkurt", "plv"), n_bins = 18L, order = 4L, modality_x = NULL, modality_y = NULL, channels_x = 1L, channels_y = 1L )phaseAmplitudeCoupling( x, y = NULL, sr = NULL, phase_band = c(4, 8), amp_band = c(30, 80), method = c("tort", "canolty", "ozkurt", "plv"), n_bins = 18L, order = 4L, modality_x = NULL, modality_y = NULL, channels_x = 1L, channels_y = 1L )
x |
A numeric signal or PhysioExperiment (phase source), or a MultiPhysioExperiment. |
y |
A numeric signal or PhysioExperiment (amplitude source), or
|
sr |
Sampling rate in Hz (required for numeric input). |
phase_band |
Numeric length-2 phase frequency band in Hz
(default: |
amp_band |
Numeric length-2 amplitude frequency band in Hz
(default: |
method |
|
n_bins |
Number of phase bins for the Tort modulation index (default: 18). |
order |
Bandpass filter order (default: 4). |
modality_x, modality_y, channels_x, channels_y
|
Passed to the shared signal-pair extraction. |
A list with pac (the coupling value), method,
phase_band, amp_band, and, for the Tort method, the
per-bin normalized amplitude distribution and bin_centers.
Tort, A. B. L., et al. (2010). Measuring phase-amplitude coupling between neuronal oscillations of different frequencies. Journal of Neurophysiology, 104(2), 1195-1210.
Canolty, R. T., et al. (2006). High gamma power is phase-locked to theta oscillations in human neocortex. Science, 313(5793), 1626-1628.
comodulogram(), plotComodulogram(), surrogateTest()
set.seed(1) t <- (0:4999) / 500 ph <- 2 * pi * 6 * t sig <- sin(ph) + (0.1 + (1 + cos(ph - pi)) / 2) * sin(2 * pi * 50 * t) phaseAmplitudeCoupling(sig, sr = 500, phase_band = c(4, 8), amp_band = c(35, 65))$pacset.seed(1) t <- (0:4999) / 500 ph <- 2 * pi * 6 * t sig <- sin(ph) + (0.1 + (1 + cos(ph - pi)) / 2) * sin(2 * pi * 50 * t) phaseAmplitudeCoupling(sig, sr = 500, phase_band = c(4, 8), amp_band = c(35, 65))$pac
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
The Phase Slope Index (Nolte et al. 2008) estimates the direction of
information flow from the slope of the coherency phase across a frequency
band, and is insensitive to instantaneous (zero-lag) mixing. Positive values
indicate that x leads (drives) y.
phaseSlopeIndex( x, y = NULL, sr = NULL, freq_band, nperseg = 256L, noverlap = NULL, normalize = TRUE, modality_x = NULL, modality_y = NULL, channels_x = 1L, channels_y = 1L )phaseSlopeIndex( x, y = NULL, sr = NULL, freq_band, nperseg = 256L, noverlap = NULL, normalize = TRUE, modality_x = NULL, modality_y = NULL, channels_x = 1L, channels_y = 1L )
x, y
|
Signals (or a single object from which a pair is extracted). |
sr |
Sampling rate in Hz. |
freq_band |
Numeric |
nperseg, noverlap
|
Welch segment length / overlap for the cross-spectrum. |
normalize |
If |
modality_x, modality_y, channels_x, channels_y
|
Passed to the internal signal-pair extractor. |
A single Phase Slope Index value.
Nolte G, et al. (2008). Robustly estimating the flow direction of information in complex physical systems. Phys Rev Lett 100:234101. doi:10.1103/PhysRevLett.100.234101
set.seed(1); sr <- 200; n <- 4000 x <- as.numeric(stats::filter(rnorm(n), rep(1/5, 5), sides = 2)); x[is.na(x)] <- 0 y <- c(rep(0, 8), x[seq_len(n - 8)]) # y lags x phaseSlopeIndex(x, y, sr = sr, freq_band = c(1, 40))set.seed(1); sr <- 200; n <- 4000 x <- as.numeric(stats::filter(rnorm(n), rep(1/5, 5), sides = 2)); x[is.na(x)] <- 0 y <- c(rep(0, 8), x[seq_len(n - 8)]) # y lags x phaseSlopeIndex(x, y, sr = sr, freq_band = c(1, 40))
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) }
Renders a comodulogram (from comodulogram()) as a heatmap.
plotComodulogram( result, title = "Comodulogram", mask = NULL, nonsignificant_alpha = 0.2 )plotComodulogram( result, title = "Comodulogram", mask = NULL, nonsignificant_alpha = 0.2 )
result |
A comodulogram result list. |
title |
Plot title. |
mask |
Optional logical significance mask or numeric p-value matrix.
When |
nonsignificant_alpha |
Opacity for non-significant cells. |
A ggplot object.
comodulogram(), modulationIndex()
## Not run: plotComodulogram(comodulogram(sig, sr = 500, phase_freqs = c(4, 6, 8), amp_freqs = c(30, 50, 70))) ## End(Not run)## Not run: plotComodulogram(comodulogram(sig, sr = 500, phase_freqs = c(4, 6, 8), amp_freqs = c(30, 50, 70))) ## End(Not run)
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 = PhysioExperiment::physioPalette(2, "sequential")[1], ... )plotCouplingMatrix( mat, title = "Coupling Matrix", low_colour = "white", high_colour = PhysioExperiment::physioPalette(2, "sequential")[1], ... )
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: the dark end of the colorblind-safe sequential palette,
|
... |
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) }
Finds the linear combinations of two modality blocks with maximal cross-modal COVARIANCE (unlike CCA's correlation), by the singular value decomposition of the cross-covariance and successive deflation. Robust when features outnumber observations, so it suits high-dimensional modalities.
plsBlocks(X, Y, ncomp = 2L)plsBlocks(X, Y, ncomp = 2L)
X, Y
|
Matrices with the same |
ncomp |
Number of PLS components (default 2). |
a pls_blocks object: xweights, yweights (the paired directions),
xscores, yscores, covariance (per-component score covariance) and
correlation (per-component score correlation).
Wold H (1975); Bookstein (1994) PLS-SVD; Krishnan et al. (2011).
set.seed(1); z <- matrix(rnorm(40), 40, 1) X <- z %*% matrix(rnorm(6), 1, 6) + matrix(rnorm(40 * 6, 0, .3), 40, 6) Y <- z %*% matrix(rnorm(5), 1, 5) + matrix(rnorm(40 * 5, 0, .3), 40, 5) plsBlocks(X, Y, ncomp = 1)$correlationset.seed(1); z <- matrix(rnorm(40), 40, 1) X <- z %*% matrix(rnorm(6), 1, 6) + matrix(rnorm(40 * 6, 0, .3), 40, 6) Y <- z %*% matrix(rnorm(5), 1, 5) + matrix(rnorm(40 * 5, 0, .3), 40, 5) plsBlocks(X, Y, ncomp = 1)$correlation
Compares the geometry of observations between modalities: each block's representational dissimilarity matrix (RDM – pairwise distances between the shared observations, using that modality's features) is compared across blocks. Two modalities are "representationally similar" if observations that are far apart in one are far apart in the other.
representationalSimilarity( blocks, method = c("euclidean", "correlation"), compare = c("spearman", "pearson"), permutations = 0L, seed = NULL )representationalSimilarity( blocks, method = c("euclidean", "correlation"), compare = c("spearman", "pearson"), permutations = 0L, seed = NULL )
blocks |
A list of >= 2 matrices, each |
method |
RDM distance: |
compare |
RDM comparison: |
permutations |
For a PAIR of blocks, Mantel permutations for a p-value (default 0). |
seed |
Optional RNG seed. |
an rsa object: similarity (block x block RSA matrix) and, for two
blocks with permutations > 0, p_value (Mantel).
Kriegeskorte N, et al. (2008) Front Syst Neurosci 2:4.
rvCoefficient(), distanceCorrelation()
set.seed(1); z <- matrix(rnorm(30 * 2), 30, 2) a <- z %*% matrix(rnorm(2 * 5), 2, 5); b <- z %*% matrix(rnorm(2 * 4), 2, 4) representationalSimilarity(list(a = a, b = b))$similarityset.seed(1); z <- matrix(rnorm(30 * 2), 30, 2) a <- z %*% matrix(rnorm(2 * 5), 2, 5); b <- z %*% matrix(rnorm(2 * 4), 2, 4) representationalSimilarity(list(a = a, b = b))$similarity
The multivariate generalisation of a squared correlation: how much the two blocks' configurations of observations agree, in [0, 1] (0 = unrelated, 1 = identical up to rotation/scaling).
rvCoefficient(X, Y, center = TRUE, permutations = 0L, seed = NULL)rvCoefficient(X, Y, center = TRUE, permutations = 0L, seed = NULL)
X, Y
|
Matrices with the same |
center |
Column-centre each block first (default |
permutations |
Row permutations for the null p-value (default 0 = skip). |
seed |
Optional RNG seed for the permutation test. |
an rv_coefficient object: rv, p_value, n.
Robert P, Escoufier Y (1976) Appl Stat 25:257-265.
distanceCorrelation(), representationalSimilarity(), cca()
set.seed(1); z <- matrix(rnorm(40 * 2), 40, 2) X <- z %*% matrix(rnorm(2 * 5), 2, 5) + matrix(rnorm(40 * 5, 0, .3), 40, 5) Y <- z %*% matrix(rnorm(2 * 4), 2, 4) + matrix(rnorm(40 * 4, 0, .3), 40, 4) rvCoefficient(X, Y)$rvset.seed(1); z <- matrix(rnorm(40 * 2), 40, 2) X <- z %*% matrix(rnorm(2 * 5), 2, 5) + matrix(rnorm(40 * 5, 0, .3), 40, 5) Y <- z %*% matrix(rnorm(2 * 4), 2, 4) + matrix(rnorm(40 * 4, 0, .3), 40, 4) rvCoefficient(X, Y)$rv
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
Computes the elastic template mean of repeated curves by iteratively aligning every curve to the current mean and averaging the aligned curves. Because the phase variability is removed before averaging, peaks are preserved rather than blurred out (unlike a naive cross-curve mean).
srvfMean(curves, t = NULL, iterations = 5L, max_step = 6L, use_fdasrvf = NA)srvfMean(curves, t = NULL, iterations = 5L, max_step = 6L, use_fdasrvf = NA)
curves |
A list of numeric curves of the same length, or a matrix whose columns are curves. |
t |
Optional grid (defaults to 0..1). |
iterations |
Number of refinement iterations (default: 5). |
max_step |
Maximum DP step for the pure-R solver (default: 6). |
use_fdasrvf |
As in |
A list with the elastic mean curve, the warpings (a
matrix, one column per curve), and the aligned curves.
t <- seq(0, 1, length.out = 80) curves <- lapply(c(-0.1, 0, 0.1), function(s) exp(-((t - (0.5 + s))^2) / (2 * 0.05^2))) m <- srvfMean(curves) max(m$mean)t <- seq(0, 1, length.out = 80) curves <- lapply(c(-0.1, 0, 0.1), function(s) exp(-((t - (0.5 + s))^2) / (2 * 0.05^2))) m <- srvfMean(curves) max(m$mean)
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", "iaaft", "aaft"), 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", "iaaft", "aaft"), 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", "iaaft", "aaft"), 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", "iaaft", "aaft"), 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
Estimates the transfer entropy from x to y and back
(Schreiber 2000), a model-free measure of directed information flow, with a
histogram (binning) estimator or the Kraskov-Stoegbauer-Grassberger (KSG)
k-nearest-neighbour estimator. With effective = TRUE the estimate is
bias-corrected by subtracting the mean transfer entropy of IAAFT surrogates
of the source, so independent signals give an effective transfer entropy near
zero.
transferEntropy( x, y = NULL, sr = NULL, k = 1L, l = 1L, delay = 1L, estimator = c("ksg", "histogram"), knn = 4L, bins = 8L, effective = FALSE, n_surrogate = 19L, seed = NULL, modality_x = NULL, modality_y = NULL, channels_x = 1L, channels_y = 1L )transferEntropy( x, y = NULL, sr = NULL, k = 1L, l = 1L, delay = 1L, estimator = c("ksg", "histogram"), knn = 4L, bins = 8L, effective = FALSE, n_surrogate = 19L, seed = NULL, modality_x = NULL, modality_y = NULL, channels_x = 1L, channels_y = 1L )
x, y
|
Two numeric signals or PhysioExperiment objects (or a
MultiPhysioExperiment via |
sr |
Sampling rate in Hz (required for numeric input). |
k |
Target (destination) embedding length (default: 1). |
l |
Source embedding length (default: 1). |
delay |
Source-to-target lag in samples (default: 1). |
estimator |
|
knn |
Number of neighbours for the KSG estimator (default: 4). |
bins |
Number of bins per dimension for the histogram estimator (default: 8). |
effective |
Subtract the surrogate (IAAFT) null mean (default:
|
n_surrogate |
Number of surrogates for |
seed |
Optional RNG seed for reproducible surrogates. |
modality_x, modality_y, channels_x, channels_y
|
Passed to the shared signal-pair extraction. |
A list with te_xy, te_yx, and net
(te_xy - te_yx); when effective = TRUE also eff_xy,
eff_yx, and the surrogate null standard deviations.
Schreiber, T. (2000). Measuring information transfer. Physical Review Letters, 85(2), 461-464.
Kraskov, A., Stoegbauer, H., & Grassberger, P. (2004). Estimating mutual information. Physical Review E, 69(6), 066138.
directedTransferFunction(), grangerCausality(),
surrogateTest()
set.seed(1) x <- rnorm(600); y <- c(rep(0, 5), 0.7 * x[1:595]) + rnorm(600, sd = 0.5) transferEntropy(x, y, sr = 100, delay = 5, estimator = "histogram")$netset.seed(1) x <- rnorm(600); y <- c(rep(0, 5), 0.7 * x[1:595]) + rnorm(600, sd = 0.5) transferEntropy(x, y, sr = 100, delay = 5, estimator = "histogram")$net
Carries a warping computed by elasticAlign() onto another channel or
modality (e.g. warp an EMG envelope by the diffeomorphism that aligns the
EEG).
warpApply(signal, gamma, t = NULL)warpApply(signal, gamma, t = NULL)
signal |
Numeric signal to warp (same length as the warping grid). |
gamma |
A warping from |
t |
Optional grid (defaults to 0..1). |
The warped signal.
t <- seq(0, 1, length.out = 50) warpApply(sin(2 * pi * t), gamma = t^1.5, t = t)[1:3]t <- seq(0, 1, length.out = 50) warpApply(sin(2 * pi * t), gamma = t^1.5, t = t)[1:3]
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