| Title: | Dynamic Connectivity Analysis for Neurophysiological Timeseries |
|---|---|
| Description: | An R port of the Python dynfc library for computing dynamic connectivity (dynFC) representations from multivariate neurophysiological timeseries, including BOLD fMRI, EEG, LFP, and related signals. Implements sliding-window Pearson correlation (Hansen et al., 2015), edge-centric cofluctuation analysis (Esfahlani et al., 2020; Faskowitz et al., 2020), instantaneous phase-locking via the Hilbert transform, dynamic phase-locking matrices (dPL), the LEiDA leading-eigenvector framework (Cabral et al., 2017; Lord et al., 2019), and the Kuramoto order parameter with metastability and Shannon entropy. Part of the Circadia Lab R ecosystem. |
| Authors: | Lucas França [aut, cre] (ORCID: <https://orcid.org/0000-0003-0853-1319>), Mario Leocadio-Miguel [aut] (ORCID: <https://orcid.org/0000-0002-7248-3529>), Dafnis Batallé [aut] (ORCID: <https://orcid.org/0000-0003-2097-979X>) |
| Maintainer: | Lucas França <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.1.5 |
| Built: | 2026-10-05 08:29:34 UTC |
| Source: | https://github.com/circadia-bio/dynR |
Design and apply a zero-phase Butterworth bandpass filter to a signal,
using scipy-compatible steady-state initial conditions (equivalent to
scipy.signal.sosfiltfilt / scipy.signal.filtfilt with
padtype = "odd").
bandpass_filter(x, flp, fhi, delt, order = 2)bandpass_filter(x, flp, fhi, delt, order = 2)
x |
Numeric vector. Signal to be filtered. |
flp |
Numeric. Low-pass cutoff frequency (Hz). |
fhi |
Numeric. High-pass cutoff frequency (Hz). |
delt |
Numeric. Sampling interval in seconds (i.e. TR for fMRI). |
order |
Integer. Filter order. Default is 2. |
Two internal code paths are used depending on order:
order <= 3 (typical fMRI use): direct-form b/a coefficients with
the companion-matrix initial-condition method. scipy filtfilt-parity
validated to < 1e-9 for standard fMRI parameters.
order >= 4: second-order sections (SOS). The companion matrix for
the full-order b/a representation becomes ill-conditioned for high-order
filters with poles close to z = 1 (very low lower cutoff). SOS avoids
this by decomposing the filter into biquad sections, each with a 2x2
companion matrix that is always well-conditioned.
Filter coefficients are computed by .butter_bandpass_zpk(), a bespoke
port of scipy.signal.butter() that requires no external packages.
Numeric vector. Zero-phase filtered signal, same length as x.
set.seed(1) x <- rnorm(200) x_filt <- bandpass_filter(x, flp = 0.01, fhi = 0.1, delt = 2, order = 2)set.seed(1) x <- rnorm(200) x_filt <- bandpass_filter(x, flp = 0.01, fhi = 0.1, delt = 2, order = 2)
Apply leida_pipeline() to multiple subjects in one call. Accepts either a
named list of [N x Tmax] matrices or a 3-D array [N x Tmax x subjects].
batch_leida(data, ...)batch_leida(data, ...)
data |
Named list of [N x Tmax] numeric matrices, or a 3-D
numeric array with dimensions [N, Tmax, subjects]. For arrays, subject
names are taken from |
... |
Additional arguments passed to |
Named list of dynR_leida objects, one per subject.
stack_leida(), leida_pipeline()
set.seed(1) ts_list <- list( sub01 = matrix(rnorm(10 * 200), nrow = 10), sub02 = matrix(rnorm(10 * 200), nrow = 10) ) results <- batch_leida(ts_list, filter = FALSE) names(results)set.seed(1) ts_list <- list( sub01 = matrix(rnorm(10 * 200), nrow = 10), sub02 = matrix(rnorm(10 * 200), nrow = 10) ) results <- batch_leida(ts_list, filter = FALSE) names(results)
Apply sw_pipeline() to multiple subjects in one call. Accepts either a
named list of [N x Tmax] matrices or a 3-D array [N x Tmax x subjects].
batch_sw(data, window, ...)batch_sw(data, window, ...)
data |
Named list of [N x Tmax] matrices, or a 3-D array
[N, Tmax, subjects]. See |
window |
Integer. Window size in timepoints passed to |
... |
Additional arguments passed to |
Named list of dynR_sw objects, one per subject.
batch_leida(), sw_pipeline()
set.seed(2) ts_list <- list( sub01 = matrix(rnorm(10 * 200), nrow = 10), sub02 = matrix(rnorm(10 * 200), nrow = 10) ) results <- batch_sw(ts_list, window = 20, filter = FALSE) names(results)set.seed(2) ts_list <- list( sub01 = matrix(rnorm(10 * 200), nrow = 10), sub02 = matrix(rnorm(10 * 200), nrow = 10) ) results <- batch_sw(ts_list, window = 20, filter = FALSE) names(results)
Compute edge time series and root-sum-square (RSS) cofluctuations from z-standardised BOLD signal. Implements the edge-centric FC framework of Esfahlani et al. (2020) and Faskowitz et al. (2020).
cofluct(timeseries, k = 1)cofluct(timeseries, k = 1)
timeseries |
Numeric matrix [N × Tmax]. BOLD signal with N parcels as rows and Tmax timepoints as columns. |
k |
Integer. Upper-triangle offset. |
A list with:
edge_ts |
Numeric matrix [n_edges × Tmax]. Edge time series, one row per unique parcel pair. |
rss |
Numeric vector [Tmax]. Root-sum-square cofluctuation at each timepoint. |
Esfahlani, F. Z. et al. (2020). High-amplitude cofluctuations in cortical activity drive functional connectivity. PNAS, 117(45), 28393–28401. doi:10.1073/pnas.2005531117
Faskowitz, J. et al. (2020). Edge-centric functional network representations of human cerebral cortex reveal overlapping system-level architecture. Nature Neuroscience, 23(12), 1644–1654. doi:10.1038/s41593-020-00719-y
set.seed(1) ts <- matrix(rnorm(10 * 200), nrow = 10, ncol = 200) res <- cofluct(ts) dim(res$edge_ts) # n_edges x 200set.seed(1) ts <- matrix(rnorm(10 * 200), nrow = 10, ncol = 200) res <- cofluct(ts) dim(res$edge_ts) # n_edges x 200
Compute the correlation between edge time series across all timepoints, producing a [Tmax × Tmax] "correlation of correlations" matrix (Hansen et al., 2015).
corr_corr(timeseries, k = 1)corr_corr(timeseries, k = 1)
timeseries |
Numeric matrix [N × Tmax]. BOLD signal. |
k |
Integer. Upper-triangle offset passed to |
Numeric matrix [Tmax × Tmax].
Hansen, E. C. A. et al. (2015). Functional connectivity dynamics: Modeling the switching behavior of the resting state. NeuroImage, 105, 525–535. doi:10.1016/j.neuroimage.2014.11.001
set.seed(1) ts <- matrix(rnorm(10 * 100), nrow = 10, ncol = 100) cc <- corr_corr(ts) dim(cc) # 100 x 100set.seed(1) ts <- matrix(rnorm(10 * 100), nrow = 10, ncol = 100) cc <- corr_corr(ts) dim(cc) # 100 x 100
Compute functional connectivity matrices over sliding windows of a BOLD timeseries (Hansen et al., 2015).
corr_slide(timeseries, window, step = NULL)corr_slide(timeseries, window, step = NULL)
timeseries |
Numeric matrix [N x Tmax]. BOLD signal with N parcels as rows and Tmax timepoints as columns. |
window |
Integer. Window size in timepoints. |
step |
Integer. Step between window onsets. Defaults to |
The correlation matrices are computed by a compiled C++ backend
(corr_slide_cpp()) that calculates Pearson correlation directly on the
input matrix. No per-window submatrix allocation or transposition is
performed; the t-outer loop ordering exploits the column-major memory
layout of the input for sequential cache access.
A list with:
corr_mats |
Array [N, N, n_windows] of Pearson correlation matrices. |
idx |
Integer vector of 1-indexed window onset positions. |
Hansen, E. C. A. et al. (2015). Functional connectivity dynamics: Modeling the switching behavior of the resting state. NeuroImage, 105, 525-535. doi:10.1016/j.neuroimage.2014.11.001
set.seed(1) ts <- matrix(rnorm(10 * 200), nrow = 10, ncol = 200) res <- corr_slide(ts, window = 20) dim(res$corr_mats) # 10 x 10 x 10set.seed(1) ts <- matrix(rnorm(10 * 200), nrow = 10, ncol = 200) res <- corr_slide(ts, window = 20) dim(res$corr_mats) # 10 x 10 x 10
Compute the Euclidean distance between each consecutive pair of rows in a matrix — typically a trajectory through PC space.
do_euclid(x)do_euclid(x)
x |
Numeric matrix [n_points × n_dims]. |
Numeric vector of length nrow(x). The first element is always 0
(no previous point).
set.seed(1) pcs <- matrix(rnorm(50 * 3), nrow = 50, ncol = 3) d <- do_euclid(pcs) length(d) # 50set.seed(1) pcs <- matrix(rnorm(50 * 3), nrow = 50, ncol = 3) d <- do_euclid(pcs) length(d) # 50
Compute instantaneous phase-locking matrices from parcel-level phase time
series and extract leading eigenvectors via get_leida(). The first and
last 10 timepoints are discarded to avoid edge effects from the Hilbert
transform.
dyn_phase_lock(phases)dyn_phase_lock(phases)
phases |
Numeric matrix [N × Tmax]. Instantaneous phases in radians,
as returned by |
The phase-locking computation is accelerated by a compiled C++ backend
(dyn_phase_lock_cpp()): only the upper triangle is evaluated with
cos(phi_i - phi_j) and mirrored to the lower, halving trigonometric
operations relative to a naive double loop.
A list with:
sync_conn |
Array [N, N, Tmax-20]. Instantaneous phase-locking matrices, one per (trimmed) timepoint. |
leida |
Matrix [Tmax-20, N]. Leading eigenvectors from |
Cabral, J. et al. (2017). Cognitive performance in healthy older adults relates to spontaneous switching between states of functional connectivity during rest. Scientific Reports, 7(1), 5135. doi:10.1038/s41598-017-05425-7
Lord, L.-D. et al. (2019). Dynamical exploration of the repertoire of brain networks at rest is modulated by psilocybin. NeuroImage, 199, 127-142. doi:10.1016/j.neuroimage.2019.05.060
set.seed(1) ts <- matrix(rnorm(10 * 200), nrow = 10, ncol = 200) phases <- hilbert_phases(ts) res <- dyn_phase_lock(phases) dim(res$sync_conn) # 10 x 10 x 180 dim(res$leida) # 180 x 10set.seed(1) ts <- matrix(rnorm(10 * 200), nrow = 10, ncol = 200) phases <- hilbert_phases(ts) res <- dyn_phase_lock(phases) dim(res$sync_conn) # 10 x 10 x 180 dim(res$leida) # 180 x 10
From a long-format data frame of cluster labels ordered in time, compute first-order Markov transition probabilities between brain states: for each source state, the fraction of transitions that lead to each target state.
dyn_transitions(tbl, vars, cVar, sortBy, groupBy, remIntra = FALSE)dyn_transitions(tbl, vars, cVar, sortBy, groupBy, remIntra = FALSE)
tbl |
A data frame in long format (one row per timepoint). |
vars |
Character vector of grouping / covariate column names to
preserve in the output (e.g. |
cVar |
Character. Name of the column holding integer cluster labels. |
sortBy |
Character vector of column names used to sort rows within each
group before transitions are computed (typically |
groupBy |
Character vector of column names that define independent
sequences (typically |
remIntra |
Logical. If |
Ported from clusters_markov() in the neonatal_dfc analysis pipeline
(França et al., Nat Commun).
A nested tibble with columns tag, source, target, and data.
tag encodes the transition as "<source>_<target>". Each data
element is a per-group tibble with columns inherited from vars plus:
n |
Raw transition count. |
tot |
Total transitions out of |
nCount |
Transition probability ( |
set.seed(1) df <- data.frame( sub = rep(c("A", "B"), each = 50), ses = 1L, ttime = rep(seq_len(50), 2), clus4 = sample(1:4, 100, replace = TRUE) ) tr <- dyn_transitions( df, vars = c("sub", "ses"), cVar = "clus4", sortBy = c("sub", "ses", "ttime"), groupBy = c("sub", "ses") ) trset.seed(1) df <- data.frame( sub = rep(c("A", "B"), each = 50), ses = 1L, ttime = rep(seq_len(50), 2), clus4 = sample(1:4, 100, replace = TRUE) ) tr <- dyn_transitions( df, vars = c("sub", "ses"), cVar = "clus4", sortBy = c("sub", "ses", "ttime"), groupBy = c("sub", "ses") ) tr
Static functional connectivity matrix derived from ts by computing the full-timeseries Pearson correlation across all 200 parcel pairs. Serves as a ground-truth reference for validating sliding-window and phase-based dynFC methods when the window spans the full timeseries.
fcfc
A numeric matrix with 200 rows and 200 columns. Diagonal is 1; off-diagonal values are Pearson correlations in [-1, 1].
Derived from ts.
Extract the leading eigenvector from a series of instantaneous phase-locking matrices. The sign of each eigenvector is normalised so that its sum is non-positive, following the LEiDA convention.
get_leida(sync_conn)get_leida(sync_conn)
sync_conn |
Numeric array [N, N, Tmax]. Instantaneous phase-locking
matrices, as returned by |
The computation is accelerated by a compiled C++ / LAPACK backend
(get_leida_cpp()): LAPACK dsyev is called once per timepoint with a
single shared workspace allocation, and only the leading eigenvector
(last column of the ascending-order output) is retained.
Numeric matrix [Tmax x N]. Leading eigenvectors, one per timepoint.
Cabral, J. et al. (2017). Cognitive performance in healthy older adults relates to spontaneous switching between states of functional connectivity during rest. Scientific Reports, 7(1), 5135. doi:10.1038/s41598-017-05425-7
Lord, L.-D. et al. (2019). Dynamical exploration of the repertoire of brain networks at rest is modulated by psilocybin. NeuroImage, 199, 127-142. doi:10.1016/j.neuroimage.2019.05.060
Compute the instantaneous phase time series for all parcels/voxels via the analytic signal (Hilbert transform). Each parcel timeseries is demeaned before transformation.
hilbert_phases(timeseries)hilbert_phases(timeseries)
timeseries |
Numeric matrix [N x Tmax]. BOLD signal with N parcels as rows and Tmax timepoints as columns. |
All N parcels are processed in two vectorised calls to mvfft() rather
than an N-iteration R loop over fft(): the timeseries matrix is transposed
to a Tmax x N layout so mvfft applies the FFT to each parcel column
simultaneously, the Hilbert multiplier is broadcast across columns, and
the inverse FFT recovers the analytic signal for all parcels at once.
.hilbert_r() is retained as an internal single-vector reference
(scipy-parity validated).
Numeric matrix [N x Tmax]. Instantaneous phases in radians.
Cabral, J. et al. (2017). Cognitive performance in healthy older adults relates to spontaneous switching between states of functional connectivity during rest. Scientific Reports, 7(1), 5135. doi:10.1038/s41598-017-05425-7
set.seed(1) ts <- matrix(rnorm(10 * 200), nrow = 10, ncol = 200) phases <- hilbert_phases(ts) dim(phases) # 10 x 200set.seed(1) ts <- matrix(rnorm(10 * 200), nrow = 10, ncol = 200) phases <- hilbert_phases(ts) dim(phases) # 10 x 200
Compute the global Kuramoto order parameter time series, the metastability
index (standard deviation of the order parameter), and Shannon entropy of
synchrony from parcel-level instantaneous phase time series.
The first and last 10 timepoints are discarded (matching dyn_phase_lock()).
kuramoto(phases, base = 2, n_bits = 8L)kuramoto(phases, base = 2, n_bits = 8L)
phases |
Numeric matrix [N x Tmax]. Instantaneous phases in radians,
as returned by |
base |
Numeric. Logarithm base for Shannon entropy. Default is 2. |
n_bits |
Integer or |
The synchrony time series is computed by a compiled C++ backend
(kuramoto_sync_cpp()) that accumulates cos and sin components directly,
avoiding R complex-number allocation and vapply dispatch overhead.
A list with:
metastability |
Numeric scalar. Standard deviation of the Kuramoto order parameter. |
synchrony |
Numeric vector [Tmax-20]. Kuramoto order parameter at each (trimmed) timepoint. |
entropy |
Numeric scalar. Shannon entropy of the synchrony series. |
set.seed(1) ts <- matrix(rnorm(10 * 200), nrow = 10, ncol = 200) phases <- hilbert_phases(ts) res <- kuramoto(phases) res$metastabilityset.seed(1) ts <- matrix(rnorm(10 * 200), nrow = 10, ncol = 200) phases <- hilbert_phases(ts) res <- kuramoto(phases) res$metastability
Convenience wrapper running the full phase-based dynamic FC pipeline:
optional Butterworth bandpass filter -> Hilbert transform ->
dynamic phase-locking matrices + LEiDA eigenvectors -> Kuramoto order
parameter. Returns a structured dynR_leida object with print() and
plot() methods.
leida_pipeline( timeseries, flp = NULL, fhi = NULL, delt = NULL, order = 2L, filter = TRUE )leida_pipeline( timeseries, flp = NULL, fhi = NULL, delt = NULL, order = 2L, filter = TRUE )
timeseries |
Numeric matrix [N x Tmax]. Rows = channels/parcels, columns = timepoints. |
flp |
Numeric. Low-pass cutoff frequency (Hz). No default — must be
set explicitly when |
fhi |
Numeric. High-pass cutoff frequency (Hz). No default — must be
set explicitly when |
delt |
Numeric. Sampling interval in seconds ( |
order |
Integer. Butterworth filter order. Default |
filter |
Logical. Apply bandpass filter before phase extraction?
Default |
dynR is modality-agnostic. flp, fhi, and delt have no defaults and
must be supplied when filter = TRUE. Set them for your recording
modality (see examples). Pass filter = FALSE if the timeseries is already
band-limited.
An object of class dynR_leida (a named list) with elements:
leida |
Matrix [Tmax-20, N]. LEiDA eigenvectors. |
sync_conn |
Array [N, N, Tmax-20]. Instantaneous phase-locking matrices. |
phases |
Matrix [N, Tmax]. Instantaneous phases in radians. |
synchrony |
Numeric vector [Tmax-20]. Kuramoto R(t). |
metastability |
Numeric. Standard deviation of synchrony. |
entropy |
Numeric. Shannon entropy of synchrony series (bits). |
N |
Integer. Number of channels/parcels. |
Tmax |
Integer. Number of timepoints. |
sw_pipeline(), dyn_phase_lock(), kuramoto(), plot.dynR_leida()
set.seed(1) ts <- matrix(rnorm(10 * 200), nrow = 10) # filter = FALSE: timeseries already band-limited res <- leida_pipeline(ts, filter = FALSE) res # fMRI BOLD (TR = 2 s) ## Not run: res <- leida_pipeline(ts, flp = 0.01, fhi = 0.1, delt = 2) ## End(Not run) # EEG alpha band (250 Hz) ## Not run: res <- leida_pipeline(ts, flp = 8, fhi = 12, delt = 1 / 250) ## End(Not run)set.seed(1) ts <- matrix(rnorm(10 * 200), nrow = 10) # filter = FALSE: timeseries already band-limited res <- leida_pipeline(ts, filter = FALSE) res # fMRI BOLD (TR = 2 s) ## Not run: res <- leida_pipeline(ts, flp = 0.01, fhi = 0.1, delt = 2) ## End(Not run) # EEG alpha band (250 Hz) ## Not run: res <- leida_pipeline(ts, flp = 8, fhi = 12, delt = 1 / 250) ## End(Not run)
Render a square correlation or phase-locking matrix as a heatmap using the dynR diverging palette (deep indigo -> periwinkle -> brick red), centred at zero. Matches the colour scheme used in the dynR vignettes and pkgdown site.
plot_fc(fc_matrix, title = "Functional connectivity", limits = c(-1, 1))plot_fc(fc_matrix, title = "Functional connectivity", limits = c(-1, 1))
fc_matrix |
Numeric matrix [N x N]. Pearson correlations or phase-locking values. |
title |
Character. Plot title. Default |
limits |
Numeric vector |
A ggplot object.
data(fc, package = "dynR") plot_fc(fc[1:20, 1:20])data(fc, package = "dynR") plot_fc(fc[1:20, 1:20])
Tile plot of brain state labels over time (or windows), coloured with the dynR state palette (periwinkle, brick red, mauve, deep indigo, dusty rose).
plot_state_sequence( states, x_label = "Timepoint", title = "Brain state sequence", palette = NULL )plot_state_sequence( states, x_label = "Timepoint", title = "Brain state sequence", palette = NULL )
states |
Integer or factor vector of state labels. |
x_label |
Character. x-axis label. Default |
title |
Character. Plot title. Default |
palette |
Character vector of colours. Defaults to the dynR 5-colour
state palette, recycled if |
A ggplot object.
set.seed(1) states <- sample(1:4, 100, replace = TRUE) plot_state_sequence(states)set.seed(1) states <- sample(1:4, 100, replace = TRUE) plot_state_sequence(states)
Line plot of the Kuramoto order parameter R(t) over time, with a dashed horizontal line at the mean. Uses the dynR periwinkle/brick-red palette.
plot_synchrony(synchrony, title = "Kuramoto order parameter")plot_synchrony(synchrony, title = "Kuramoto order parameter")
synchrony |
Numeric vector. Kuramoto R(t), as returned by |
title |
Character. Plot title. |
A ggplot object.
set.seed(1) ts <- matrix(rnorm(10 * 200), nrow = 10) ph <- hilbert_phases(ts) kop <- kuramoto(ph) plot_synchrony(kop$synchrony)set.seed(1) ts <- matrix(rnorm(10 * 200), nrow = 10) ph <- hilbert_phases(ts) kop <- kuramoto(ph) plot_synchrony(kop$synchrony)
Plot method for dynR_leida objects
## S3 method for class 'dynR_leida' plot(x, type = c("synchrony", "fc"), ...)## S3 method for class 'dynR_leida' plot(x, type = c("synchrony", "fc"), ...)
x |
A |
type |
Character. |
... |
Additional arguments passed to the underlying plot function. |
A ggplot object.
Plot method for dynR_sw objects
## S3 method for class 'dynR_sw' plot(x, type = c("rss", "fc"), ...)## S3 method for class 'dynR_sw' plot(x, type = c("rss", "fc"), ...)
x |
A |
type |
Character. |
... |
Additional arguments passed to the underlying plot function. |
A ggplot object.
Estimate Shannon entropy from a numeric vector, with optional
bit-depth discretisation (as used internally by kuramoto()).
shannon_entropy(x, base = 2, n_bits = NULL)shannon_entropy(x, base = 2, n_bits = NULL)
x |
Numeric vector. |
base |
Numeric. Logarithm base. Default is 2 (entropy in bits). |
n_bits |
Integer or |
Numeric scalar. Shannon entropy.
x <- sample(1:4, 100, replace = TRUE) shannon_entropy(x)x <- sample(1:4, 100, replace = TRUE) shannon_entropy(x)
Combine the LEiDA eigenvector matrices from a list of dynR_leida results
into a single matrix (or data frame) ready for cross-subject K-means
clustering.
stack_leida(batch_result, add_subject_id = TRUE)stack_leida(batch_result, add_subject_id = TRUE)
batch_result |
Named list of |
add_subject_id |
Logical. Prepend a |
If add_subject_id = TRUE: a data frame with columns subject and
one column per parcel (named V1, V2, ...).
If FALSE: a plain numeric matrix [total_timepoints x N].
batch_leida()
set.seed(3) ts_list <- list( sub01 = matrix(rnorm(10 * 200), nrow = 10), sub02 = matrix(rnorm(10 * 200), nrow = 10) ) results <- batch_leida(ts_list, filter = FALSE) leida_all <- stack_leida(results) dim(leida_all)set.seed(3) ts_list <- list( sub01 = matrix(rnorm(10 * 200), nrow = 10), sub02 = matrix(rnorm(10 * 200), nrow = 10) ) results <- batch_leida(ts_list, filter = FALSE) leida_all <- stack_leida(results) dim(leida_all)
Combine the Kuramoto synchrony time series from a list of dynR_leida
results into a tidy data frame with one row per timepoint per subject.
stack_synchrony(batch_result)stack_synchrony(batch_result)
batch_result |
Named list of |
A data frame with columns:
subject |
Subject identifier. |
timepoint |
Timepoint index (within subject). |
synchrony |
Kuramoto R(t). |
metastability |
Subject-level metastability (constant within subject). |
batch_leida()
set.seed(4) ts_list <- list( sub01 = matrix(rnorm(10 * 200), nrow = 10), sub02 = matrix(rnorm(10 * 200), nrow = 10) ) results <- batch_leida(ts_list, filter = FALSE) df_sync <- stack_synchrony(results) head(df_sync)set.seed(4) ts_list <- list( sub01 = matrix(rnorm(10 * 200), nrow = 10), sub02 = matrix(rnorm(10 * 200), nrow = 10) ) results <- batch_leida(ts_list, filter = FALSE) df_sync <- stack_synchrony(results) head(df_sync)
Convenience wrapper running the full correlation-based dynamic FC pipeline:
optional Butterworth bandpass filter -> sliding-window Pearson correlation
matrices -> edge-centric cofluctuations. Returns a structured dynR_sw
object with print() and plot() methods.
sw_pipeline( timeseries, window, step = NULL, flp = NULL, fhi = NULL, delt = NULL, order = 2L, filter = TRUE )sw_pipeline( timeseries, window, step = NULL, flp = NULL, fhi = NULL, delt = NULL, order = 2L, filter = TRUE )
timeseries |
Numeric matrix [N x Tmax]. |
window |
Integer. Window size in timepoints. |
step |
Integer. Step between window onsets. Default: |
flp |
Numeric. Low-pass cutoff (Hz). No default — required when
|
fhi |
Numeric. High-pass cutoff (Hz). No default — required when
|
delt |
Numeric. Sampling interval in seconds. No default — required
when |
order |
Integer. Butterworth filter order. Default |
filter |
Logical. Apply bandpass filter? Default |
dynR is modality-agnostic. flp, fhi, and delt have no defaults and
must be supplied when filter = TRUE. Pass filter = FALSE if the
timeseries is already band-limited.
An object of class dynR_sw (a named list) with elements:
corr_mats |
Array [N, N, n_windows]. Sliding FC matrices. |
idx |
Integer vector. 1-indexed window onset positions. |
edge_ts |
Matrix [n_edges, Tmax]. Edge time series. |
rss |
Numeric vector [Tmax]. Root-sum-square cofluctuation. |
window |
Integer. Window size used. |
step |
Integer. Step size used. |
N |
Integer. Number of channels/parcels. |
Tmax |
Integer. Number of timepoints. |
leida_pipeline(), corr_slide(), cofluct(), plot.dynR_sw()
set.seed(1) ts <- matrix(rnorm(10 * 200), nrow = 10) # filter = FALSE: timeseries already band-limited res <- sw_pipeline(ts, window = 20, filter = FALSE) res # fMRI BOLD (TR = 2 s) ## Not run: res <- sw_pipeline(ts, window = 20, flp = 0.01, fhi = 0.1, delt = 2) ## End(Not run)set.seed(1) ts <- matrix(rnorm(10 * 200), nrow = 10) # filter = FALSE: timeseries already band-limited res <- sw_pipeline(ts, window = 20, filter = FALSE) res # fMRI BOLD (TR = 2 s) ## Not run: res <- sw_pipeline(ts, window = 20, flp = 0.01, fhi = 0.1, delt = 2) ## End(Not run)
A resting-state BOLD fMRI timeseries from the edge-ts repository, parcellated into 200 regions of interest. Used in dynR vignettes and examples to demonstrate dynamic FC methods on realistic data.
tsts
A numeric matrix with 200 rows (parcels) and 600 columns (timepoints).
https://github.com/brain-networks/edge-ts