I am fitting a logistic regression for a binary classification problem. Now I would like to find the source code of predict function and see how "predict" works.
> methods(predict)
[1] predict.ar* predict.Arima* predict.arima0*
[4] predict.glm predict.HoltWinters* predict.lm
[7] predict.loess* predict.mlm* predict.nls*
[10] predict.poly* predict.ppr* predict.prcomp*
[13] predict.princomp* predict.smooth.spline* predict.smooth.spline.fit*
[16] predict.StructTS*
see '?methods' for accessing help and source code
The predict
is a generic function that will invoke the specific predict function based on the first input argument.
Within glmnet package https://github.com/cran/glmnet/tree/master/R, there are two main predict functions -- predict.glmnet
and predict.lognet
. Predict.glm
can be found at https://github.com/SurajGupta/r-source/blob/master/src/library/stats/R/predict.glm.R. So what are the relations among predict.glm
, predict.glmnet
and predict.lognet
?
And in predict.lognet.R, there is one line:
nfit=NextMethod("predict")
It is explained in R Documentation that "NextMethod invokes the next method (determined by the class vector, either of the object supplied to the generic, or of the first argument to the function containing NextMethod if a method was invoked directly). Normally NextMethod is used with only one argument, generic, but if further arguments are supplied these modify the call to the next method."
What is "predict"
in NextMethod("predict")
? Is it calling predict.glm
?
How the prediction can be made based on a saved file .RDS model?
Thank you.