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 fastcpd object.

See also

Examples

set.seed(1)
data <- c(rnorm(300, 0, 1), rnorm(400, 0, 100), rnorm(300, 0, 1))
result <- fastcpd.variance(data)
summary(result)
#> 
#> Call:
#> fastcpd.variance(data = data)
#> 
#> Change points:
#> 300 700 
#> 
#> Cost values:
#> 703.3755 2430.33 705.6112 
if (requireNamespace("mvtnorm", quietly = 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:
#> 753.6359 1706.144 1280.607 
# \donttest{
set.seed(1)
data <- c(rnorm(3000, 0, 1), rnorm(3000, 0, 2), rnorm(3000, 0, 1))
(result_time <- system.time(
  result <- fastcpd.variance(data, r.progress = FALSE, cp_only = TRUE)
))
#>    user  system elapsed 
#>   1.900   0.001   1.901 
result@cp_set
#> [1] 2997 5989
# }
# \donttest{
set.seed(1)
data <- c(rnorm(3000, 0, 1), rnorm(3000, 0, 2), rnorm(3000, 0, 1))
(result_time <- system.time(
  result <- fastcpd.variance(
    data, beta = "BIC", cost_adjustment = "BIC",
    r.progress = FALSE, cp_only = TRUE
  )
))
#>    user  system elapsed 
#>   1.850   0.000   1.851 
result@cp_set
#> [1] 2997 5989
# }