View source: R/sparsegl-methods.R
predict.sparsegl | R Documentation |
sparsegl
object.Similar to other predict methods, this function produces fitted values and
class labels from a fitted sparsegl
object.
## S3 method for class 'sparsegl'
predict(
object,
newx,
s = NULL,
type = c("link", "response", "coefficients", "nonzero", "class"),
...
)
object |
Fitted |
newx |
Matrix of new values for |
s |
Value(s) of the penalty parameter |
type |
Type of prediction required. Type |
... |
Not used. |
s
is the new vector of lambda
values at which predictions are requested.
If s
is not in the lambda sequence used for fitting the model, the coef
function will use linear interpolation to make predictions. The new values
are interpolated using a fraction of coefficients from both left and right
lambda
indices.
The object returned depends on type.
sparsegl()
, coef.sparsegl()
.
n <- 100
p <- 20
X <- matrix(rnorm(n * p), nrow = n)
eps <- rnorm(n)
beta_star <- c(rep(5, 5), c(5, -5, 2, 0, 0), rep(-5, 5), rep(0, (p - 15)))
y <- X %*% beta_star + eps
groups <- rep(1:(p / 5), each = 5)
fit1 <- sparsegl(X, y, group = groups)
predict(fit1, newx = X[10, ], s = fit1$lambda[3:5])
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.