| Title: | Complex Dynamic Systems |
| Version: | 0.1.0 |
| Description: | Performs analysis of complex dynamic systems with a focus on the temporal unfolding of patterns, changes, and state transitions in behavioral data. Supports both time series and sequence data and provides tools for the analysis and visualization of complexity, pattern identification, trends, regimes, sequence typology as well as early warning signals. |
| License: | MIT + file LICENSE |
| URL: | https://github.com/santikka/codyna/ |
| BugReports: | https://github.com/santikka/codyna/issues/ |
| Depends: | R (≥ 4.1.0) |
| Imports: | checkmate, cli, dplyr, ggplot2, patchwork, rlang, stats, tibble, tidyr, tidyselect |
| Suggests: | knitr, rmarkdown, testthat (≥ 3.0.0) |
| VignetteBuilder: | knitr |
| Config/testthat/edition: | 3 |
| Encoding: | UTF-8 |
| RoxygenNote: | 7.3.3 |
| LazyData: | true |
| NeedsCompilation: | no |
| Packaged: | 2026-01-11 13:47:25 UTC; Santtu |
| Author: | Santtu Tikka [aut, cre], Mohammed Saqr [aut] |
| Maintainer: | Santtu Tikka <santtuth@gmail.com> |
| Repository: | CRAN |
| Date/Publication: | 2026-01-16 11:00:13 UTC |
The codyna Package.
Description
Performs analysis of complex dynamic systems with a focus on the temporal unfolding of patterns, changes, and state transitions in behavioral data. The package supports both time series and sequence data and provides tools for the analysis and visualization of complexity, pattern identification, trends, regimes, sequence typology as well as early warning signals.
Author(s)
Santtu Tikka and Mohammed Saqr
See Also
Useful links:
Calculate Dynamic Complexity Measures for Time-Series Data
Description
Computes dynamic complexity and other rolling window measures for univariate time series data.
Usage
complexity(data, measures = "complexity", window = 7L, align = "center")
Arguments
data |
[ |
measures |
[ |
window |
[ |
align |
[ |
Details
The following measures can be calculated:
-
"complexity": Product of fluctuation and distribution measures. -
"fluctuation": Root mean square of successive differences. -
"distribution": Deviation from uniform distribution. -
"autocorrelation": Lag-1 autocorrelation coefficient. -
"max": Rolling maximum. -
"min": Rolling minimum. -
"variance": Rolling variance.
The option "all" computes all of the above.
Value
A tibble with the time index, the original time-series data,
and the calculated measures.
Examples
set.seed(123)
ts_data <- stats::arima.sim(list(order = c(1, 1, 0), ar = 0.6), n = 200)
# Single measure
comp_single <- complexity(ts_data, measures = "complexity")
# Multiple measures
comp_multi <- complexity(ts_data, measures = c("complexity", "variance"))
Convert Sequence Data to Various Formats
Description
Converts wide format sequence data into useful formats for analysis, such as frequency table, one-Hot encoding, or edge list (graph format).
Usage
convert(data, cols, format = "frequency")
Arguments
data |
[ |
cols |
[ |
format |
[
|
Value
A tibble structured according to the requested format.
Examples
convert(engagement, format = "frequency")
convert(engagement, format = "onehot")
convert(engagement, format = "edgelist")
convert(engagement, format = "reverse")
Regime Detection for Time Series Data
Description
Detects regime changes in time series data using multiple methods including cumulative peaks, changepoint detection, variance shifts, threshold analysis, gradient changes, and entropy analysis.
Usage
detect_regimes(
data,
method = "smart",
sensitivity = "medium",
min_change,
window = 10,
peak = 2,
cumulative = 0.6
)
Arguments
data |
[ |
method |
[
|
sensitivity |
[ |
min_change |
[ |
window |
[ |
peak |
[ |
cumulative |
[ |
Value
An object of class regimes which is a tibble containing
the following columns:
value: Original time series data.
time: Original time points.
change: A logical vector indicating regime changes.
id: An integer regime identifier.
type: Type of change detected by the method.
magnitude: Magnitude of the change (method-specific interpretation)
confidence: Confidence in the detection
(method-specific interpretation, typically between 0 and 1, or NA)
stability: Categorical stability: "Stable", "Transitional", and
"Unstable".
score: A numeric stability score between 0 and 1.
Examples
set.seed(123)
ts_data <- stats::arima.sim(list(order = c(1, 1, 0), ar = 0.6), n = 200)
regimes <- detect_regimes(
data = ts_data,
method = "threshold",
sensitivity = "medium"
)
Detect Early Warning Signals in a Time Series
Description
Detect Early Warning Signals in a Time Series
Usage
detect_warnings(
data,
method = "rolling",
metrics = "all",
window = 0.5,
burnin = 0.1,
demean = TRUE,
detrend = "none",
threshold = 2,
consecutive = 2L,
bandwidth,
span,
degree
)
Arguments
data |
[ |
method |
[ |
metrics |
[
|
window |
[ |
burnin |
[ |
demean |
[ |
detrend |
[
|
threshold |
[ |
consecutive |
[ |
bandwidth |
See |
span |
See |
degree |
See |
Value
An object of class ews containing the EWS results as a tibble.
Examples
set.seed(123)
ts_data <- stats::arima.sim(list(order = c(1, 1, 0), ar = 0.6), n = 200)
# Rolling window (default)
ews_roll <- detect_warnings(ts_data)
# Expanding window
ews_exp <- detect_warnings(ts_data, method = "expanding")
Discover Sequence Patterns
Description
Discovering various types of patterns in sequence data. Provides n-gram extraction, gapped pattern discovery, analysis of repeated patterns and targeted pattern search.
Usage
discover_patterns(
data,
type = "ngram",
pattern,
len = 2:5,
gap = 1:3,
min_support = 0.01,
min_count = 2,
start,
end,
contains
)
Arguments
data |
[ |
type |
[
|
pattern |
[ |
len |
[ |
gap |
[ |
min_support |
[ |
min_count |
[ |
start |
[ |
end |
[ |
contains |
[ |
Value
A tibble containing the discover patterns, counts, proportions,
and support.
Examples
# N-grams
ngrams <- discover_patterns(engagement, type = "ngram")
# Gapped patterns
gapped <- discover_patterns(engagement, type = "gapped")
# Repeated patterns
repeated <- discover_patterns(engagement, type = "repeated")
# Custom pattern with a wildcard state
custom <- discover_patterns(engagement, pattern = "Active->*")
Ecological Momentary Assessment (EMA) Data
Description
Example data for complex adaptive systems perspective to behavior change research. The dataset consists of 20 individuals with 9 self-report variables (and time of response) each. For more information on the data, please see https://heinonmatti.github.io/complexity-behchange/dataset-info.html
Usage
ema
Format
A data.frame object.
Source
https://github.com/heinonmatti/complexity-behchange
Example Data on Student Engagement
Description
Students' engagement states (Active / Average / Disengaged)
throughout a whole study program. The data was generated synthetically
based on the article "The longitudinal association between engagement and
achievement varies by time, students' profiles, and achievement state:
A full program study". Used also in the tna package.
Usage
engagement
Format
An stslist object (sequence data).
Source
doi:10.1016/j.compedu.2023.104787
References
Tikka S, López-Pernas S, Saqr M (2025). "tna: An R Package for Transition Network Analysis." Applied Psychological Measurement. doi:10.1177/01466216251348840
Example Data on Group Regulation
Description
Students' regulation during collaborative learning. Students' interactions
were coded as: "adapt", "cohesion", "consensus", "coregulate", "discuss",
"emotion", "monitor", "plan", "synthesis". Used also in the tna package.
Usage
group_regulation
Format
A data.frame object.
Source
The data was generated synthetically.
References
Tikka S, López-Pernas S, Saqr M (2025). "tna: An R Package for Transition Network Analysis." Applied Psychological Measurement. doi:10.1177/01466216251348840
Plot EWS Results
Description
Plot EWS Results
Usage
## S3 method for class 'ews'
plot(x, ...)
Arguments
x |
[ |
... |
Ignored. |
Value
A ggplot object.
Examples
set.seed(123)
ts_data <- stats::arima.sim(list(order = c(1, 1, 0), ar = 0.6), n = 200)
ews_roll <- detect_warnings(ts_data)
plot(ews_roll)
Plot Time Series Data with Detected Regime Stability
Description
Plot Time Series Data with Detected Regime Stability
Usage
## S3 method for class 'regimes'
plot(x, points = FALSE, ...)
Arguments
x |
[ |
points |
[ |
... |
Ignored. |
Value
A ggplot object.
Examples
set.seed(123)
ts_data <- stats::arima.sim(list(order = c(1, 1, 0), ar = 0.6), n = 200)
regimes <- detect_regimes(
data = ts_data,
method = "threshold",
sensitivity = "medium"
)
plot(regimes)
Print EWS Detection Results
Description
Print EWS Detection Results
Usage
## S3 method for class 'ews'
print(x, ...)
Arguments
x |
[ |
... |
Additional arguments passed to the generic print method. |
Value
x (invisibly).
Examples
set.seed(123)
ts_data <- stats::arima.sim(list(order = c(1, 1, 0), ar = 0.6), n = 200)
ews <- detect_warnings(ts_data)
print(ews)
Print Regime Detection Results
Description
Print Regime Detection Results
Usage
## S3 method for class 'regimes'
print(x, ...)
Arguments
x |
[ |
... |
Additional arguments passed to the generic print method. |
Value
x (invisibly).
Examples
set.seed(123)
ts_data <- stats::arima.sim(list(order = c(1, 1, 0), ar = 0.6), n = 200)
regimes <- detect_regimes(
data = ts_data,
method = "threshold",
sensitivity = "medium"
)
print(regimes)
Compute Sequence Indices for Sequence Data
Description
Compute Sequence Indices for Sequence Data
Usage
sequence_indices(data, cols, favorable, omega = 1)
Arguments
data |
[ |
cols |
[ |
favorable |
[ |
omega |
[ |
Value
A tibble containing the index values.
Examples
sequence_indices(engagement)