The fastcpd (fast change point detection) is a fast implmentation of change point detection methods in R. The fastcpd package is designed to find change points in a fast manner. It is easy to install and extensible to all kinds of change point problems with a user specified cost function apart from the built-in cost functions.
To learn more behind the algorithms:
Development version
# Development version from r-universe with CRAN version as a fallback
install.packages(
"fastcpd",
repos = c("https://doccstat.r-universe.dev", "https://cloud.r-project.org")
)
## install.packages("pak")
pak::pak("doccstat/fastcpd")
## install.packages("devtools")
devtools::install_github("doccstat/fastcpd")
With mamba or conda (available soon)
Package dependencies
fastcpd
depends on the following packages:
If you’re compiling from source, you can run the following command to see the complete set of system packages needed on your machine.
pak::pkg_sysreqs("doccstat/fastcpd")
#> ── Install scripts ───────────────────────────────────────────── Ubuntu 20.04
#> apt-get -y update
#> apt-get -y install libcurl4-openssl-dev libssl-dev zlib1g-dev make
#>
#> ── Packages and their system dependencies ───────────────────────────────────
#> curl – libcurl4-openssl-dev, libssl-dev
#> data.table – zlib1g-dev
#> fs – make
#> openssl – libssl-dev
Should I install suggested packages?
The suggested packages are not required for the main functionality of the package. They are only required for the vignettes. If you want to learn more about the package comparison and other vignettes, you could either check out vignettes on CRAN or pkgdown generated documentation.
I countered problems related to gfortran on Mac OSX or Linux!
The package should be able to install on Mac and any Linux distribution without any problems if all the dependencies are installed. However, if you encountered problems related to gfortran, it might be because RcppArmadillo
is not installed previously. Try Mac OSX stackoverflow solution or Linux stackover solution if you have trouble installing RcppArmadillo
.
Available soon: rshiny.fastcpd.xingchi.li
set.seed(1)
n <- 1000
x <- rep(0, n + 3)
for (i in 1:600) {
x[i + 3] <- 0.6 * x[i + 2] - 0.2 * x[i + 1] + 0.1 * x[i] + rnorm(1, 0, 3)
}
for (i in 601:1000) {
x[i + 3] <- 0.3 * x[i + 2] + 0.4 * x[i + 1] + 0.2 * x[i] + rnorm(1, 0, 3)
}
result <- fastcpd::fastcpd.ar(x[3 + seq_len(n)], 3, r.progress = FALSE)
summary(result)
#>
#> Call:
#> fastcpd::fastcpd.ar(data = x[3 + seq_len(n)], order = 3, r.progress = FALSE)
#>
#> Change points:
#> 614
#>
#> Cost values:
#> 2743.759 2028.588
#>
#> Parameters:
#> segment 1 segment 2
#> 1 0.57120256 0.2371809
#> 2 -0.20985108 0.4031244
#> 3 0.08221978 0.2290323
plot(result)
Tip
It is hard to demonstrate all the features of fastcpd
in a single example due to the flexibility of the package. For more examples, please refer to the function reference.
Note
r.progress = FALSE
is used to suppress the progress bar. Users are expected to see the progress bar when running the code by default.
fastcpd_ar
fastcpd_arima
fastcpd_arma
fastcpd_garch
fastcpd_var
fastcpd_ts
fastcpd_mean
fastcpd_variance
fastcpd_meanvariance
fastcpd_binomial
fastcpd_lasso
fastcpd_lm
fastcpd_poisson
variance_arma
variance_lm
variance_mean
variance_median
bitcoin
occupancy
transcriptome
uk_seatbelts
well_log
We welcome contributions from everyone. Please follow the instructions below to make contributions.
Fork the repo.
Create a new branch from main
branch.
Make changes and commit them.
src/fastcpd_class_cost.cc
with proper example and tests in vignettes/gallery.Rmd
and tests/testthat/test-gallery.R
.src/fastcpd_constants.h
.R/fastcpd_wrappers.R
for the new family of models and move the examples to the new wrapper function as roxygen examples._pkgdown.yml
.Push the changes to your fork.
Create a pull request.
Make sure the pull request does not create new warnings or errors in devtools::check()
.
Encountered a bug or unintended behavior?