predict.gam
for prediction from a
model fitted by bam
. Can compute on a parallel cluster. Takes a fitted bam
object produced by bam
and produces predictions given a new set of values for the model covariates
or the original values used for the model fit. Predictions can be accompanied
by standard errors, based on the posterior distribution of the model
coefficients. The routine can optionally return the matrix by which the model
coefficients must be pre-multiplied in order to yield the values of the linear predictor at
the supplied covariate values: this is useful for obtaining credible regions
for quantities derived from the model (e.g. derivatives of smooths), and for lookup table prediction outside
R
(see example code below).
## S3 method for class 'bam':
predict(object,newdata,type="link",se.fit=FALSE,terms=NULL,
block.size=50000,newdata.guaranteed=FALSE,na.action=na.pass,cluster=NULL,...)
bam
object as produced by bam
.newdata
is provided then
"link"
(default) the linear predictor (possibly with
associated standard errors) is returned. When type="terms"
each component of the
linear predictor is returned seperately (possibly with standard errorstype=="terms"
then only results for the terms named in this array
will be returned.TRUE
to turn off all checking of
newdata
except for sanity of factor levels: this can speed things up
for large prediction tasks, but newdata
must be complete, with no
NA
values for predictors reqNA
values in newdata
. With the
default na.pass
, any row of newdata
containing NA
values
for required predictors, gives rise to NA
predictions (even if the term predict.bam
can compute in parallel using parLapply
from the parallel
package, if it is supplied with a cluster on which to do this (a cluster here can be some cores of a
single machtype=="lpmatrix"
then a matrix is returned which will
give a vector of linear predictor values (minus any offest) at the supplied covariate
values, when applied to the model coefficient vector.
Otherwise, if se.fit
is TRUE
then a 2 item list is returned with items (both arrays) fit
and se.fit
containing predictions and associated standard error estimates, otherwise an
array of predictions is returned. The dimensions of the returned arrays depends on whether
type
is "terms"
or not: if it is then the array is 2 dimensional with each
term in the linear predictor separate, otherwise the array is 1 dimensional and contains the
linear predictor/predicted values (or corresponding s.e.s). The linear predictor returned termwise will
not include the offset or the intercept.newdata
can be a data frame, list or model.frame: if it's a model frame
then all variables must be supplied.
predict.gam
are based on the
Bayesian posterior covariance matrix of the parameters Vp
in the fitted
bam object. To facilitate plotting with termplot
, if object
possesses
an attribute "para.only"
and type=="terms"
then only parametric
terms of order 1 are returned (i.e. those that termplot
can handle).
Note that, in common with other prediction functions, any offset supplied to
gam
as an argument is always ignored when predicting, unlike
offsets specified in the gam model formula.
See the examples in predict.gam
for how to use the lpmatrix
for obtaining credible
regions for quantities derived from the model.
Marra, G and S.N. Wood (2012) Coverage Properties of Confidence Intervals for Generalized Additive Model Components. Scandinavian Journal of Statistics.
Wood S.N. (2006b) Generalized Additive Models: An Introduction with R. Chapman and Hall/CRC Press.
bam
, predict.gam
## for parallel computing see examples for ?bam
## for general useage follow examples in ?predict.gam
Run the code above in your browser using DataLab