The safely_detect_changepoints() function calculates the optimal positioning and number of changepoints for given data and penalty. It uses a PELT algorithm with a nonparametric cost function based on the empirical distribution. The implementation is inspired by the code available on https://github.com/rkillick/changepoint.

safely_detect_changepoints(data, penalty = "MBIC", nquantiles = 10)

Arguments

data

a vector within which you wish to find changepoints

penalty

penalty for introducing another changepoint, one of "AIC", "BIC", "SIC", "MBIC", "Hannan-Quinn" or numeric non-negative value

nquantiles

the number of quantiles used in integral approximation

Value

a vector of optimal changepoint positions (last observations of each segment)

Examples


library(rSAFE)

data <- rep(c(2,7), each=4)
safely_detect_changepoints(data)
#> [1] 4

set.seed(123)
data <- c(rnorm(15, 0), rnorm(20, 2), rnorm(30, 8))
safely_detect_changepoints(data)
#> [1] 15 35
safely_detect_changepoints(data, penalty = 25)
#> [1] 35