detectEWMAMean: Detect a change/changes in a vector using 'EWMA' method

View source: R/detectEWMAMeanCDR.R

detectEWMAMeanR Documentation

Detect a change/changes in a vector using 'EWMA' method

Description

Given a vector x, use the 'EWMA' method to sequentially detect changes (or a single change) in the MEAN of the vector.

Usage

detectEWMAMean(
  x,
  r = 0.25,
  L = 3,
  BL = 50,
  multiple = TRUE,
  single = !multiple,
  usePrechange = FALSE,
  prechangeMean = NULL,
  prechangeSigma = NULL,
  prechangeVar = NULL,
  skipCheck = FALSE
)

Arguments

x

The vector (stream) in which to detect change(s).

r

Control parameter for EWMA. Must be in range [0,1]. Default is r=0.25.

L

Control parameter for EWMA. Default is L=3.00

BL

The burn-in length. Default is BL=50.

multiple

Boolean to use to decide whether to detect multiple changes or only a single change. Default is TRUE (i.e. detect multiple changes).

single

Boolean to use to decide whether to detect only a single change or multiple changes. Set to !multiple, i.e. default is FALSE. If both single and multiple are set to TRUE, then only a single change will be detected; if both set to FALSE then multiple changes will be detected (i.e. single dominates).

usePrechange

Boolean indicating whether prechange parameters (mean and variance) are known and will be used (or not). Default is FALSE. If TRUE, then prechange mean and standard deviation variance must be specified. See parameters prechangeMean, prechangeSigma and prechangeVar.

prechangeMean

Value to be used for the prechange mean. Default is NULL. If prechangeKnown = TRUE and value is NULL, this will result in an error.

prechangeSigma

Value to be used for the prechange standard deviation. Default is NULL. If prechangeKnown = TRUE and value is NULL, this will result in an error, unless prechangeVar is not NULL.

prechangeVar

Value to be used for the prechange variance. Default is NULL. If prechangeKnown = TRUE and value is NULL, this will result in an error, unless prechangeSigma is not NULL. prechangeVar is set to sqrt(prechangeSigma).

skipCheck

A boolean which allows the function to skip the check of the stream. Default is FALSE.

Details

'EWMA' updates via:

Z_{j} = (1-r) Z_{j-1} + r x_{j}

where \mu is the mean of the in-control stream, x_j is the observation at time j and r is a control parameter for EWMA. Then, a change is signalled if

|Z_j - \mu| > L \sigma_{Z_j}

, where L is the other control parameter, and \sigma_{Z_j} is a scaled version of the in-control variance \sigma. This is the formulation for using 'EWMA' to detect an increase or decrease in the mean.

Value

A list with the following elements:

tauhat

A vector of the changepoints found.

Author

Dean Bodenham

References

S. W. Roberts (1959) Control chart tests based on geometric moving averages. Technometrics, 1(3), 239-250

Examples

# create a stream with three changepoints
set.seed(8)
x <- rnorm(400, 5, 1) + rep(c(0:3), each=100) # mean is 5 and s.d. is 1

# multiple changepoints
list_ewma <- detectEWMAMean(x, r=0.25, L=3.023, BL=50, multiple=TRUE)

# now only a single (the first) changepoint
list_ewma2 <- detectEWMAMean(x, r=0.25, L=3.023, BL=50, single=TRUE)

# now only a single (the first) changepoint, but with the prechange 
# mean and variance known
list_ewma3 <- detectEWMAMean(x, r=0.25, L=3.023, BL=50, single=TRUE,
                             prechangeMean=5, prechangeSigma=1)



ffstream documentation built on May 31, 2023, 7:53 p.m.