Package 'fastOnlineCpt'

Title: Online Multivariate Changepoint Detection
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.
Authors: Georg Hahn [aut,cre]
Maintainer: Georg Hahn <[email protected]>
License: GPL (>= 2)
Version: 1.0
Built: 2024-11-23 05:03:54 UTC
Source: https://github.com/cran/fastOnlineCpt

Help Index


Add new pp-dimensional data point, where pp is the number of time series being monitored.

Description

Add new pp-dimensional data point, where pp 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 n×pn \times p to be added, where nn is the number of new time points being added.

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 f(n)f(n) of one argument which for every nn returns a testing threshold such that n=1f(n)=α\sum_{n=1}^\infty f(n) = \alpha, where α\alpha is the desired level of the test over the (possibly infinite) time horizon.

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)