Skip to contents

fastcpd_arma and fastcpd.arma are wrapper functions of fastcpd to find change points in ARMA(p, q) models. The function is similar to fastcpd except that the data is by default a one-column matrix or univariate vector and thus a formula is not required here.

Usage

fastcpd_arma(data, order = c(0, 0), ...)

fastcpd.arma(data, order = c(0, 0), ...)

Arguments

data

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

order

A vector of length two specifying the order of the ARMA model.

...

Other arguments passed to fastcpd, for example, segment_count.

Value

A class fastcpd object.

Examples

# \donttest{
if (!requireNamespace("ggplot2", quietly = TRUE)) utils::install.packages(
  "ggplot2", repos = "https://cloud.r-project.org", quiet = TRUE
)

set.seed(1)
n <- 300
w <- rnorm(n + 3, 0, 3)
x <- rep(0, n + 3)
for (i in 1:200) {
  x[i + 3] <- 0.1 * x[i + 2] - 0.3 * x[i + 1] + 0.1 * x[i] +
    0.1 * w[i + 2] + 0.5 * w[i + 1] + w[i + 3]
}
for (i in 201:n) {
  x[i + 3] <- 0.3 * x[i + 2] + 0.1 * x[i + 1] - 0.3 * x[i] -
    0.6 * w[i + 2] - 0.1 * w[i + 1] + w[i + 3]
}
result <- suppressWarnings(
  fastcpd.arma(
    data = x[3 + seq_len(n)],
    order = c(3, 2),
    segment_count = 3,
    lower = c(rep(-1, 3 + 2), 1e-10),
    upper = c(rep(1, 3 + 2), Inf),
    line_search = c(1, 0.1, 1e-2)
  )
)
summary(result)
#> 
#> Call:
#> fastcpd.arma(data = x[3 + seq_len(n)], order = c(3, 2), segment_count = 3, 
#>     lower = c(rep(-1, 3 + 2), 1e-10), upper = c(rep(1, 3 + 2), 
#>         Inf), line_search = c(1, 0.1, 0.01))
#> 
#> Change points:
#> 200 
#> 
#> Cost values:
#> 494.3396 253.7842 
#> 
#> Parameters:
#>      segment 1   segment 2
#> 1  0.001350478  0.74342384
#> 2 -0.828668713 -0.07333667
#> 3  0.200084507 -0.36950210
#> 4  0.208486751 -1.27312849
#> 5  0.999994041  0.45204533
#> 6  7.831992812  8.83494421
plot(result)

# }