DeCAFS {DeCAFS} | R Documentation |
Main DeCAFS algorithm for detecting abrupt changes
Description
This function implements the DeCAFS algorithm to detect abrupt changes in mean of a univariate data stream in the presence of local fluctuations and auto-correlated noise.
It detects the changes under a penalised likelihood model where the data, , is
with an AR(1) process, and for
where at time if we do not have a change then
and
; whereas if we have a change then
and
.
DeCAFS estimates the change by minimising a cost equal to twice the negative log-likelihood of this model, with a penalty
for adding a change.
Note that the default DeCAFS behavior will assume the RWAR model, but fit on edge cases is still possible. For instance, should the user wish for DeCAFS to fit an AR model only with a piecewise constant signal, or similarly a model that just assumes random fluctuations in the signal, this can be specified within the initial parameter estimation, by setting the argument:
modelParam = estimateParameters(y, model = "AR")
. Similarly, to allow for negative autocorrelation estimation, set modelParam = estimateParameters(Y$y, phiLower = -1)
.
Usage
DeCAFS(
data,
beta = 2 * log(length(data)),
modelParam = estimateParameters(data, warningMessage = warningMessage),
penalties = NULL,
warningMessage = TRUE
)
Arguments
data |
A vector of observations y |
beta |
The l0 penalty. The default one is |
modelParam |
A list of 3 initial model parameters: |
penalties |
Can be used as an alternative to the model parameters, a list of 3 initial penalties: |
warningMessage |
When |
Value
Returns an s3 object of class DeCAFSout where:
$changepoints
is the vector of change-point locations,
$signal
is the estimated signal without the auto-correlated noise,
$costFunction
is the optimal cost in form of piecewise quadratics at the end of the sequence,
$estimatedParameters
is a list of parameters estimates (if estimated, otherwise simply the initial
modelParam
input),$data
is the sequence of observations.
References
Romano, G., Rigaill, G., Runge, V., Fearnhead, P. (2021). Detecting Abrupt Changes in the Presence of Local Fluctuations and Autocorrelated Noise. Journal of the American Statistical Association. doi:10.1080/01621459.2021.1909598.
Examples
library(ggplot2)
set.seed(42)
Y <- dataRWAR(n = 1e3, phi = .5, sdEta = 1, sdNu = 3, jumpSize = 15, type = "updown", nbSeg = 5)
y <- Y$y
res = DeCAFS(y)
ggplot(data.frame(t = 1:length(y), y), aes(x = t, y = y)) +
geom_point() +
geom_vline(xintercept = res$changepoints, color = "red") +
geom_vline(xintercept = Y$changepoints, col = "blue", lty = 3)