Learn R Programming

glinternet (version 1.0.12)

predict.glinternet: Make predictions from a "glinternet" object.

Description

Similar to other predict methods, this function returns fitted values on the response scale. Also gives the option to return the link function.

Usage

# S3 method for glinternet
predict(object, X, type = c("response", "link"), lambda=NULL, ...)

Arguments

object

Fitted "glinternet" model object.

X

Matrix of new values for which to make predictions. Must have the same number of variables as during training the model, and all the variables must have the same number of levels.

type

Return fitted Y values or the link function.

lambda

User input lambda sequence. Must be subset of the lambdas used in fitting. If NULL (the default), predict at all the lambdas used during fitting.

Not used. Other arguments to predict.

Value

A matrix of predicted values, with columns corresponding to each fitted model.

Details

If lambda is not specified, makes predictions at all the fitted lambda values. Users may provide their own lambda sequence, but this must be a subset of the values used to fit the models.

See Also

glinternet, glinternet.cv, predict.glinternet.cv, plot.glinternet.cv

Examples

Run this code
# NOT RUN {
Y = rnorm(100)
numLevels = sample(1:5, 10, replace=TRUE)
X = sapply(numLevels, function(x) if (x==1)
rnorm(100) else sample(0:(x-1), 100, replace=TRUE))
fit = glinternet(X, Y, numLevels)
max(abs(fit$fitted - predict(fit, X)))
# }

Run the code above in your browser using DataLab