Learn R Programming

codyna (version 0.1.0)

detect_regimes: 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
)

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.

Arguments

data

[ts, numeric()]
Univariate time series data.

method

[character(1)]
Detection method. The available options are:

  • "cumulative_peaks": Detects cumulative complexity peaks using Z-tests.

  • "changepoint": Change point detection (multi-window mean-shift test).

  • "threshold": Adaptive quartile-based regime classification.

  • "variance_shift": Detects changes in variance patterns.

  • "slope": Detects changes in local slope (rolling linear models).

  • "entropy": Detects changes in the Shannon entropy of the complexity series, calculated in rolling windows.

  • "smart" (default): Combines gradient, peaks, and changepoint methods.

  • "all": Applies all individual methods listed above and uses ensemble voting.

sensitivity

[character(1)]
Detection sensitivity level. The available options are: "low", "medium", "high". The default is "medium". This affects thresholds and window sizes within the detection methods.

min_change

[integer(1)]
Minimum number of observations between changes. If missing (default), the value is determined automatically (typically 10% of observations, minimum of 10).

window

[integer(1)]
base window size for rolling calculations. This is further adjusted by sensitivity. The default is 10.

peak

[numeric(1)]
Base z-score threshold for individual peak detection with the "cumulative_peaks" method. Adjusted by sensitivity. The default is 2.0.

cumulative

[numeric(1)]
A value between 0 and 1 that defines the base proportion threshold for identifying cumulative peak regions. Adjusted by sensitivity. The default is 0.6.

Examples

Run this code
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"
)

Run the code above in your browser using DataLab