fastcpd_ts
is a wrapper function for fastcpd
to find
change points in time series data. The function is similar to fastcpd
except that the data is a time series data and the family is one of
"ar"
, "var"
, "arima"
or "garch"
.
Arguments
- data
A numeric vector, a matrix, a data frame or a time series object.
- family
A character string specifying the family of the time series. The value should be one of
"ar"
,"var"
,"arima"
or"garch"
.- order
A positive integer or a vector of length less than four specifying the order of the time series. Possible combinations with
family
are:ar, NUMERIC(1): AR(p) model using linear regression.
ar, NUMERIC(3): ARIMA(p, 0, 0) model using
forecast::Arima
, wherep
is the first element of the vector.var, NUMERIC(1): VAR(p) model using linear regression.
ma, NUMERIC(1): MA(q) model using
forecast::Arima
.ma, NUMERIC(3): ARIMA(0, 0, q) model using
forecast::Arima
, whereq
is the third element of the vector.arima, NUMERIC(3): ARIMA(p, d, q) model using
forecast::Arima
.garch, NUMERIC(2): GARCH(p, q) model using
tseries::garch
.
- ...
Other arguments passed to
fastcpd
, for example,segment_count
. One special argument can be passed here isinclude.mean
, which is a logical value indicating whether the mean should be included in the model. The default value isTRUE
.
Examples
# \donttest{
set.seed(1)
n <- 600
x <- rep(0, n + 1)
for (i in 1:300) {
x[i + 1] <- 0.8 * x[i] + rnorm(1, 0, 2)
}
for (i in 301:n) {
x[i + 1] <- 0.1 * x[i] + rnorm(1, 0, 2)
}
result <- fastcpd.ts(
x[1 + seq_len(n)],
"ar",
c(1, 0, 0),
include.mean = FALSE,
trim = 0,
beta = (1 + 1 + 1) * log(n) / 2 * 3
)
summary(result)
#>
#> Call:
#> fastcpd.ts(data = x[1 + seq_len(n)], family = "ar", order = c(1,
#> 0, 0), include.mean = FALSE, trim = 0, beta = (1 + 1 + 1) *
#> log(n)/2 * 3)
#>
#> Change points:
#> 301
#>
#> Cost values:
#> 623.7791 643.8769
plot(result)
# }