Skip to contents

This function predicts values based on glmnet model objects.

Usage

forecast_by_glmnet(
  object,
  newx,
  type = c("link", "response", "coefficients", "class", "nonzero"),
  newoffset,
  s,
  lambda,
  gamma,
  ...
)

Arguments

object

an object of class Trained

newx

Matrix of new values for x at which predictions are to be made. Must be a matrix; can be sparse as in Matrix package. This argument is not used for type=c("coefficients","nonzero")

type

Type of prediction required. Type "link" gives the linear predictors for "binomial", "multinomial", "poisson" or "cox" models; for "gaussian" models it gives the fitted values. Type "response" gives the fitted probabilities for "binomial" or "multinomial", fitted mean for "poisson" and the fitted relative-risk for "cox"; for "gaussian" type "response" is equivalent to type "link". Type "coefficients" computes the coefficients at the requested values for s. Note that for "binomial" models, results are returned only for the class corresponding to the second level of the factor response. Type "class" applies only to "binomial" or "multinomial" models, and produces the class label corresponding to the maximum probability. Type "nonzero" returns a list of the indices of the nonzero coefficients for each value of s.

newoffset

If an offset is used in the fit, then one must be supplied for making predictions (except for type="coefficients" or type="nonzero")

s

Value(s) of the penalty parameter lambda at which predictions are required. Default is the entire sequence used to create the model.

lambda

(optional) value of the penalty parameter. Used if s is not provided

gamma

Single value of gamma at which predictions are required, for "relaxed" objects.

...

further arguments to predict.glmnet

Value

A vector containing the predictions.

See also

Author

Alessandro Barberis