Skip to contents

fastcpd_variance and fastcpd.variance are wrapper functions of fastcpd to find the variance change. The function is similar to fastcpd except that the data is by default a matrix or data frame or a vector with each row / element as an observation and thus a formula is not required here.

Usage

fastcpd_variance(data, ...)

fastcpd.variance(data, ...)

Arguments

data

A matrix, a data frame or a vector.

...

Other arguments passed to fastcpd, for example, segment_count.

Value

A class fastcpd object.

Examples

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

set.seed(1)
p <- 3
result <- fastcpd.variance(
  rbind(
    mvtnorm::rmvnorm(300, rep(0, p), crossprod(matrix(runif(p^2) * 2 - 1, p))),
    mvtnorm::rmvnorm(400, rep(0, p), crossprod(matrix(runif(p^2) * 2 - 1, p))),
    mvtnorm::rmvnorm(300, rep(0, p), crossprod(matrix(runif(p^2) * 2 - 1, p)))
  )
)
summary(result)
#> 
#> Call:
#> fastcpd.variance(data = rbind(mvtnorm::rmvnorm(300, rep(0, p), 
#>     crossprod(matrix(runif(p^2) * 2 - 1, p))), mvtnorm::rmvnorm(400, 
#>     rep(0, p), crossprod(matrix(runif(p^2) * 2 - 1, p))), mvtnorm::rmvnorm(300, 
#>     rep(0, p), crossprod(matrix(runif(p^2) * 2 - 1, p)))))
#> 
#> Change points:
#> 300 700 
#> 
#> Cost values:
#> 314.4177 1121.157 844.608