Learn R Programming

onlineCPD (version 1.0)

onlineCPD: Online Changepoint Detection

Description

Performs the oCPD algorithm in a truely on-line fashion; each iteration, you provide it with one more data point in the series, and the function will update the run length probabilities.

Usage

onlineCPD(oCPD = NULL, datapt, timept = NULL, hazard_func = const_hazard)

Arguments

oCPD
an object of type "oCPD", datapt will be added to the end of this series
datapt
the next data point in the series. This must have the same number of variables as oCPD
timept
optional, the corresponding time for datapt
hazard_func
hazard function used in the model. Defaults to a constant hazard, suitable for exponential family models.

Value

An object of class "oCPD", which is a list containing the following: An object of class "oCPD", which is a list containing the following:

Details

This function performs the oCPD algorithm, one point at a time. To use, start with either the result to a call to offlineCPD or just a single data point. In the case of a single data point, leave argument oCPD as NULL. See Examples section.

See offlineCPD for more information on how the algorithm works.

References

Adams, R. P. and Mackay, D. J. C. (2007), Bayesian Online Changepoint Detection

####OUR PAPER, WHEN IT EXISTS

Examples

Run this code
##### Univariate Data #####
set.seed(6)
x <- c(rnorm(50,mean=0.3,sd=0.15),rnorm(40,mean=0.7,sd=0.1),rnorm(60,mean=0.5,sd=0.15))
res <- onlineCPD(datapt=x[1])
for(k in x)
  res <- onlineCPD(res,k)
plot(res)

##### Real Multivariate Data #####
data(WalBelSentiment)
data(WalBelTimes)
res <- onlineCPD(datapt=WalBelSentiment[1400,],timept=WalBelTimes[1400])
for(k in 1401:1600)
  res <- onlineCPD(res,WalBelSentiment[k,],WalBelTimes[k])
plot(res)

## You can use onlineCPD to add points to an existing "oCPD" object
y <- c(rnorm(50,0.5,0.1),rnorm(20,0.48,0.02),rnorm(50,0.5,0.1))
res <- offlineCPD(y)
plot(res)
x <- rnorm(75,0.7,0.4)
for(k in x)
  res <- onlineCPD(res,k)
plot(res)

Run the code above in your browser using DataLab