predict.Gam | R Documentation |

Obtains predictions and optionally estimates standard errors of those predictions from a fitted generalized additive model object.

## S3 method for class 'Gam' predict( object, newdata, type = c("link", "response", "terms"), dispersion = NULL, se.fit = FALSE, na.action = na.pass, terms = labels(object), ... )

`object` |
a fitted |

`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 |

`type` |
type of predictions, with choices |

`dispersion` |
the dispersion of the GLM fit to be assumed in computing the standard errors. If omitted, that returned by 'summary' applied to the object is used |

`se.fit` |
if |

`na.action` |
function determining what should be done with missing values in 'newdata'. The default is to predict 'NA'. |

`terms` |
if |

`...` |
Placemark for additional arguments to predict |

a vector or matrix of predictions, or a list consisting of
the predictions and their standard errors if ```
se.fit =
TRUE
```

. 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.

When `newdata`

are supplied, `predict.Gam`

simply invokes
inheritance and gets `predict.glm`

to produce the parametric part of
the predictions. For each nonparametric term, `predict.Gam`

reconstructs the partial residuals and weights from the final iteration of
the local scoring algorithm. The appropriate smoother is called for each
term, with the appropriate `xeval`

argument (see `s`

or
`lo`

), and the prediction for that term is produced.

The standard errors are based on an approximation given in Hastie (1992).
Currently `predict.Gam`

does not produce standard errors for
predictions at `newdata`

.

Warning: naive use of the generic `predict`

can produce incorrect
predictions when the `newdata`

argument is used, if the formula in
`object`

involves transformations such as `sqrt(Age - min(Age))`

.

Written by Trevor Hastie, following closely the design in the
"Generalized Additive Models" chapter (Hastie, 1992) in Chambers and Hastie
(1992). This version of `predict.Gam`

is adapted from the S version to
match the corresponding predict methods for `glm`

and `lm`

objects
in R. The `safe.predict.Gam`

function in S is no longer required,
primarily because a safe prediction method is in place for functions like
`ns`

, `bs`

, and `poly`

.

Hastie, T. J. (1992) *Generalized additive models.* Chapter
7 of *Statistical Models in S* eds J. M. Chambers and T. J. Hastie,
Wadsworth & Brooks/Cole.

Hastie, T. and Tibshirani, R. (1990) *Generalized Additive Models.*
London: Chapman and Hall.

Venables, W. N. and Ripley, B. D. (2002) *Modern Applied Statistics
with S.* New York: Springer.

`predict.glm`

, `fitted`

,
`expand.grid`

data(gam.data) Gam.object <- gam(y ~ s(x,6) + z, data=gam.data) predict(Gam.object) # extract the additive predictors data(gam.newdata) predict(Gam.object, gam.newdata, type="terms")

Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, read Embedding Snippets.