dynR
Dynamic connectivity analysis for neurophysiological timeseries in R
About
dynR computes dynFC representations from preprocessed multivariate timeseries, providing the upstream computation layer for dynamic connectivity analysis. It is a full R port of the Python dynfc library, motivated by reproducibility: R + renv provides a more stable long-term environment than Python dependency chains for research pipelines.
Although the bundled example data and several vignettes use BOLD fMRI, all methods are applicable to any band-limited neurophysiological signal where phase relationships or pairwise correlations carry meaningful information — including EEG, LFP, and MEG.
The outputs of dynR feed directly into stateR for brain state quantification (fractional occupancy, dwell time, Markov transitions).
Pipeline Position
Multivariate timeseries [N × Tmax]
│
▼
dynR ← this package
(dynFC representations)
│
▼
stateR
(brain state metrics: FO, dwell time, Markov transitions)
Quick Example
library(dynR)
# Simulated timeseries: 80 channels, 300 timepoints
set.seed(42)
ts <- matrix(rnorm(80 * 300), nrow = 80, ncol = 300)
# 1. Bandpass filter (e.g. fMRI: TR = 2 s, 0.01–0.1 Hz)
ts_filt <- apply(ts, 1, bandpass_filter, flp = 0.01, fhi = 0.1, delt = 2)
ts_filt <- t(ts_filt)
# 2. Phase-based: LEiDA + Kuramoto
phases <- hilbert_phases(ts_filt)
dpl <- dyn_phase_lock(phases) # dpl$leida: [280 × 80] LEiDA eigenvectors
kop <- kuramoto(phases) # kop$metastability, kop$entropy
# 3. Cluster LEiDA vectors → feed into stateR
km <- kmeans(dpl$leida, centers = 5, nstart = 100)
# 4. Correlation-based: sliding-window FC + cofluctuations
sw <- corr_slide(ts_filt, window = 30, step = 5)
ec <- cofluct(ts_filt) # ec$edge_ts, ec$rssFeatures
| Function | Description |
|---|---|
hilbert_phases() |
Instantaneous phase extraction via the analytic signal |
dyn_phase_lock() |
Dynamic phase-locking matrices (dPL) + LEiDA eigenvectors |
get_leida() |
Leading eigenvector decomposition (LEiDA) |
kuramoto() |
Kuramoto order parameter, metastability, Shannon entropy |
corr_slide() |
Sliding-window Pearson correlation matrices |
cofluct() |
Edge-centric cofluctuation time series + RSS |
corr_corr() |
Correlation-of-correlations (FC recurrence) matrix |
bandpass_filter() |
Zero-phase Butterworth bandpass filter |
shannon_entropy() |
Shannon entropy with optional bit-depth discretisation |
dyn_transitions() |
First-order Markov transition probabilities between brain states |
All timeseries inputs follow the [N, Tmax] convention (rows = channels/parcels, columns = timepoints), matching the original Python dynfc package.
Status
dynR is in early development. The API may change without notice, estimation results have not yet been validated against a reference implementation, and the package has not undergone peer review. Use with caution and verify outputs independently before using in any research context.
Links
- 🌐 Documentation
- 💻 GitHub
- 🧪 stateR — brain state metrics, consumes dynR output
- 🕐 zeitR — wrist actigraphy analysis