Learn R Programming

cpss (version 0.0.3)

cpss.var: Detecting changes in (co)variance

Description

Detecting changes in (co)variance

Usage

cpss.var(
  dataset,
  algorithm = "BS",
  dist_min = floor(log(n)),
  ncps_max = ceiling(n^0.4),
  pelt_pen_val = NULL,
  pelt_K = 0,
  wbs_nintervals = 500,
  criterion = "CV",
  times = 2,
  mu = NULL
)

Value

cpss.var returns an object of an S4 class, called "cpss", which collects data and information required for further change-point analyses and summaries. See cpss.custom.

Arguments

dataset

a numeric matrix of dimension \(n\times d\), where each row represents an observation and each column stands for a variable. A numeric vector is also acceptable for univariate observations.

algorithm

a character string specifying the change-point searching algorithm, one of the following choices: "SN" (segment neighborhood), "BS" (binary segmentation), "WBS" (wild binary segmentation) and "PELT" (pruned exact linear time) algorithms.

dist_min

an integer specifying minimum searching distance (length of feasible segments).

ncps_max

an integer specifying an upper bound of the number of true change-points.

pelt_pen_val

a numeric vector specifying candidate values of the penalty only if algorithm = "PELT".

pelt_K

a numeric value for pruning adjustment only if algorithm = "PELT". It is usually taken to be 0 if the negative log-likelihood is used as a cost, see Killick et al. (2012).

wbs_nintervals

an integer specifying the number of random intervals drawn only if algorithm = "WBS", see Fryzlewicz (2014).

criterion

a character string specifying the model selection criterion, "CV" ("cross-validation") or "MS" ("multiple-splitting").

times

an integer specifying how many times of sample-splitting should be performed; It should be 2 if criterion = "CV".

mu

If a numeric vector or constant is supplied, it will be taken as the value of the common mean. By default it is NULL, and the mean is estimated by the sample mean.

References

Killick, R., Fearnhead, P., and Eckley, I. A. (2012). Optimal Detection of Changepoints With a Linear Computational Cost. Journal of the American Statistical Association, 107(500): 1590–1598. Fryzlewicz, P. (2014). Wild binary segmentation for multiple change-point detection. The Annals of Statistics, 42(6): 2243–2281.

See Also

cpss.meanvar cpss.mean

Examples

Run this code
library("cpss")
if (!requireNamespace("MASS", quietly = TRUE)) {
  stop("Please install the package \"MASS\".")
}
set.seed(666)
n <- 1000
tau <- c(200, 500, 750)
mu <- list(rep(0, 2), rep(0, 2), rep(0, 2), rep(0, 2))
Sigma <- list(diag(2), matrix(c(1, 0, 0, 4), 2), matrix(c(1, -0.5, -0.5, 4), 2), diag(2))
seg_len <- diff(c(0, tau, n))
y <- lapply(seq(1, length(tau) + 1), function(k) {
  MASS::mvrnorm(n = seg_len[k], mu = mu[[k]], Sigma = Sigma[[k]])
})
y <- do.call(rbind, y)
res <- cpss.var(y, algorithm = "BS", dist_min = 20)
cps(res)
# [1] 215 515 751

Run the code above in your browser using DataLab