Learn R Programming

RegimeChange (version 0.1.1)

bocpd: Bayesian Online Changepoint Detection

Description

Implements the BOCPD algorithm of Adams and MacKay (2007). Maintains a posterior distribution over the run length (time since last changepoint) and updates it online as new observations arrive.

Usage

bocpd(
  data,
  type = "both",
  prior = NULL,
  hazard = NULL,
  threshold = 0.3,
  truncate_run_length = NULL,
  ...
)

Value

List containing:

  • changepoints: Detected changepoint locations

  • posterior: Matrix of run length posteriors over time

  • prob_change: Probability of changepoint at each time

  • map_run_length: Maximum a posteriori run length at each time

Arguments

data

Numeric vector or matrix

type

Type of change to detect (currently supports "both")

prior

Prior specification (from normal_gamma(), normal_known_var(), etc.)

hazard

Hazard prior (from geometric_hazard(), etc.) or numeric hazard rate

threshold

Probability threshold for declaring a changepoint

truncate_run_length

Maximum run length to track (for efficiency)

...

Additional arguments

References

Adams, R. P. and MacKay, D. J. C. (2007). Bayesian Online Changepoint Detection. arXiv:0710.3742

Examples

Run this code
data <- c(rnorm(100, mean = 0), rnorm(100, mean = 3))

result <- bocpd(data)

result <- bocpd(data, prior = normal_gamma(mu0 = 0, kappa0 = 1,
                                            alpha0 = 1, beta0 = 1))


result <- bocpd(data, hazard = 0.01)

Run the code above in your browser using DataLab