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.

1 | ```
onlineCPD(oCPD = NULL, datapt, timept = NULL, hazard_func = const_hazard)
``` |

`oCPD` |
an object of type "oCPD", |

`datapt` |
the next data point in the series. This must have the same number of variables as |

`timept` |
optional, the corresponding time for |

`hazard_func` |
hazard function used in the model. Defaults to a constant hazard, suitable for exponential family models. |

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.

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

`R` |
n by n matrix of run-length probabilities. The value at |

`data` |
same as the input parameter, included for plotting. |

`time` |
same as the input parameter, included for plotting. |

`alpha` |
the vector of values of alpha after the final data point. |

`beta` |
the vector (or matrix) of values of beta (the variance) after the final data point. |

`kappa` |
the vector of values of kappa after the final data point. |

`mu` |
the vector (or matrix) of values of mu (the mean) after the final data point |

`max` |
vector of values; |

`changes` |
locations of detected changepoints. When the algorithm can not detect the exact location of a change, multiple possible values are reported. |

For a version of this same algorithm that functions offline (i.e. you give it the whole time series at once), see `offlineCPD`

This version runs a little slower because it needs to copy the "oCPD" object with every iteration. Use `offlineCPD`

unless you don't have the whole time series available at the start.

Zachary Zanussi

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

####OUR PAPER, WHEN IT EXISTS

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | ```
##### 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)
``` |

Questions? Problems? Suggestions? Tweet to @rdrrHQ or email at ian@mutexlabs.com.

All documentation is copyright its authors; we didn't write any of that.