mcp is regression with multiple change points, inferring full Bayesian uncertainty for all parameters, including
the change points themselves. At its simplest, it feels like lm() with one formula per segment. At its most
flexible, it aims to be brms for change points:
GLMM and distributional regression: Gaussian, binomial, Bernoulli, Poisson, and Negative Binomial families. Group-level (random) effects, AR/MA, and regression on distributional parameters (e.g.,
sigma,shape).Express expert knowledge: Specify the number of change points, the form of each segment, and restrict coefficients via priors. Compare hypotheses using
loo()andhypothesis().Native feel:
summary(),plot_pars(),pp_check(), andas_draws_df()follow the conventions ofbrms,rstanarm, andposterior, adapted to change point regression. Inspect the sampled JAGS model infit$jags_code.
You will find many aliases for change point regression in the literature, including piecewise linear, discontinuity, segmented, and broken stick regression.
See mcp() to fit models, mcp-formula for the model and formula syntax, and mcp-priors for priors.
Extended formulas and model features - and links to worked examples
Distributional regression: Model residual variance and other distributional parameters across segments, e.g.,
~ sigma(1 + x)or~ shape(1). Read more.Time-series residuals: Model serial dependence using
ar(p)andma(q)terms with a generalized link-scale recurrence. Read more.Group-level effects: Add hierarchical (random) intercepts, slopes, and change points, e.g.,
~ 1 + (1|id)or~ cp((1|id)) + 0 + x. Read more.Families: Binomial, Bernoulli, Poisson, and negative-binomial responses with several link functions. Read more.
Model comparison and hypothesis testing: Compare models using PSIS-LOO (
loo()) or WAIC (waic()), and test hypotheses (hypothesis()) using Savage-Dickey density ratios for point-null tests or posterior-to-prior odds for directional tests. Read more.Fits, predictions, and forecasts:
fitted(),predict(), andresiduals(), including forecasts beyond the data. Read more.Missing responses: Missing values in the response are imputed jointly with the parameters. Read more.
Options
mcp_quiet: Logical. The default ofmcp(..., quiet).options(mcp_quiet = TRUE)suppresses routine JAGS output and mcp sampling-status messages for the session.mcp_reparam: Logical.TRUE(default) letsmcp()sample some default priors on scales that mix faster. This changes onlyfit$jags_codeand sampling efficiency, not the model, the priors, or the posterior.options(mcp_reparam = FALSE)writes the plain model, which is mostly useful for seeing howmcpworks. Ignored whenjags_codeis supplied. Read more in From formulas to sampler code.
References
Lindeløv, J. K. (2020). mcp: An R Package for Regression With Multiple Change Points. OSF Preprints. doi:10.31219/osf.io/fzqxv Introduces the
mcppackage, formula syntax, default priors, and workflow for regression with multiple change points across generalized linear and time-series models. Newer-than-2020 versions of the paper may be available at that link. Please cite the newest version.Carlin, B. P., Gelfand, A. E., & Smith, A. F. (1992). Hierarchical Bayesian Analysis of Changepoint Problems. Applied Statistics, 41(2), 389–405. doi:10.2307/2347570 Introduced Gibbs sampling for hierarchical Bayesian change-point models, the computational approach that BUGS and JAGS build on.
Author
Jonas Kristoffer Lindeløv jonas@lindeloev.dk
