cvpcplus | R Documentation |
Selects the tuning parameters, bandwidth and the penalty lambda, of the PCpluS estimator F. Pein (2021). The values obtained can be used in the estimator pcplus
.
cv.pcplus(y, bandwidth, lambda, nbandwidth = 30L, nlambda = 30L,
lambda.min.ratio = 0.01, sd = NULL, thresh = 1e-7, maxit = 1e5L)
y |
a numeric vector containing the observations, only finite values are allowed |
bandwidth |
a numeric vector specifying possible values for the bandwidth of the kernel smoother; each entry must be between |
lambda |
a decreasing sequence of numerics specifying possible values for the penalty penalty of the fused lasso; each value must be positive. If missing an exponential grid of length |
nbandwidth |
a single integer giving the length of the grid for |
nlambda |
a single integer giving the length of the grid for |
lambda.min.ratio |
a single numeric between |
sd |
a single positive value giving the standard deviation of the observations; may be |
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 lambda
and bandwidth
giving the best parameter for the tuning parameters. Both can be passed directly to pcplus
. Note that lambda
is a decaying sequence instead of a single value. This improves the runtime of the estimator. The last value is the suggested tuning parameter. Furthermoore, it has the entries cv
with the loss for the selected parameters, bandwidths
with the grid of bandwidths used, and cvs
with the loss for all bandwidths.
Pein, F. (2021). Change-point regression with a smooth additive disturbance. arXiv preprint arXiv:2112.03878.
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.