Skip to contents

detect_ar() and fastcpd.ar() are wrapper functions of detect() to find change points in AR(\(p\)) models. The function is similar to detect() except that the data is by default a one-column matrix or univariate vector and thus a formula is not required here.

Usage

detect_ar(data, order = 0, ...)

fastcpd_ar(data, order = 0, ...)

fastcpd.ar(data, order = 0, ...)

Arguments

data

A numeric vector, a matrix, a data frame or a time series object.

order

A positive integer specifying the order of the AR model.

...

Other arguments passed to detect(), for example, segment_count.

Value

A fastcpd object.

See also

Examples

set.seed(1)
n <- 1000
x <- rep(0, n + 3)
for (i in 1:600) {
  x[i + 3] <- 0.6 * x[i + 2] - 0.2 * x[i + 1] + 0.1 * x[i] + rnorm(1, 0, 3)
}
for (i in 601:1000) {
  x[i + 3] <- 0.3 * x[i + 2] + 0.4 * x[i + 1] + 0.2 * x[i] + rnorm(1, 0, 3)
}
result <- detect_ar(x[3 + seq_len(n)], 3)
summary(result)
#> 
#> Call:
#> detect_ar(data = x[3 + seq_len(n)], order = 3)
#> 
#> Change points:
#> 614 
#> 
#> Cost values:
#> 2754.116 2038.945 
#> 
#> Parameters:
#>     segment 1 segment 2
#> 1  0.57120256 0.2371809
#> 2 -0.20985108 0.4031244
#> 3  0.08221978 0.2290323
plot(result)

set.seed(1)
n <- 1000
x <- rep(0, n + 3)
for (i in 1:600) {
  x[i + 3] <- 0.6 * x[i + 2] - 0.2 * x[i + 1] + 0.1 * x[i] + rnorm(1, 0, 3)
}
for (i in 601:1000) {
  x[i + 3] <- 0.3 * x[i + 2] + 0.4 * x[i + 1] + 0.2 * x[i] + rnorm(1, 0, 3)
}
result <-
  detect_ar(x[3 + seq_len(n)], 3, beta = "MDL", cost_adjustment = "MDL")
summary(result)
#> 
#> Call:
#> detect_ar(data = x[3 + seq_len(n)], order = 3, beta = "MDL", 
#>     cost_adjustment = "MDL")
#> 
#> Change points:
#> 614 
#> 
#> Cost values:
#> 3973.35 2941.576 
#> 
#> Parameters:
#>     segment 1 segment 2
#> 1  0.57120256 0.2371809
#> 2 -0.20985108 0.4031244
#> 3  0.08221978 0.2290323
plot(result)