| predict.bridge | R Documentation |
Compute response predictions, extract coefficients, or identify nonzero predictors from a fitted bridge object.
## S3 method for class 'bridge'
predict(
object,
newx,
s = c("lambda.min", "lambda.1se"),
type = c("response", "nonzero", "coefficients"),
...
)
object |
Fitted object returned by |
newx |
Numeric matrix with one row per new observation and the
same |
s |
Numeric fitted penalty value(s).
Values must match The character selector |
type |
Output to return: |
... |
Additional arguments accepted for compatibility. |
Prediction uses the fitted intercept and original-scale slopes.
Columns of newx are matched by position, not reordered by their names.
For type = "nonzero", all fitted penalties are inspected and
s does not restrict the returned indices.
For type = "response", a numeric vector for one
selected penalty or a matrix with one row per new observation and one
column per selected penalty. For type = "coefficients", a numeric
matrix with p + 1 rows, including the intercept, even for one penalty.
For type = "nonzero", a pathwise collection of 1-based predictor
indices excluding the intercept. Its historical container can simplify
depending on the support pattern and number of predictors.
Bahadir Yuzbasi
Maintainer: Bahadir Yuzbasi b.yzb@hotmail.com
coef.bridge, 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.
model1 <- bridge(X, y, q = 1, nlambda = 5)
# Predict five observations at one explicitly selected penalty.
predict(model1, newx = X[1:5, , drop = FALSE], s = model1$lambda[2])
# Extract coefficients using the complete type name.
predict(model1, s = model1$lambda[2], type = "coefficients")
# Predictor indices for every fitted penalty; the intercept is excluded.
predict(model1, type = "nonzero")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.