Skip to contents

fastcpd_var and fastcpd.var are wrapper functions of fastcpd.ts to find change points in VAR(p) models. The function is similar to fastcpd.ts except that the data is by default a matrix with row as an observation and thus a formula is not required here.

Usage

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

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

Arguments

data

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

order

A positive integer specifying the order of the VAR model.

...

Other arguments passed to fastcpd, for example, segment_count.

Value

A class fastcpd object.

Examples

set.seed(1)
n <- 800
p <- 2
theta_1 <- matrix(c(-0.3, 0.6, -0.5, 0.4, 0.2, 0.2, 0.2, -0.2), nrow = p)
theta_2 <- matrix(c(0.3, -0.4, 0.1, -0.5, -0.5, -0.2, -0.5, 0.2), nrow = p)
x <- matrix(0, n + 2, p)
for (i in 1:500) {
  x[i + 2, ] <- theta_1 %*% c(x[i + 1, ], x[i, ]) + rnorm(p, 0, 1)
}
for (i in 501:n) {
  x[i + 2, ] <- theta_2 %*% c(x[i + 1, ], x[i, ]) + rnorm(p, 0, 1)
}
result <- fastcpd.var(x, 2, cost_adjustment = NULL)
summary(result)
#> 
#> Call:
#> fastcpd.var(data = x, order = 2, cost_adjustment = NULL)
#> 
#> Change points:
#> 518 
#> 
#> Cost values:
#> 1537.24 807.8969