Get predictions from a glmnetfit fit object
predict.glmnetfit.RdGives fitted values, linear predictors, coefficients and number of non-zero
coefficients from a fitted glmnetfit object.
Arguments
- object
Fitted "glmnetfit" object.
- newx
Matrix of new values for
xat which predictions are to be made. Must be a matrix. This argument is not used fortype = c("coefficients","nonzero").- s
Value(s) of the penalty parameter lambda at which predictions are required. Default is the entire sequence used to create the model.
- type
Type of prediction required. Type "link" gives the linear predictors (eta scale); Type "response" gives the fitted values (mu scale). Type "coefficients" computes the coefficients at the requested values for s. Type "nonzero" returns a list of the indices of the nonzero coefficients for each value of s.
- exact
This argument is relevant only when predictions are made at values of
s(lambda) different from those used in the fitting of the original model. Ifexact=FALSE(default), then the predict function uses linear interpolation to make predictions for values ofs(lambda) that do not coincide with those used in the fitting algorithm. While this is often a good approximation, it can sometimes be a bit coarse. Withexact=TRUE, these different values ofsare merged (and sorted) withobject$lambda, and the model is refit before predictions are made. In this case, it is required to supply the original data x= and y= as additional named arguments to predict() or coef(). The workhorsepredict.glmnet()needs to update the model, and so needs the data used to create it. The same is true of weights, offset, penalty.factor, lower.limits, upper.limits if these were used in the original call. Failure to do so will result in an error.- newoffset
If an offset is used in the fit, then one must be supplied for making predictions (except for type="coefficients" or type="nonzero").
- ...
This is the mechanism for passing arguments like
x=whenexact=TRUE; seeexactargument.