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 |
-dimensional data point, where
is the number of time series being monitored.Add new -dimensional data point, where
is the number of time series being monitored.
addData(obj, data) ## S4 method for signature 'fastOnlineCpt' addData(obj, data)
addData(obj, data) ## S4 method for signature 'fastOnlineCpt' addData(obj, data)
obj |
An object of the class "fastOnlineCpt". |
data |
The new data of dimension |
An object of the class "fastOnlineCpt".
Hahn, G. (2021). Online multivariate changepoint detection with type I error control and constant time/memory updates per series. Under review.
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)
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.
checkCpt(obj, screenOutput = TRUE) ## S4 method for signature 'fastOnlineCpt' checkCpt(obj, screenOutput = TRUE)
checkCpt(obj, screenOutput = TRUE) ## S4 method for signature 'fastOnlineCpt' checkCpt(obj, screenOutput = TRUE)
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). |
An object of the class "fastOnlineCpt".
Hahn, G. (2021). Online multivariate changepoint detection with type I error control and constant time/memory updates per series. Under review.
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)
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.
fastOnlineCpt(spending_sequence)
fastOnlineCpt(spending_sequence)
spending_sequence |
A function |
A new object of the class "fastOnlineCpt".
Hahn, G. (2021). Online multivariate changepoint detection with type I error control and constant time/memory updates per series. Under review.
library(fastOnlineCpt) alpha <- 0.01 halfspent <- 100 spending_sequence <- function(n) { (n/(n+halfspent) - (n-1)/(n-1+halfspent)) * alpha } obj <- fastOnlineCpt(spending_sequence)
library(fastOnlineCpt) alpha <- 0.01 halfspent <- 100 spending_sequence <- function(n) { (n/(n+halfspent) - (n-1)/(n-1+halfspent)) * alpha } obj <- fastOnlineCpt(spending_sequence)
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.
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.
Hahn, G. (2021). Online multivariate changepoint detection with type I error control and constant time/memory updates per series. Under review.
library(fastOnlineCpt) alpha <- 0.01 halfspent <- 100 spending_sequence <- function(n) { (n/(n+halfspent) - (n-1)/(n-1+halfspent)) * alpha } obj <- fastOnlineCpt(spending_sequence)
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.
lastCptTest(obj) ## S4 method for signature 'fastOnlineCpt' lastCptTest(obj)
lastCptTest(obj) ## S4 method for signature 'fastOnlineCpt' lastCptTest(obj)
obj |
An object of the class "fastOnlineCpt". |
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.
Hahn, G. (2021). Online multivariate changepoint detection with type I error control and constant time/memory updates per series. Under review.
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))
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.
resetAlgorithm(obj) ## S4 method for signature 'fastOnlineCpt' resetAlgorithm(obj)
resetAlgorithm(obj) ## S4 method for signature 'fastOnlineCpt' resetAlgorithm(obj)
obj |
An object of the class "fastOnlineCpt". |
An object of the class "fastOnlineCpt".
Hahn, G. (2021). Online multivariate changepoint detection with type I error control and constant time/memory updates per series. Under review.
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)
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)