Computes standard Recurrence Quantification Analysis (RQA) measures from a multivariate state-space embedding, separately for each participant.
RQA characterises the temporal organisation of a dynamical system by
examining how often and in what patterns the system revisits previous states.
The function accepts output from make_statespace() directly — each row of
the embedded matrix is treated as a point in the reconstructed state space.
When multiple subseries exist per participant (e.g., from overnight breaks
detected by resample_timeseries()), RQA is first computed within each
subseries and then averaged to yield participant-level estimates.
Usage
compute_rqa(
data,
r = 1,
min_diag = 2L,
min_vert = 2L,
participant_col = "ID",
series_col = "Series_ID",
time_col = "time",
verbose = TRUE
)Arguments
- data
An
experdyn_statespaceobject returned bymake_statespace(), or a data frame containing lagged columns named*_lag0,*_lag1, etc.- r
[numeric(1): 1.0]
Euclidean distance threshold for the recurrence matrix. Data are z-scored within each subseries before distances are computed, soris on a standardised scale.- min_diag
[integer(1): 2]
Minimum diagonal line length included in DET, L, and ENTR calculations.- min_vert
[integer(1): 2]
Minimum vertical line length included in LAM and TT calculations.- participant_col
[character(1): "ID"]
Participant identifier column.- series_col
[character(1): "Series_ID"]
Subseries identifier column.- time_col
[character(1): "time"]
Optional time column used for ordering within subseries.- verbose
[logical(1): TRUE]
IfTRUE, prints a short completion summary.
Value
An object of class experdyn_rqa — a named list with:
| Element | Description |
participant_rqa | One row per participant with cross-series mean RQA measures. |
series_rqa | One row per participant-subseries with per-series RQA measures. |
recurrence_data | Sparse data frame of recurrence point coordinates for plotting. |
r | Matching tolerance used. |
min_diag | Minimum diagonal line length used. |
min_vert | Minimum vertical line length used. |
RQA measures (columns in participant_rqa and series_rqa):
| Measure | Description |
RR | Recurrence Rate — proportion of recurrent points. |
DET | Determinism — proportion of recurrences forming diagonal lines ≥ min_diag. |
L | Mean diagonal line length. |
Lmax | Longest diagonal line. |
ENTR | Shannon entropy of diagonal line length distribution. |
LAM | Laminarity — proportion of recurrences forming vertical lines ≥ min_vert. |
TT | Trapping Time — mean vertical line length. |
Vmax | Longest vertical line. |
See also
make_statespace()for building the embedding passed to this function.plot_rqa()for visualising the recurrence structure.compute_mvsampen()for sample entropy, a complementary complexity measure.
Examples
set.seed(1)
n <- 30
t_obs <- as.POSIXct("2025-01-01 09:00:00") +
cumsum(sample(60 * c(60, 90), n, replace = TRUE))
df <- data.frame(
time = t_obs,
Component_1 = cumsum(rnorm(n)),
Component_2 = cumsum(rnorm(n))
)
rs <- resample_timeseries(df, time_col = "time", verbose = FALSE, plot = FALSE)
ss <- make_statespace(rs)
rqa <- compute_rqa(ss, r = 1.2, verbose = FALSE)
rqa
#> ===== Recurrence Quantification Analysis =====
#> Tolerance (r) : 1.200
#> Min diagonal (min_diag): 2
#> Min vertical (min_vert): 2
#> Participants : 1
#> Series : 1
#>
#> ID n_series n_series_valid RR DET L Lmax ENTR LAM TT Vmax
#> All 1 1 0.109 0.754 2.875 7 1.127 0.582 2.84 6
#>
#> Per-series results : use `$series_rqa`
#> Recurrence data : use `$recurrence_data` (for custom plots)
#> ===============================================
