Type: | Package |
Title: | Online Multivariate Changepoint Detection |
Version: | 1.0 |
Date: | 2021-07-07 |
Author: | Georg Hahn [aut,cre] |
Maintainer: | Georg Hahn <ghahn@hsph.harvard.edu> |
Description: | Implementation of a simple algorithm designed for online multivariate changepoint detection of a mean in sparse changepoint settings. The algorithm is based on a modified cusum statistic and guarantees control of the type I error on any false discoveries, while featuring O(1) time and O(1) memory updates per series as well as a proven detection delay. |
License: | GPL-2 | GPL-3 [expanded from: GPL (≥ 2)] |
Imports: | Rdpack,methods |
RdMacros: | Rdpack |
RoxygenNote: | 7.1.1 |
NeedsCompilation: | no |
Packaged: | 2021-07-08 16:18:25 UTC; acer |
Repository: | CRAN |
Date/Publication: | 2021-07-09 08:30:07 UTC |
Add new p
-dimensional data point, where p
is the number of time series being monitored.
Description
Add new p
-dimensional data point, where p
is the number of time series being monitored.
Usage
addData(obj, data)
## S4 method for signature 'fastOnlineCpt'
addData(obj, data)
Arguments
obj |
An object of the class "fastOnlineCpt". |
data |
The new data of dimension |
Value
An object of the class "fastOnlineCpt".
References
Hahn, G. (2021). Online multivariate changepoint detection with type I error control and constant time/memory updates per series. Under review.
Examples
library(fastOnlineCpt)
alpha <- 0.01
halfspent <- 100
spending_sequence <- function(n) { (n/(n+halfspent) - (n-1)/(n-1+halfspent)) * alpha }
obj <- fastOnlineCpt(spending_sequence)
p <- 10
n <- 50
data <- matrix(rnorm(p*n,mean=0),ncol=n)
obj <- addData(obj,data)
Test if a changepoint has occurred.
Description
Test if a changepoint has occurred.
Usage
checkCpt(obj, screenOutput = TRUE)
## S4 method for signature 'fastOnlineCpt'
checkCpt(obj, screenOutput = TRUE)
Arguments
obj |
An object of the class "fastOnlineCpt". |
screenOutput |
Boolean variable to indicate if the test result for a changepoint should be printed on the screen (default TRUE). |
Value
An object of the class "fastOnlineCpt".
References
Hahn, G. (2021). Online multivariate changepoint detection with type I error control and constant time/memory updates per series. Under review.
Examples
library(fastOnlineCpt)
alpha <- 0.01
halfspent <- 100
spending_sequence <- function(n) { (n/(n+halfspent) - (n-1)/(n-1+halfspent)) * alpha }
obj <- fastOnlineCpt(spending_sequence)
p <- 10
n <- 50
data <- matrix(rnorm(p*n,mean=0),ncol=n)
obj <- addData(obj,data)
obj <- checkCpt(obj)
data <- matrix(rnorm(p*n,mean=1),ncol=n)
obj <- addData(obj,data)
obj <- checkCpt(obj)
Initialize a new object of the class "fastOnlineCpt". This object allows one to add data in an online fashion and test for a changepoint.
Description
Initialize a new object of the class "fastOnlineCpt". This object allows one to add data in an online fashion and test for a changepoint.
Usage
fastOnlineCpt(spending_sequence)
Arguments
spending_sequence |
A function |
Value
A new object of the class "fastOnlineCpt".
References
Hahn, G. (2021). Online multivariate changepoint detection with type I error control and constant time/memory updates per series. Under review.
Examples
library(fastOnlineCpt)
alpha <- 0.01
halfspent <- 100
spending_sequence <- function(n) { (n/(n+halfspent) - (n-1)/(n-1+halfspent)) * alpha }
obj <- fastOnlineCpt(spending_sequence)
S4 class providing functionality to detect multivariate changepoints in an online setting.
Description
Provides method "addData" to add new incoming data for one or more time points, "checkCpt" to test for a changepoint, "lastCptTest" to query the last test result of the function "checkCpt", and "resetAlgorithm" to reset the algorithm in order to detect a new changepoint.
Slots
spending_sequence
A function handle which returns a testing level used in multiple testing.
data
Environment variable to store incoming data as a matrix.
T
The current time point.
S
Internal variable of the algorithm (modified cusum statistic).
s
Internal variable of the algorithm (modified cusum statistic).
nTest
Internal variable of the algorithm (counter for the multiple testing correction).
lastCptTest
Internal variable to store the last test result, which can be queried with a member function.
References
Hahn, G. (2021). Online multivariate changepoint detection with type I error control and constant time/memory updates per series. Under review.
Examples
library(fastOnlineCpt)
alpha <- 0.01
halfspent <- 100
spending_sequence <- function(n) { (n/(n+halfspent) - (n-1)/(n-1+halfspent)) * alpha }
obj <- fastOnlineCpt(spending_sequence)
Return the last result of the changepoint test performed with the function "checkCpt" as a vector.
Description
Return the last result of the changepoint test performed with the function "checkCpt" as a vector.
Usage
lastCptTest(obj)
## S4 method for signature 'fastOnlineCpt'
lastCptTest(obj)
Arguments
obj |
An object of the class "fastOnlineCpt". |
Value
A 5-dimensional vector containing the number of the test, the value of the Z-statistic, the p-value, the available testing level, and the changepoint location if a changepoint has been detected or NA otherwise. If no previous test has been performed, NA is returned.
References
Hahn, G. (2021). Online multivariate changepoint detection with type I error control and constant time/memory updates per series. Under review.
Examples
library(fastOnlineCpt)
alpha <- 0.01
halfspent <- 100
spending_sequence <- function(n) { (n/(n+halfspent) - (n-1)/(n-1+halfspent)) * alpha }
obj <- fastOnlineCpt(spending_sequence)
p <- 10
n <- 50
data <- matrix(rnorm(p*n,mean=0),ncol=n)
obj <- addData(obj,data)
obj <- checkCpt(obj)
print(lastCptTest(obj))
data <- matrix(rnorm(p*n,mean=1),ncol=n)
obj <- addData(obj,data)
obj <- checkCpt(obj)
print(lastCptTest(obj))
Reset the algorithm in order to detect a new changepoint. The algorithm can be reset at any point in time. To ensure valid multiple testing corrections, the time horizon is not reset to zero.
Description
Reset the algorithm in order to detect a new changepoint. The algorithm can be reset at any point in time. To ensure valid multiple testing corrections, the time horizon is not reset to zero.
Usage
resetAlgorithm(obj)
## S4 method for signature 'fastOnlineCpt'
resetAlgorithm(obj)
Arguments
obj |
An object of the class "fastOnlineCpt". |
Value
An object of the class "fastOnlineCpt".
References
Hahn, G. (2021). Online multivariate changepoint detection with type I error control and constant time/memory updates per series. Under review.
Examples
library(fastOnlineCpt)
alpha <- 0.01
halfspent <- 100
spending_sequence <- function(n) { (n/(n+halfspent) - (n-1)/(n-1+halfspent)) * alpha }
obj <- fastOnlineCpt(spending_sequence)
p <- 10
n <- 50
data <- matrix(rnorm(p*n,mean=0),ncol=n)
obj <- addData(obj,data)
obj <- resetAlgorithm(obj)