Learn R Programming

tidychangepoint

Usage

To install tidychangepoint from CRAN:

install.packages("tidychangepoint")

To install the development version of tidychangepoint:

remotes::install_github("beanumber/tidychangepoint")

To load it:

library(tidychangepoint)

Tidy methods for changepoint analysis

The tidychangepoint package allows you to use any number of algorithms for detecting changepoint sets in univariate time series with a common, tidyverse-compliant interface. Currently, algorithms from changepoint, wbs, and several genetic algorithms made accessible via GA are supported. It also provides model-fitting procedures for commonly-used parametric models, tools for computing various penalty functions, and graphical diagnostic displays.

Changepoint sets are computed using the segment() function, which takes a numeric vector that is coercible into a ts object, and a string indicating the algorithm you wish you use. segment() always returns a tidycpt object.

x <- segment(CET, method = "pelt", model = fit_meanshift_norm, minseglen = 3)
class(x)
## [1] "tidycpt"

Various methods are available for tidycpt objects. For example, as.ts() returns the original data as ts object, and changepoints() returns the set of changepoint indices.

changepoints(x)
## [1] 330

If the original time series has time labels, we can also retrieve that information.

changepoints(x, use_labels = TRUE)
## [1] "1988-01-01"

The fitness() function returns the both the value and the name of the objective function that the algorithm used to find the optimal changepoint set.

fitness(x)
##    MBIC 
## 688.331

The tidy() method shows the fitted parameters values for each region.

tidy(x)
## Registered S3 method overwritten by 'tsibble':
##   method               from 
##   as_tibble.grouped_df dplyr

## # A tibble: 2 × 9
##   region    num_obs   min   max  mean    sd begin   end param_mu
##   <chr>       <int> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>    <dbl>
## 1 [1,330)       329  6.86  10.6  9.17 0.615     1   330     9.17
## 2 [330,367)      37  8.95  11.2 10.3  0.528   330   367    10.3

Algorithmic coverage

ls_methods()
## # A tibble: 12 × 5
##    method      pkg             segmenter_class helper              wraps        
##    <chr>       <chr>           <chr>           <chr>               <chr>        
##  1 pelt        changepoint     cpt             segment_pelt()      changepoint:…
##  2 binseg      changepoint     cpt             <NA>                changepoint:…
##  3 segneigh    changepoint     cpt             <NA>                changepoint:…
##  4 single-best changepoint     cpt             <NA>                changepoint:…
##  5 wbs         wbs             wbs             <NA>                wbs::wbs()   
##  6 ga          GA              tidyga          segment_ga()        GA::ga()     
##  7 ga-shi      GA              tidyga          segment_ga_shi()    segment_ga() 
##  8 ga-coen     GA              tidyga          segment_ga_coen()   segment_ga() 
##  9 coen        tidychangepoint seg_basket      segment_coen()      <NA>         
## 10 random      GA              tidyga          segment_ga_random() segment_ga() 
## 11 manual      tidychangepoint seg_cpt         segment_manual()    <NA>         
## 12 null        tidychangepoint seg_cpt         segment_manual()    <NA>
ls_coverage() |>
  dplyr::group_by(method) |>
  dplyr::summarize(
    models = paste(unique(model), collapse = ", "),
    penalties = paste(unique(penalty), collapse = ", ")
  ) |>
  dplyr::arrange(method) |>
  knitr::kable()
methodmodelspenalties
binsegfit_meanvarNone, SIC, BIC, MBIC, AIC, HQC, Asymptotic, Manual, CROPS
coenfit_nhppBMDL
gafit_lmshift, fit_lmshift_ar1, fit_meanshift_lnorm, fit_meanshift_norm, fit_meanshift_norm_ar1, fit_meanvar, fit_nhpp, fit_trendshift, fit_trendshift_ar1SIC, AIC, BIC, HQC, MBIC, MDL
ga-coenfit_nhppBMDL
ga-shifit_meanshift_norm_ar1BIC
manualfit_meanshift_normBIC
nullfit_meanshift_normBIC
peltfit_meanshift_norm, fit_meanvarNone, SIC, BIC, MBIC, AIC, HQC, Asymptotic, Manual, CROPS
randomfit_lmshift, fit_lmshift_ar1, fit_meanshift_lnorm, fit_meanshift_norm, fit_meanshift_norm_ar1, fit_meanvar, fit_nhpp, fit_trendshift, fit_trendshift_ar1SIC, AIC, BIC, HQC, MBIC, MDL
segneighfit_meanvarNone, SIC, BIC, MBIC, AIC, HQC, Asymptotic, Manual, CROPS
single-bestfit_meanvarNone, SIC, BIC, MBIC, AIC, HQC, Asymptotic, Manual, CROPS
wbsNANA

References

Please read the full paper for more details.

To cite the package, use the following information:

citation("tidychangepoint")
## Warning in citation("tidychangepoint"): could not determine year for
## 'tidychangepoint' from package DESCRIPTION file

## To cite package 'tidychangepoint' in publications use:
## 
##   Baumer B, Suárez Sierra B, Coen A, Taimal C (????). _tidychangepoint:
##   A Tidy Framework for Changepoint Detection Analysis_. R package
##   version 0.0.1.9002, <https://beanumber.github.io/tidychangepoint/>.
## 
## A BibTeX entry for LaTeX users is
## 
##   @Manual{,
##     title = {tidychangepoint: A Tidy Framework for Changepoint Detection Analysis},
##     author = {Benjamin S. Baumer and Biviana Marcela {Suárez Sierra} and Arrigo Coen and Carlos A. Taimal},
##     note = {R package version 0.0.1.9002},
##     url = {https://beanumber.github.io/tidychangepoint/},
##   }

Copy Link

Version

Install

install.packages('tidychangepoint')

Monthly Downloads

253

Version

1.0.0

License

GPL (>= 3)

Maintainer

Ben Baumer

Last Published

January 31st, 2025

Functions in tidychangepoint (1.0.0)

changepoints

Extract changepoints
cut_by_tau

Use a changepoint set to break a time series into regions
evaluate_cpts

Evaluate candidate changepoints sets
deg_free

Retrieve the degrees of freedom from a logLik object
ls_models

Algorithmic coverage through tidychangepoint
new_fun_cpt

Class for model-fitting functions
mlb_diffs

Differences between leagues in Major League Baseball
diagnose

Diagnose the fit of a segmented time series
exceedances

Compute exceedances of a threshold for a time series
mcdf

Cumulative distribution of the exceedances of a time series
file_name

Obtain a descriptive filename for a tidycpt object
model_variance

Compute model variance
model_name

Retrieve the name of the model that a segmenter or model used
mde_rain

Rainfall in Medellín, Colombia
italy_grads

Italian University graduates by disciplinary groups from 1926-2013
new_seg_basket

Default class for candidate changepoint sets
fit_meanvar

Fit a model for mean and variance
fit_meanshift

Fast implementation of meanshift model
fit_nhpp

Fit a non-homogeneous Poisson process model to the exceedances of a time series.
model_args

Retrieve the arguments that a model-fitting function used
fit_nhpp_region

Fit an NHPP model to one specific region
iweibull

Weibull distribution functions
plot_best_chromosome

Diagnostic plots for seg_basket objects
seg_params

Retrieve parameters from a segmenter
fit_lmshift

Regression-based model fitting
new_mod_cpt

Base class for changepoint models
segment_manual

Manually segment a time series
log_likelihood_region_weibull

Log-Likelihood functions for regions (Weibull)
plot_intensity

Plot the intensity of an NHPP fit
plot.tidyga

Plot GA information
pad_tau

Pad and unpad changepoint sets with boundary points
tidychangepoint-package

tidychangepoint: A Tidy Framework for Changepoint Detection Analysis
segment_ga

Segment a time series using a genetic algorithm
segment_coen

Algoritmo genético de Bayesian MDL a un paso
test_set

Simulate time series with known changepoint sets
segment

Segment a time series using a variety of algorithms
new_seg_cpt

Base class for segmenters
tau2time

Convert changepoint sets to time indices
segment_pelt

Segment a time series using the PELT algorithm
tbl_coef

Format the coefficients from a linear model as a tibble
fitness

Retrieve the optimal fitness (or objective function) value used by an algorithm
whomademe

Recover the function that created a model
as.ts.mod_cpt

Objects exported from other packages
regions

Extract the regions from a tidycpt object
tidycpt-class

Container class for tidycpt objects
vec_ptype2.logLik.logLik

Vectors implementation for logLik
as_year

Convert a date into a year
MBIC

Modified Bayesian Information Criterion
CET

Hadley Centre Central England Temperature
as.segmenter

Convert, retrieve, or verify a segmenter object
SIC

Schwarz information criterion
BMDL

Bayesian Maximum Descriptive Length
MDL

Maximum Descriptive Length
as.model

Convert, retrieve, or verify a model object
HQC

Hannan–Quinn information criterion
DataCPSim

Simulated time series data
compare_models

Compare various models or algorithms for a given changepoint set
build_gabin_population

Initialize populations in genetic algorithms
evolve_gbmdl

Generate a list of candidate changepoints using a genetic algorithm
binary2tau

Convert changepoint sets to binary strings
bogota_pm

Particulate matter in Bogotá, Colombia