DeCAFS {DeCAFS} | R Documentation |
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, y_1, ..., y_n
, is
y_t = \mu_t + \epsilon_t
with \epsilon_t
an AR(1) process, and for t = 2, ..., N
\mu_t = \mu_{t-1} + \eta_t + \delta_t
where at time t
if we do not have a change then \delta_t = 0
and \eta_t \sim N(0, \sigma_\eta^2)
; whereas if we have a change then \delta_t \neq 0
and \eta_t=0
.
DeCAFS estimates the change by minimising a cost equal to twice the negative log-likelihood of this model, with a penalty \beta
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)
.
DeCAFS(
data,
beta = 2 * log(length(data)),
modelParam = estimateParameters(data, warningMessage = warningMessage),
penalties = NULL,
warningMessage = TRUE
)
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 |
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.
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.
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)