Make Predictions from a Fitted Model Object

DESCRIPTION:

Returns a vector or array of predictions.
This function is an S Version 3 generic (see ); 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.coxph.penal, , , , , , , , , , predict.lmRobMM, , , , , predict.nls, predict.ns, , , , , predict.survReg.penal, , , .

USAGE:

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

REQUIRED ARGUMENTS:

object
a fitted model object.

OPTIONAL ARGUMENTS:

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.

OPTIONAL ARGUMENTS:

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.

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 .

WARNING:

Calling predict on objects of class "lm", "bdLm", "glm", or bdGlm 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.

SEE ALSO:

, , , .

EXAMPLES:

# extract the fitted linear predictor from a glm object  
glmob <- glm(Kyphosis ~ poly(Age, 2) + (Number > 5)*Start, 
             family = binomial, data = kyphosis) 
predict(glmob) 
predict(gamob, newdata, type = "terms")