CRAN status Downloads R-CMD-check Codecov test coverage Last Commit r-universe CodeFactor


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:


# Install from CRAN

Development version

# Development version from r-universe with CRAN version as a fallback
  repos = c("", "")

## install.packages("pak")

## install.packages("devtools")

With mamba or conda (available soon)

# conda-forge is a fork from CRAN and may not be up-to-date

# Use mamba
mamba install r-fastcpd
# Use conda
conda install -c conda-forge r-fastcpd


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.

#> ── 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

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.


fastcpd cheatsheet


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 + 1] <- 0.3 * x[i + 2] + 0.4 * x[i + 1] + 0.2 * x[i] + rnorm(1, 0, 3)
result <-[3 + seq_len(n)], 3, r.progress = FALSE)
#> Call:
#> = x[3 + seq_len(n)], order = 3, r.progress = FALSE)
#> Change points:
#> 612 
#> Cost values:
#> 2748.404 2022.597 
#> Parameters:
#>     segment 1   segment 2
#> 1  0.57656238  0.13006290
#> 2 -0.21582749 -0.03084403
#> 3  0.07985424 -0.04544551

[!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.


Main function

Wrapper functions

Time series

Unlabeled data

Regression data

Utility functions


Main class

Make contributions

We welcome contributions from everyone. Please follow the instructions below to make contributions.

  1. Fork the repo.

  2. Create a new branch from main branch.

  3. Make changes and commit them.

    1. Please follow the Google’s R style guide for naming variables and functions.
    2. If you are adding a new family of models with new cost functions with corresponding gradient and Hessian, please add them to src/ with proper example and tests in vignettes/gallery.Rmd and tests/testthat/test-gallery.R.
    3. Add the family name to src/fastcpd_constants.h.
    4. [Recommended] Add a new wrapper function in R/fastcpd_wrappers.R for the new family of models and move the examples to the new wrapper function as roxygen examples.
    5. Add the new wrapper function to the corresponding section in _pkgdown.yml.
  4. Push the changes to your fork.

  5. Create a pull request.

  6. Make sure the pull request does not create new warnings or errors in devtools::check().

Contact us

Encountered a bug or unintended behavior?

  1. File a ticket at GitHub Issues.
  2. Contact the authors specified in DESCRIPTION.

Stargazers over time

Stargazers over time

Codecov Icicle

Codecov Icicle