| coef.cv.rbridge | R Documentation |
Extract original-scale intercept and slope coefficients from a fitted cross-validated cv.rbridge object.
## S3 method for class 'cv.rbridge'
coef(object, s = c("lambda.1se", "lambda.min"), ...)
object |
Fitted object returned by |
s |
Penalty selection, using numeric fitted values or a character name.
Numeric values must match
The default is |
... |
Additional arguments accepted for compatibility. |
The returned matrix retains its dimensions for a single selected penalty.
The defaults differ between coef() and predict():
coefficient extraction uses lambda.1se, whereas response prediction
uses lambda.min. Specify the same s in both calls when comparing
coefficients and their predictions.
Returned slopes are on the original predictor scale; the linear
restrictions concern standardized slopes. See rbridge for
converting scales before checking restriction residuals.
Numeric matrix with p + 1 rows and one column per
selected penalty, even when only one penalty is selected. The first row
is (Intercept); subsequent rows are original-scale slopes in the
training predictor order.
Bahadir Yuzbasi
Maintainer: Bahadir Yuzbasi b.yzb@hotmail.com
predict.cv.rbridge, cv.rbridge
# 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))
# A user-specified sum of standardized slopes: b[1] + b[2] + b[5] = 6.5.
# This target is illustrative; it is not asserted to equal the generating sum.
R1.mat <- matrix(c(1, 1, 0, 0, 1, 0, 0, 0), nrow = 1)
r1.vec <- matrix(6.5, nrow = 1, ncol = 1)
# Five penalties keep this help example fast; the default is 100.
model1 <- cv.rbridge(X, y, q = 1, R = R1.mat, r = r1.vec, nlambda = 5,
nfolds = 3, num_threads = 1)
# A single selected penalty still gives a coefficient matrix.
coefficients <- coef(model1, s = "lambda.min")
coefficients
dim(coefficients)
# The default uses the historical error-bar selector.
coef(model1)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.