Skip to contents

"fastcpd_poisson" and "fastcpd.poisson" are wrapper functions of fastcpd to find change points in Poisson 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_poisson(data, ...)

fastcpd.poisson(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

# \donttest{
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 <- 1100
p <- 3
x <- mvtnorm::rmvnorm(n, rep(0, p), diag(p))
delta <- rnorm(p)
theta_0 <- c(1, 0.3, -1)
y <- c(
  rpois(500, exp(x[1:500, ] %*% theta_0)),
  rpois(300, exp(x[501:800, ] %*% (theta_0 + delta))),
  rpois(200, exp(x[801:1000, ] %*% theta_0)),
  rpois(100, exp(x[1001:1100, ] %*% (theta_0 - delta)))
)
result <- fastcpd.poisson(cbind(y, x))
summary(result)
#> 
#> Call:
#> fastcpd.poisson(data = cbind(y, x))
#> 
#> Change points:
#> 505 800 1003 
#> 
#> Cost values:
#> 250.9977 188.4381 98.97221 51.24394 
#> 
#> Parameters:
#>    segment 1  segment 2  segment 3  segment 4
#> 1  1.0155039  0.6050537  1.0536534  1.4451928
#> 2  0.2763447 -0.2766940  0.2629143  0.9910079
#> 3 -1.0492042 -0.5883050 -0.9551797 -1.4354638
plot(result)

# }