pcplus | R Documentation |
Computes the PCpluS estimator F. Pein (2021) for a given bandwidth and the penalty lambda. Bandwidth and lambda can be obtained by cross-validation using the function cv.pcplus
. The PCpluS estimator returns a piecewise constant function plus a smooth function as well as the change-points of the piecewise constant function.
pcplus(y, bandwidth, lambda, sd = NULL, nlambda = 30L, thresh = 1e-7, maxit = 1e5L)
y |
a numeric vector containing the observations, only finite values are allowed |
bandwidth |
a single positive value specifying the bandwidth for the kernel smoother; must be between |
lambda |
a single positive numeric or a decreasing sequence of positive numeric values giving the penalty for the fused lasso. If a sequence is passed, then only the smallest value is used to compute the estimator. However, passing a sequence of lambda values is often much faster than passing a single value |
sd |
a single positive value giving the standard deviation of the observations; may be |
nlambda |
a single positive integer specifying the number of lambda values to pass to the lasso; only used if |
thresh |
a single positive numeric value giving a convergence threshold for coordinate descent. Each inner coordinate-descent loop continues until the maximum change in the objective after any coefficient update is less than |
maxit |
a single positive integer giving the maximum number of passes over the data for all lambda values |
a list
containing the entries est
with the fitted values of the esitmator, smooth
with the smooth part of the estimator, cpfun
with the change-point part of the estimator, and cps
with the estimated change-point locations.
Pein, F. (2021). Change-point regression with a smooth additive disturbance. arXiv preprint arXiv:2112.03878.
cv.pcplus
library(PCpluS)
set.seed(1)
y <- c(rnorm(125), rnorm(125, 3)) + sin(2 * pi * 1:250 / 250)
CV <- cv.pcplus(y)
ret <- pcplus(y, lambda = CV$lambda, bandwidth = CV$bandwidth)
plot(y, pch = 16)
lines(ret$est, col = "red")
abline(v = ret$cps)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.