predict
Make Predictions from a Fitted Model Object

Description

Returns a vector or array of predictions.
This function is an S Version 3 generic (see Methods); method functions can be written to handle specific S Version 3 classes of data. Classes that already have methods for this function include: predict.bs, predict.censorReg, predict.coxph.penal, predict.coxph, predict.discrim, predict.factanal, predict.gam, predict.glm, predict.gls, predict.gnls, predict.lm, predict.lmList, predict.lmRobMM, predict.lme, predict.loess, predict.mlm, predict.nlme, predict.nls, predict.ns, predict.princomp, predict.princomp, predict.smooth.spline.fit, predict.smooth.spline, predict.survReg.penal, predict.survReg, predict.survreg, predict.tree.

Usage

predict(object, ...)
predict(object, newdata, ...) # most methods have second argument newdata
predict(object, newx, ...)    # some methods have second argument newx

Arguments

object a fitted model object.
newdata, newx Most methods have an optional second argument named newdata or newx indicating new data (explanatory variables) for which predictions are desired. If omitted then predictions (fitted values) for the original data are returned.
Value
depends on the method; typically a vector or array of predictions, a list consisting of the predictions and their standard errors, or a list containing x and y components of points on a prediction curve.
A standard use of predict is to simply extract the fitted values from a fit object, or in the case of generalized models, to extract the linear or additive predictor.
Warning
Calling predict on objects of class "lm" or "glm" can produce incorrect predictions when the newdata argument is used if the formula in object involves data-dependent transformations, such as poly(Age, 3) or sqrt(Age - min(Age)). The predict.gam method overcomes this for the gam, glm, and lm classes. In other cases, this can be overcome by explicitly supplying the derived matrix for predictions, rather than a data frame.
Note
Argument lists and detailed information are available by clicking the link on the specific method you are currently working with. For example, if you have a linear model object testdata.lm <- lm(y ~ x1 + x2, data=testdata) and you wish to use predict(), then click the link for predict.lm.
See Also
expand.grid, fitted, predict.gam, predict.glm.
Examples
# extract the fitted linear predictor from a glm object
glmob <- glm(Kyphosis ~ poly(Age, 2) + (Number > 5)*Start,
    family=binomial, data=Sdatasets::kyphosis)
predict(glmob)
newdata <- Sdatasets::kyphosis[11:20,]
predict(glmob, newdata, type = "terms")
Package stats version 6.1.4-13
Package Index