Skip to contents

fastcpd_meanvariance(), fastcpd.meanvariance(), fastcpd_mv(), fastcpd.mv() are wrapper functions of fastcpd() to find the meanvariance 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_meanvariance(data, ...)

fastcpd.meanvariance(data, ...)

fastcpd_mv(data, ...)

fastcpd.mv(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)
p <- 1
result <- fastcpd.meanvariance(c(
  rnorm(300, 0, 1),
  rnorm(400, 10, 1),
  rnorm(300, 0, 10),
  rnorm(300, 0, 1),
  rnorm(400, 10, 1),
  rnorm(300, 10, 10)
))
summary(result)
#> 
#> Call:
#> fastcpd.meanvariance(data = c(rnorm(300, 0, 1), rnorm(400, 10, 
#>     1), rnorm(300, 0, 10), rnorm(300, 0, 1), rnorm(400, 10, 1), 
#>     rnorm(300, 10, 10)))
#> 
#> Change points:
#> 300 700 1001 1300 1700 
#> 
#> Cost values:
#> 412.1898 586.8914 1139.531 433.9691 562.2071 1142.934 
plot(result)

if (requireNamespace("mvtnorm", quietly = TRUE)) {
  set.seed(1)
  p <- 4
  result <- fastcpd.mv(
    rbind(
      mvtnorm::rmvnorm(300, mean = rep(0, p), sigma = diag(1, p)),
      mvtnorm::rmvnorm(400, mean = rep(10, p), sigma = diag(1, p)),
      mvtnorm::rmvnorm(300, mean = rep(0, p), sigma = diag(100, p)),
      mvtnorm::rmvnorm(300, mean = rep(0, p), sigma = diag(1, p)),
      mvtnorm::rmvnorm(400, mean = rep(10, p), sigma = diag(1, p)),
      mvtnorm::rmvnorm(300, mean = rep(10, p), sigma = diag(100, p))
    )
  )
  summary(result)
}
#> 
#> Call:
#> fastcpd.mv(data = rbind(mvtnorm::rmvnorm(300, mean = rep(0, p), 
#>     sigma = diag(1, p)), mvtnorm::rmvnorm(400, mean = rep(10, 
#>     p), sigma = diag(1, p)), mvtnorm::rmvnorm(300, mean = rep(0, 
#>     p), sigma = diag(100, p)), mvtnorm::rmvnorm(300, mean = rep(0, 
#>     p), sigma = diag(1, p)), mvtnorm::rmvnorm(400, mean = rep(10, 
#>     p), sigma = diag(1, p)), mvtnorm::rmvnorm(300, mean = rep(10, 
#>     p), sigma = diag(100, p))))
#> 
#> Change points:
#> 300 700 1000 1300 1700 
#> 
#> Cost values:
#> 1714.968 2299.119 4500.027 1654.917 2259.023 4444.359 
# \donttest{
set.seed(1)
data <- c(rnorm(2000, 0, 1), rnorm(2000, 1, 1), rnorm(2000, 1, 2))
(result_time <- system.time(
  result <- fastcpd.variance(data, r.progress = FALSE, cp_only = TRUE)
))
#>    user  system elapsed 
#>   1.266   0.000   1.266 
result@cp_set
#> [1] 1985 4000
# }
# \donttest{
set.seed(1)
data <- c(rnorm(2000, 0, 1), rnorm(2000, 1, 1), rnorm(2000, 1, 2))
(result_time <- system.time(
  result <- fastcpd.variance(
    data, beta = "BIC", cost_adjustment = "BIC",
    r.progress = TRUE, cp_only = TRUE
  )
))
#>    user  system elapsed 
#>   1.033   0.000   1.032 
result@cp_set
#> [1] 1985 4000
# }