tau: a set of indices representing a changepoint set
deg_poly: integer indicating the degree of the polynomial spline to be fit. Passed to stats::poly().
...: arguments passed to stats::lm()
Returns
A mod_cpt object
Details
These model-fitting functions use stats::lm() to fit the corresponding regression model to a time series, using the changepoints specified by the tau argument. Each changepoint is treated as a categorical fixed-effect, while the deg_poly
argument controls the degree of the polynomial that interacts with those fixed-effects. For example, setting deg_poly equal to 0 will return the same model as calling fit_meanshift_norm(), but the latter is faster for larger changepoint sets because it doesn't have to fit all of the regression models.
Setting deg_poly equal to 1 fits the trendshift model.
fit_lmshift_ar1(): will apply auto-regressive lag 1 errors
fit_trendshift(): will fit a line in each region
fit_trendshift_ar1(): will fit a line in each region and autoregress lag 1 errors
Examples
# Manually specify a changepoint settau <- c(365,826)# Fit the modelmod <- fit_lmshift(DataCPSim, tau)# Retrieve model parameterslogLik(mod)deg_free(mod)# Manually specify a changepoint setcpts <- c(1700,1739,1988)ids <- time2tau(cpts, as_year(time(CET)))# Fit the modelmod <- fit_lmshift(CET, tau = ids)# View model parametersglance(mod)glance(fit_lmshift(CET, tau = ids, deg_poly =1))glance(fit_lmshift_ar1(CET, tau = ids))glance(fit_lmshift_ar1(CET, tau = ids, deg_poly =1))glance(fit_lmshift_ar1(CET, tau = ids, deg_poly =2))# Empty changepoint sets are allowedfit_lmshift(CET, tau =NULL)# Duplicate changepoints are removedfit_lmshift(CET, tau = c(42,42))
See Also
Other model-fitting: fit_meanshift(), fit_meanvar(), fit_nhpp(), model_args(), model_name(), new_fun_cpt(), whomademe()