Skip to contents

"fastcpd_binomial" and "fastcpd.binomial" are wrapper functions of fastcpd to find change points in logistic regression models. The function is similar to "fastcpd" except that the data is by default a matrix or data frame with the response variable as the first column and thus a formula is not required here.

Usage

fastcpd_binomial(data, ...)

fastcpd.binomial(data, ...)

Arguments

data

A matrix or a data frame with the response variable as the first column.

...

Other arguments passed to fastcpd, for example, segment_count.

Value

A class fastcpd object.

Examples

for (package in c("ggplot2", "mvtnorm")) {
  if (!requireNamespace(package, quietly = TRUE)) utils::install.packages(
    package, repos = "https://cloud.r-project.org", quiet = TRUE
  )
}

set.seed(1)
n <- 500
p <- 4
x <- mvtnorm::rmvnorm(n, rep(0, p), diag(p))
theta <- rbind(rnorm(p, 0, 1), rnorm(p, 2, 1))
y <- c(
  rbinom(300, 1, 1 / (1 + exp(-x[1:300, ] %*% theta[1, ]))),
  rbinom(200, 1, 1 / (1 + exp(-x[301:n, ] %*% theta[2, ])))
)
result <- suppressWarnings(fastcpd.binomial(cbind(y, x)))
summary(result)
#> 
#> Call:
#> fastcpd.binomial(data = cbind(y, x))
#> 
#> Change points:
#> 301 
#> 
#> Cost values:
#> 137.2291 69.38333 
#> 
#> Parameters:
#>    segment 1 segment 2
#> 1 -0.9606121 2.1356877
#> 2 -1.6525248 2.7666014
#> 3  1.0558616 2.3871760
#> 4  0.3810240 0.7277254
plot(result)