Wraps mcp::mcp() (Lindeløv): a Bayesian multiple-changepoint
regression specified as a list of formulas, one per segment. This
is the most expressive detector in the package — each segment can have its
own intercept, slope, variance and autocorrelation, and the changepoints
themselves get full posterior distributions rather than point estimates,
which ggcpt_posterior() already knows how to draw.
Arguments
- x
A numeric vector.
- change_in
Shorthand for the segment model when
modelis not given:"mean"fits a change in intercept (list(y ~ 1, ~ 1)),"slope"a change in slope (list(y ~ 1 + t, ~ 0 + t)),"var"a change in residual standard deviation (list(y ~ 1, ~ 0 + sigma(1))).- n_changepoints
Number of changepoints in the shorthand model. Defaults to
1.- model
An explicit mcp model: a list of formulas. Overrides
change_inandn_changepoints, and is the reason to reach for this engine at all.- prior
Optional named list of priors, passed to
mcp::mcp().- iter, adapt, chains
Sampler settings, passed through.
- seed
Optional seed.
- ...
Additional arguments passed to
mcp::mcp().
Value
A ggcpt object. The changepoints tibble carries the
posterior mean location together with ci_lower/ci_upper
from the posterior quantiles, and $data$fitted holds the
posterior predictive mean, so autoplot(show_ci = TRUE,
show_fit = TRUE) shows both.
JAGS is a system dependency
mcp samples through JAGS, a separate program installed outside R.
Having the package is not the same as being able to run it:
mcp imports rjags, and on some platforms rjags
installs happily and only fails when it looks for the JAGS library at run
time — in which case mcp::mcp() returns a fit carrying no
posterior samples, with a warning rather than an error. This wrapper
checks for that and says so plainly instead of failing several frames
later inside summary(). Everything else in the package works
without JAGS.
References
Lindeløv JK (2020). “mcp: An R package for regression with multiple change points.” OSF Preprints. doi:10.31219/osf.io/fzqxv .
See also
Other changepoint engines:
bcp_wrapper(),
beast_wrapper(),
bfast_wrapper(),
binsegrcpp_wrapper(),
bocpd_wrapper(),
cpm_wrapper(),
cpop_wrapper(),
cpt_wrapper(),
decafs_wrapper(),
ecp_wrapper(),
envcpt_wrapper(),
esac_wrapper(),
fabisearch_wrapper(),
fastcpd_wrapper(),
fcov_wrapper(),
fmean_wrapper(),
fpop_wrapper(),
geomcp_wrapper(),
hdcov_wrapper(),
hdreg_wrapper(),
idetect_wrapper(),
inspect_wrapper(),
kcp_wrapper(),
kwc_wrapper(),
mosum_wrapper(),
network_wrapper(),
not_wrapper(),
npmojo_wrapper(),
nsp_wrapper(),
ocd_wrapper(),
pilliat_wrapper(),
segmented_wrapper(),
smuce_wrapper(),
sn_wrapper(),
strucchange_wrapper(),
taylor_wrapper(),
tguh_wrapper(),
trend_wrapper(),
var_wrapper(),
wbs2_wrapper(),
wbs_wrapper(),
wbsts_wrapper()
Examples
# Not run by R CMD check: whether this works depends on a *system*
# library, and no test of installed R packages predicts that reliably --
# `rjags` can be present and still fail to find JAGS at run time.
if (FALSE) { # \dontrun{
set.seed(2026)
fit <- mcp_wrapper(c(rnorm(60), rnorm(60, 4)), iter = 500, adapt = 200)
fit
} # }
