| cpt_segment_models | R Documentation |
Detection says where the regimes change; this fits your model to
each regime. Every segment of fit gets its own copy of
model, fitted by engine to that segment's rows, and the
result is a table with one fitted model per segment that
tidy(), glance() and predict() read.
cpt_segment_models(fit, model = NULL, data = NULL, engine = stats::lm, ...)
## S3 method for class 'ggcpt_segment_models'
tidy(x, conf_level = 0.95, ...)
## S3 method for class 'ggcpt_segment_models'
glance(x, ...)
## S3 method for class 'ggcpt_segment_models'
print(x, ...)
fit |
A |
model |
A formula. For a result from a formula fit it defaults to
that formula; for a series it defaults to |
data |
Optional data frame with one row per observation, supplying covariates the model uses. For a formula fit the covariates are taken from the result. |
engine |
The fitting function, called as |
... |
Further arguments for |
x |
A |
conf_level |
Confidence level for the coefficient intervals. |
A ggcpt_segment_models tibble with one row per segment:
segment, start, end, n and model (a
list-column of fitted models, NULL where the fit failed).
tidy() gives the coefficient table with a segment
column; glance() one row per segment with n,
sigma, r_squared, AIC, BIC and
logLik.
predict.ggcpt() to forecast from a segment,
tidy.ggcpt(what = "coefficients") for the coefficients
the detection itself implies.
Other segment models:
cpt_counterfactual(),
predict.ggcpt()
set.seed(1)
d <- data.frame(x = runif(200))
d$y <- ifelse(seq_len(200) <= 100, 1 + 2 * d$x, 3 - d$x) + rnorm(200, 0, 0.3)
fit <- cpt_detect(y ~ x, data = d, method = "strucchange")
sm <- cpt_segment_models(fit)
tidy(sm)
glance(sm)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.