Description Usage Arguments Value Author(s) See Also Examples
View source: R/processObservation.R
Updates the state of an existing Change Point Model (CPM) S4 object, by processing a single observation. This effectively computes the D_{k,t+1} statistics, for a CPM that had previously seen t observations. When the function is called, several events happen. First, the function returns a CPM object which is identical the CPM object passed to the function, except that the observation passed as an argument has been processed and added to the state. Second, the CPM computes the D_{t+1} statistic and compares it to its stored sequence of thresholds. If a change is detected, then this is stored in the state of the CPM, and a call to changeDetected
will now return TRUE
.
Note that this function is part of the S4 object section of the cpm
package, which allows for more precise control over the change detection process. For many simple change detection applications this extra complexity will not be required, and the detectChangePoint
and processStream
functions should be used instead.
For a fuller overview of this function including a description of the CPM framework and examples of how to use the various functions, please consult the package manual "Parametric and Nonparametric Sequential Change Detection in R: The cpm Package" available from www.gordonjross.co.uk
1 2 | processObservation(cpm,x)
|
cpm |
The CPM S4 object which is to be updated. |
x |
The observation which is to be processed. |
The updated CPM. If a stream is being processed, then this should be stored, and used to process the next observation in the sequence.
Gordon J. Ross gordon@gordonjross.co.uk
makeChangePointModel, changeDetected
.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | #generate a sequence containing a single change point
x <- c(rnorm(100,0,1),rnorm(100,1,1))
#use a Student CPM
cpm <- makeChangePointModel(cpmType="Student", ARL0=500)
for (i in 1:length(x)) {
#process each observation in turn
cpm <- processObservation(cpm,x[i])
if (changeDetected(cpm)) {
print(sprintf("change detected at observation %s",i))
break
}
}
|
[1] "change detected at observation 113"
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.