IMPORTANT: Older versions of DeCAFS have a major bug
that severely affect the computational complexity of the procedure. This
was fixed from version 3.3.2. Should you have an older version installed
(lower than 3.3.2) please make sure you update your DeCAFS package
either through CRAN or GitHub. You can check your version number at the
bottom of the documentation page of DeCAFS, via
help("DeCAFS")
.
WHAT’S NEW: In addition to the automatic model
selection, we introduced a graphical iterative model selection procedure
that aids the user in selecting an appropriate model for a given
sequence of observations. This tuning procedure can seriously improve
performances under more challenging scenarios. More details can be found
by checking the documentation:
help("guidedModelSelection")
.
DeCAFS vignette |
DeCAFS
is a c++
implementation for
R
of the DeCAFS algorithm for performing optimal multiple
changepoint detection on detecting the change in mean in presence of
autocorrelation or random fluctuations in the data sequence.
To install the package from Github:
# devtools::install_github("gtromano/DeCAFS")
library(DeCAFS)
Alternatively one could fork this repository, and:
# install.packages("DeCAFS", repos = NULL, type = "source")
library(DeCAFS)
The packages requires Rcpp
with compiler support for the
std
library with the g++14
standard.
If any bug should be spotted, or for any information regarding this
package, please email the package mantainer: g
dot
romano
at lancaster.ac.uk
.
We model a combination of a radom walk process (also known as standard Brownian motion or Wiener Process) and an AR process. Let be a random vectorm then for ,
where
and
Then, DeCAFS solves the following minimization problem:
Where our , and is an indicator function..
This demo shows some of the features present in the
DeCAFS
package.
Three functions at the moment are present in the package:
functions | description |
---|---|
DeCAFS | Main function to run the DeCAFS algorithm on a sequence of observations |
dataRWAR | Generate a realization of a RW+AR process |
estimateParameters | Estimate the parameters of our model |
At the moment only two functions for data generation and parameter estimation are present, and they all are tailored for the Random Walk. Since l2-FPOP can tackle also other Stochastic Processes, more functions are expected to be added.
We will start generating a Random Walk. The function
dataRWAR
takes in:
set.seed(42)
= dataRWAR(n = 1e3, poisParam = .01, meanGap = 15, phi = .5, sdEta = 3, sdNu = 1)
Y = Y[["y"]] y
Running DeCAFS is fairly straightforward:
= DeCAFS(y) res
We can plot the DeCAFS segmentation (red lines), alongside with our real segmentation (dotted blue lines).
Alternatively, we can also pass all the required parameters in order for it to run. In this case, since we both have an AR and RW component, we will need to pass down both , and .
= DeCAFS(y, beta = 2 * log(length(y)), modelParam = list(sdEta = 3, sdNu = 1, \phi = .7)) res
## Error: <text>:1:84: unexpected input
## 1: res = DeCAFS(y, beta = 2 * log(length(y)), modelParam = list(sdEta = 3, sdNu = 1, \
## ^
Let’s say we now have the . In this case our model simply becomes a random walk plus noise:
Our Algorithm is capable of dealing with this extreme situation:
set.seed(44)
= dataRWAR(n = 1e3, poisParam = .01, meanGap = 15, phi = 0, sdEta = 2, sdNu = 1)
Y = Y[["y"]]
y
= DeCAFS(y, beta = 2 * log(length(y)), modelParam = list(sdEta = 2, sdNu = 1, phi = 0)) res
which leads to the result:
Secondly, let’s say that the In this case we end up with an Autoregressive model with changes.
In this case we need to set , and for :
set.seed(46)
= dataRWAR(n = 1e3, poisParam = .01, meanGap = 10, phi = .98, sdEta = 0, sdNu = 2)
Y = Y[["y"]]
y
= DeCAFS(y, beta = 2 * log(length(y)), modelParam = list(sdEta = 0, sdNu = 2, phi = .98)) res
which leads to the result:
we see that in this case we miss one changepoint.
If you have interest to contribute to this package, please do not
esitate to contact the maintainer: g
dot
romano
at lancaster.ac.uk
.