predict.gam(object, newdata, type, se.fit = F, terms)
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.
predict(gamob) # extract the additive predictors predict(gamob, newdata, type="terms") predict.gam(lmobjet, newdata) # safe prediction for lm object