cusum_function: Calculate the CUMSUM statistic

View source: R/Finalised_coding.R

cusum_functionR Documentation

Calculate the CUMSUM statistic

Description

This function returns the CUMSUM statistic for a given data sequence. See Details for more information.

Usage

cusum_function(x)

Arguments

x

A numeric vector containing the data.

Details

The CUSUM statistic for x at a location b is defined as

\tilde{X}_{s,e}^b = \sqrt{\frac{e-b}{n(b-s+1)}}\sum_{t=s}^{b}X_t - \sqrt{\frac{b-s+1}{n(e-b)}}\sum_{t=b+1}^{e}X_t,

where 1\le s \le b < e\le T and n=e-s+1. In cusum_function, we have s=1, e=T.

Value

A numeric vector with the CUSUM statistic values at b = 1,2,...,T-1, where T is the length of x.

Author(s)

Andreas Anastasiou, anastasiou.andreas@ucy.ac.cy

See Also

cumsum_lin for the calculation of the contrast function that is used in the case of piecewise-linear mean signals.

Examples

no.cpt.noise <- rnorm(2000)
csm.no.cpt <- IDetect:::cusum_function(no.cpt.noise)

single.cpt <- c(rep(4,1000),rep(0,1000))
single.cpt.noise <- single.cpt + rnorm(2000)
csm.single.cpt <- IDetect:::cusum_function(single.cpt.noise)
#*** Notice that the maximum in absolute value of \code{csm.single.cpt}
#*** occurs in a neighbourhood of the true change-point, which is 1000.
which.max(abs(csm.single.cpt))

IDetect documentation built on May 7, 2026, 5:09 p.m.