library("cpss")
set.seed(666)
n <- 1000
tau <- c(100, 300, 700, 900)
tau_ext <- c(0, tau, n)
theta <- c(1, 0.2, 1, 0.2, 1)
seg_len <- diff(c(0, tau, n))
y <- unlist(lapply(seq(1, length(tau) + 1), function(k) {
rexp(seg_len[k], theta[k])
}))
res <- cpss.em(
y, family = "exp", algorithm = "WBS",
dist_min = 10, ncps_max = 10,
criterion = "MS", times = 10
)
cps(res)
# [1] 100 299 705 901
Run the code above in your browser using DataLab