cpop.crops {cpop}R Documentation

Calculate changepoint locations over a range of penalty values

Description

Runs the Changepoints for a Range of Penalties (CROPS) algorithm of Haynes et al. (2017) to find all of the optimal segmentations for multiple penalty values over a continuous range. For details of the CROPS method see the crops package. To obtain details for each segmentation determined by cpop.crops use the segmentations method (see example below).

Usage

cpop.crops(
  y,
  x = 1:length(y),
  grid = x,
  beta_min = 1.5 * log(length(y)),
  beta_max = 2.5 * log(length(y)),
  sd = sqrt(mean(diff(diff(y))^2)/6),
  minseglen = 0,
  prune.approx = FALSE
)

Arguments

y

A vector of length n containing the data.

x

A vector of length n containing the locations of y. Default value is NULL, in which case the locations x = 1:length(y)-1 are assumed.

grid

An ordered vector of possible locations for the change points. If this is NULL, then this is set to x, the vector of times/locations of the data points.

beta_min

Minimum value of the penalty range to be searched. Default is 1.5*log(length(y))

beta_max

Maximum value of the penalty range to be searched. Default is 2.5*log(length(y))

sd

Estimate of residual standard deviation. Can be a single numerical value or a vector of values for the case of varying standard deviation. Default value is sd = sqrt(mean(diff(diff(y))^2)/6).

minseglen

The minimum allowable segment length, i.e. distance between successive changepoints. Default is 0.

prune.approx

Only relevant if a minimum segment length is set. If TRUE, cpop will use an approximate pruning algorithm that will speed up computation but may occasionally lead to a sub-optimal solution in terms of the estimate change point locations. If the minimum segment length is 0, then an exact pruning algorithm is possible and is used.

Value

An instance of an S4 class of type cpop.crops.class which extends the crops.class in crops.

References

Haynes K, Eckley IA, Fearnhead P (2017). “Computationally Efficient Changepoint Detection for a Range of Penalties.” Journal of Computational and Graphical Statistics, 26(1), 134-143. doi:10.1080/10618600.2015.1116445.

Grose D, Fearnhead P (2021). crops: Changepoints for a Range of Penalties (CROPS). R package version 1.0.1, https://CRAN.R-project.org/package=crops.

Fearnhead P, Grose D (2024). “cpop: Detecting Changes in Piecewise-Linear Signals.” Journal of Statistical Software, 109(7), 1–30. doi:10.18637/jss.v109.i07.

Examples


library(cpop)

# generate some data
set.seed(0)
x <- seq(0,1,0.01)
n <- length(x)
sd <- rep(0.1,n)
mu <- c(2*x[1:floor(n/2)],2 - 2*x[(floor(n/2)+1):n])
y <- rnorm(n,mu,sd)
# calculate the changepoint locations and cost over a range of penalty values
res <- cpop.crops(y,x,sd=sd,beta_min=0.4*log(length(y)),beta_max=2.5*log(length(y)))
summary(res)

# plot the results
plot(res) 

# show the segmentations
 segmentations(res)



[Package cpop version 1.0.7 Index]