Learn R Programming

codyna (version 0.1.0)

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

Value

An object of class ews containing the EWS results as a tibble.

Arguments

data

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

method

[character(1)]
Name of the analysis method. Either "rolling" or "expanding" for rolling window and expanding window, respectively.

metrics

[character(1)]
Names of the EWS metrics to compute. The default is "all" computing all metrics. The available options are:

  • "ar1": The autoregressive coefficient of an AR1 model.

  • "sd": Standard deviation.

  • "skew": Skewness.

  • "kurt": Kurtosis.

  • "cv": Coefficient of variation.

  • "rr": Return rate (1 - ar1).

  • "all": All of the above.

window

[numeric(1)]
Window size as a proportion of the total series length (default 0.5).

burnin

[numeric(1)]
Burn-in period as a proportion of the total series length (default 0.1).

demean

[logical(1)]
Should the time series be demeaned before analysis? If TRUE (the default), the "ar1" metric will be based on an AR1 model where the mean of the observations is first subtracted. See stats::ar.ols() for details.

detrend

[character(1)]
Name of the detrending method to apply to the time series data before computing the metrics. The default is "none" for no detrending. The available options are:

  • "gaussian": Estimates a smooth curve via kernel-based regression using stats::ksmooth() with a Gaussian kernel which is then subtracted from the time series.

  • "loess": Estimates a smooth curve via local polynomial regression using stats::loess() which is then subtracted from the time series.

  • "linear": Fits a linear regression model via stats::lm() and uses the residuals for computing the metrics.

  • "first-diff": Uses the differences between the time series and its first-order lagged values.

  • "none": Use the original time series data.

threshold

[numeric(1)]
The z-score threshold value for the expanding window method. The default is 2.0.

consecutive

[integer(1)]
The number of times the threshold has to be crossed consecutively to be counted as a detection. The default is 2.

bandwidth

See stats::ksmooth().

span

See stats::loess().

degree

See stats::loess().

Examples

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

Run the code above in your browser using DataLab