Learn R Programming

cpss (version 0.0.2)

cpss.glm: Detecting changes in GLMs

Description

Detecting changes in GLMs

Usage

cpss.glm(
  formula,
  family,
  data = NULL,
  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
)

Value

cpss.glm 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

formula

a formula object describing the change-point model to be fitted.

family

a description of the error distribution and link function to be used in the model, which can be a character string naming a family function or a family function.

data

an optional data frame, list or environment containing the variables in the model.

algorithm

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

dist_min

an integer indicating the minimum distance between two successive candidate change-points, with a default value \(floor(log(n))\).

ncps_max

an integer indicating the maximum number of change-points searched for, with a default value \(ceiling(n^0.4)\).

pelt_pen_val

a numeric vector specifying the collection of candidate values of the penalty if the "PELT" algorithm is used.

pelt_K

a numeric value to adjust the pruning tactic, usually is taken to be 0 if negative log-likelihood is used as a cost; more details can be found in Killick et al. (2012).

wbs_nintervals

an integer indicating the number of random intervals drawn in the "WBS" algorithm and a default value 500 is used.

criterion

a character string indicating which model selection criterion, "cross- validation" ("CV") or "multiple-splitting" ("MS"), is used.

times

an integer indicating how many times of sample-splitting should be performed; if "CV" criterion is used, it should be set as 2.

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.

See Also

cpss.lm

Examples

Run this code
library("cpss")
set.seed(666)
n <- 200
size <- rpois(n, 20 - 1) + 1
tau <- c(75, 100, 175)
tau_ext <- c(0, tau, n)
be <- list(c(0, 0.5), c(0, -0.5), c(0.5, -0.5), c(-0.5, -0.5))
seg_len <- diff(c(0, tau, n))
x <- rnorm(n)
eta <- lapply(seq(1, length(tau) + 1), function(k) {
  be[[k]][1] + be[[k]][2] * x[(tau_ext[k] + 1):tau_ext[k + 1]]
})
eta <- do.call(c, eta)
p <- 1 / (1 + exp(-eta))
y <- rbinom(n, size = size, prob = p)
# \donttest{
pelt_pen_val <- (log(n))^seq(0.5, 2, by = 0.1)
res <- cpss.glm(
  formula = cbind(y, size - y) ~ x, family = binomial(),
  algorithm = "PELT", pelt_pen_val = pelt_pen_val,
  dist_min = 5, ncps_max = 10
)
summary(res)
# 75  105  175
coef(res)
# [1,] 0.02540872  0.08389551  0.5284425 -0.4980768
# [2,] 0.57222684 -0.45430385 -0.5203319 -0.4581678
# }

Run the code above in your browser using DataLab