Learn R Programming

scam (version 1.0)

predict.scam: Prediction from fitted SCAM model

Description

This function is a clone of the mgcv library code predict.gam with some modifications to adopt shape preserving smooth terms. It takes a fitted scam object produced by scam() 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.

Usage

## S3 method for class 'scam':
predict(object,newdata,type="link",se.fit=FALSE,terms=NULL,
    block.size=1000,newdata.guaranteed=FALSE,na.action=na.pass,...)

Arguments

object
a fitted scam object as produced by scam().
newdata
A data frame or list containing the values of the model covariates at which predictions are required. If this is not provided then predictions corresponding to the original data are returned. If newdata is provided then
type
When this has the value "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 erro
se.fit
when this is TRUE (not default) standard error estimates are returned for each prediction.
terms
if type=="terms" then only results for the terms given in this array will be returned.
block.size
maximum number of predictions to process per call to underlying code: larger is quicker, but more memory intensive. Set to < 1 to use total number of predictions as this.
newdata.guaranteed
Set to 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
na.action
what to do about NA 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 ter
...
other arguments.

Value

  • If type=="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.

Details

See predict.gam for details.

References

Chambers and Hastie (1993) Statistical Models in S. Chapman & Hall. Wood S.N. (2006) Generalized Additive Models: An Introduction with R. Chapman and Hall/CRC Press. Pya, N. (2010) Additive models with shape constraints. PhD thesis. University of Bath. Department of Mathematical Sciences

See Also

scam, plot.scam

Examples

Run this code
library(scam)
set.seed(2)
n <- 200
x1 <- runif(n)*6-3
f1 <- 3*exp(-x1^2) # unconstrained term
x2 <- runif(n)*4-1;
f2 <- exp(4*x2)/(1+exp(4*x2)) # monotone increasing smooth
f <- f1+f2
y <- f+rnorm(n)*0.2
dat <- data.frame(x1=x1,x2=x2,y=y)
b <- scam(y~s(x1,k=15,bs="cr",m=2)+s(x2,k=30,bs="mpi",m=2),
    family=gaussian(link="identity"),data=dat)

newd <- data.frame(x1=seq(-2.9,2.9,length.out=30),x2=seq(-0.9,2.9,length.out=30))
pred <- predict.scam(b,newd)
pred
predict(b,newd,type="terms",se=TRUE)
plot(b,se=TRUE,residuals=TRUE,pages=1)

Run the code above in your browser using DataLab