| cpt_select | R Documentation |
Builds a ladder of candidate segmentations with K = 0, 1, \ldots
changepoints and scores each one, returning the chosen K, the
criterion curve behind the choice, and the fitted result at that K.
Five criteria are available, including the consistent sample-splitting
cross-validation of Zou, Wang and Li (2020) and the segment-length mBIC of
Zhang and Siegmund (2007).
cpt_select(
x,
method = "pelt",
criterion = c("bic", "mbic", "aic", "crops_elbow", "cv", "stability"),
k_max = 20,
folds = 5,
B = 100,
change_in = "mean",
index = NULL,
seed = NULL,
...
)
## S3 method for class 'ggcpt_selection'
print(x, ...)
## S3 method for class 'ggcpt_selection'
tidy(x, ...)
## S3 method for class 'ggcpt_selection'
autoplot(
object,
plot_type = c("criterion", "segmentation", "ladder"),
max_facets = 12,
...
)
x |
A numeric vector, or a |
method |
Detection method used to build the candidate ladder.
Defaults to |
criterion |
Which criterion selects
|
k_max |
Largest number of changepoints considered. Defaults to
|
folds |
Folds for |
B |
Bootstrap replicates for |
change_in |
Passed to the detector, and inherited from The three closed-form criteria assume a change in the mean
whatever this is set to. |
index |
Optional time index (a vector of dates, or a |
seed |
Optional seed. The seed is scoped to this call:
|
... |
Additional arguments passed to |
object |
A |
plot_type |
|
max_facets |
Maximum number of rungs drawn by
|
A ggcpt_selection object: a list with
criterion_table (one row per candidate K: k,
value, cost, chosen, and a cpts
list-column), k (the chosen number), fit (the
ggcpt at that K), criterion and data.
Methods: print(), tidy() and autoplot() with
plot_type = "criterion", "segmentation" or
"ladder".
zou2020coppsggchangepoint
\insertRefzhang2007mbicggchangepoint
\insertRefhaynes2017cropsggchangepoint
cpt_crops(), cpt_penalty(),
cpt_sensitivity().
set.seed(2026)
x <- c(rnorm(80), rnorm(80, 4), rnorm(80, 1))
sel <- cpt_select(x, criterion = "bic", k_max = 6)
sel
ggplot2::autoplot(sel)
ggplot2::autoplot(sel, plot_type = "ladder")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.