Make Predictions from a Fitted GAM Object

DESCRIPTION:
Provides a "safe" method of prediction from a fitted GAM object.

USAGE:
predict.gam(object, newdata, type, se.fit = F, terms)

REQUIRED ARGUMENTS:
object:
a fitted gam object, or one of its inheritants, such as a glm or lm object.

OPTIONAL ARGUMENTS:
newdata:
a data frame containing the values at which predictions are required. This argument can be missing, in which case predictions are made at the same values used to compute the object. Only those predictors, referred to in the right side of the formula in object need be present by name in newdata.
type:
type of predictions, with choices "link" (the default), "response", or "terms". The default produces predictions on the scale of the additive predictors, and with newdata missing, predict() is simply an extractor function for this component of a gam object. If "response" is selected, the predictions are on the scale of the response, and are monotone transformations of the additive predictors, using the inverse link function. If type="terms" is selected, a matrix of predictions is produced, one column for each term in the model.
se.fit:
if TRUE, pointwise standard errors are computed along with the predictions.
terms:
if type="terms", the terms= argument can be used to specify which terms should be included; the default is labels(object).

VALUE:
a vector or matrix of predictions, or a list consisting of the predictions and their standard errors if se.fit = T. If type="terms", a matrix of fitted terms is produced, with one column for each term in the model (or subset of these if the terms= argument is used). There is no column for the intercept, if present in the model, and each of the terms is centered so that their average over the original data is zero. The matrix of fitted terms has a "constant" attribute which, when added to the sum of these centered terms, gives the additive predictor. See the documentation of predict() for more details on the components returned.

DETAILS:
This function is a method for the generic function predict for class "gam". It can be invoked by calling predict for an object of the appropriate class, or directly by calling predict.gam regardless of the class of the object.

This is a safe method of prediction for the classes gam, glm, and lm. Naive use of the generic predict() 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)). These problems are overcome by predict.gam() by taking the following steps. A combined data frame is constructed containing the predictors in object, using both the data used in fitting object, as well as newdata. From this, a combined model frame and model matrix is constructed, and object is refitted using the top portion of both of these (belonging to the fitting set). The GAM iterations are not repeated; rather one final IRLS step is performed, using the working weights and response from the final iteration in the creation of the original object. In this way, it is guaranteed that any coefficients that are estimated can be applied to both the fitting or prediction portions of the model matrix.


SEE ALSO:
predict , fitted , expand.grid , gam.object .

EXAMPLES:
predict(gamob) # extract the additive predictors
predict(gamob, newdata, type="terms")
predict.gam(lmobjet, newdata) # safe prediction for lm object