| cv.bridge | R Documentation |
Evaluate a fitted penalty path using contiguous validation folds and return the full-data coefficients together with two penalty selectors.
cv.bridge(
X,
y,
q,
lambda,
nfolds = 10,
lambda.min = ifelse(n > p, 0.001, 0.05),
nlambda = 100,
eta = 1e-07,
converge = 10^10,
num_threads = 10
)
X |
Numeric design matrix with |
y |
Numeric response vector of length |
q |
Bridge-penalty exponent, a finite number in |
lambda |
Optional nonempty numeric vector of finite, nonnegative penalty
values. Its order is retained. When supplied, it determines the fitted path
and overrides |
nfolds |
Number of validation folds, an integer between 2 and
|
lambda.min |
Positive absolute endpoint of the automatically generated
penalty grid. The default is |
nlambda |
Number of automatically generated penalty values, an integer
of at least 2. The default is |
eta |
Positive numerical tolerance, with default |
converge |
Nonnegative initial convergence-distance value, retained for
compatibility. The default is |
num_threads |
Requested fold-level workers, a positive integer.
The default is |
Fold assignment follows the supplied row order. The nfolds
validation sets are contiguous blocks; their sizes can differ by one.
Centering and RMS scaling use all observations before fold allocation,
and each fold fit also reconstructs its training-set intercept.
These historical preprocessing and error-bar conventions are retained.
The reported validation error aggregates held-out predictions at each
fitted penalty, and coefficients in betas come from a final fit
to all observations.
For one fixed penalty, let K be nfolds, n the total
observation count, I_k the validation indices in fold k,
and e_i the held-out response residual for observation i.
Equation (1) defines a fold's error contribution d_k, the pooled
validation MSE, and the historical error-bar width:
\begin{aligned}
d_k&=\frac{1}{n}\sum_{i\in I_k}e_i^2,\\
\mathrm{cve}&=\sum_{k=1}^{K}d_k,\\
\mathrm{cvse}&=\sqrt{\frac{1}{K(n-1)}
\sum_{k=1}^{K}(d_k-\mathrm{cve})^2}. \qquad (1)
\end{aligned}
The folds partition all observations, so the sum in Equation (1) weights
each held-out observation equally. The final quantity supplies the plotted
bar width and the historical lambda.1se threshold. Its centering
uses the pooled cve, not the average fold contribution, and it is
not a conventional foldwise standard error.
predict() defaults to the minimum-error penalty lambda.min.
coef() defaults to lambda.1se. Supply s explicitly
to use the same penalty for both operations.
Use plot() to inspect the curve, error bars and selected penalties.
A list of class cv.bridge with components:
cve |
Numeric vector of validation mean squared errors, one per penalty. Squared holdout residuals are summed across folds and divided by the total observation count, so each observation has the same weight. |
cvse |
Numeric vector from the historical CV error-bar calculation. It is not the conventional standard error of foldwise mean squared errors. |
cvup, cvlo |
Upper and lower curves, computed as |
lambda |
Numeric penalty vector in fitted order. |
nz |
Number of nonzero slopes, excluding the intercept, in each full-data fit. |
betas |
Full-data coefficient matrix with |
lambda.min |
Fitted penalty with the smallest |
lambda.1se |
Largest fitted penalty whose |
Bahadir Yuzbasi
Maintainer: Bahadir Yuzbasi b.yzb@hotmail.com
bridge, plot.cv.bridge, coef.cv.bridge, predict.cv.bridge
# Reproducible synthetic demonstration: 100 observations, eight predictors.
set.seed(2019)
beta <- c(3, 1.5, 0, 0, 2, 0, 0, 0)
p <- length(beta)
beta <- matrix(beta, nrow = p, ncol = 1)
n <- 100
X <- matrix(rnorm(n * p), nrow = n, ncol = p)
y <- as.numeric(X %*% beta + rnorm(n))
# Five penalties keep this help example fast; the default is 100.
# Three contiguous folds and one worker keep this demonstration small.
model1 <- cv.bridge(X, y, q = 1,
nlambda = 5, nfolds = 3, num_threads = 1)
model2 <- cv.bridge(X, y, q = 2,
nlambda = 5, nfolds = 3, num_threads = 1)
# Inspect both selectors and explicitly choose the minimum-error fit.
c(minimum_error = model1$lambda.min, historical_1se = model1$lambda.1se)
coef(model1, s = "lambda.min")
predict(model1, newx = X[1:5, , drop = FALSE], s = "lambda.min")
plot(model1)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.