Learn R Programming

RegimeChange (version 0.1.1)

detect_pelt: Detect changepoints using enhanced PELT algorithm

Description

Pruned Exact Linear Time (PELT) algorithm for optimal changepoint detection with enhancements for autocorrelated data and numerical stability.

Usage

detect_pelt(
  data,
  type = "both",
  penalty = "MBIC",
  min_segment = 2,
  robust = FALSE,
  correct_ar = FALSE,
  merge_close = NULL,
  ...
)

Value

A list with components:

changepoints

Integer vector of detected changepoint locations

n_changepoints

Number of changepoints detected

cost

Final cost value

ar_coefficient

Estimated AR(1) coefficient (if correct_ar = TRUE)

prewhitened

Logical indicating if pre-whitening was applied

robust

Logical indicating if robust estimation was used

robust_level

Character indicating robustness level used

information_criterion

Reserved for future use

Arguments

data

Numeric vector or matrix. For matrices, rows are observations.

type

Type of change to detect: "mean", "var", or "both".

penalty

Penalty type ("MBIC", "BIC", "AIC") or numeric value.

min_segment

Minimum segment length (default: 2).

robust

Logical or character. FALSE for standard, TRUE for moderate robustness, or one of "mild", "moderate", "aggressive", "auto" for specific levels.

correct_ar

Logical. Apply pre-whitening for autocorrelated data. Default: FALSE.

merge_close

Integer or NULL. Merge changepoints within this distance. Default: NULL.

...

Additional arguments (currently unused).

Details

This implementation includes enhancements over standard PELT:

Pre-whitening for autocorrelated data: When correct_ar = TRUE, the function estimates the AR(1) coefficient and transforms the data via \(y'_t = y_t - \rho y_{t-1}\) before applying PELT.

Configurable robustness: The robust parameter accepts:

  • FALSE: Standard MLE-based estimation

  • TRUE or "moderate": 10\

  • "mild": 5\

  • "aggressive": 15\

  • "auto": Automatically select based on data characteristics

References

Killick, R., Fearnhead, P., and Eckley, I. A. (2012). Optimal detection of changepoints with a linear computational cost. JASA, 107(500), 1590-1598.

Examples

Run this code

data <- c(rnorm(100, 0), rnorm(100, 3))
result <- detect_pelt(data, type = "mean")


data_contaminated <- c(rnorm(100, 0), rnorm(100, 3))
data_contaminated[sample(200, 10)] <- rnorm(10, 0, 10)
result_robust <- detect_pelt(data_contaminated, robust = TRUE)


result_auto <- detect_pelt(data_contaminated, robust = "auto")

Run the code above in your browser using DataLab