gam object produced by gam() and plots the
component smooth functions that make it up, on the scale of the linear
predictor. Optionally produces term plots for parametric model components
as well.plot.gam(x,residuals=FALSE,rug=TRUE,se=TRUE,pages=0,select=NULL,
scale=-1,n=100,n2=40,pers=FALSE,theta=30,phi=30,jit=FALSE,
xlab=NULL,ylab=NULL,main=NULL,ylim=NULL,xlim=NULL,too.far=0.1,
all.terms=FALSE,shade=FALSE,shade.col="gray80",...)gam object as produced by gam().TRUE then partial residuals are added to plots of 1-D smooths. If FALSE
then no residuals are added. If this is an array of the correct length then it is used as the array of
residuals to be used for producing partial residupages=1 then all terms will be plotted on one page with the layout performed automatically.
Set to 0 to have the routine leave all graphics settings as they arselect=2.ylim supplied.TRUE if you want perspective plots for 2-d
terms.TRUE then the partial effects of parametric
model components are also plotted, via a call to termplot. Only
terms of order 1 can be plotted in this way.TRUE to produce shaded regions as confidence bands
for smooths (not avaliable for parametric terms, which are plotted using termplot).plot.gam() in S-PLUS.Plots of 2-D smooths with standard error contours shown can not easily be customized.
The function can not deal with smooths of more than 2 variables!
termplot. For plots of 1-d smooths, the x axis of each plot is labelled
with the covariate name, while the y axis is labelled s(cov,edf) where cov
is the covariate name, and edf the estimated (or user defined for regression splines) degrees of freedom of the smooth.
Contour plots are produced for 2-d smooths with the x-axes labelled with the first covariate
name and the y axis with the second covariate name. The main title of
the plot is something like s(var1,var2,edf), indicating the
variables of which the term is a function, and the estimated degrees of
freedom for the term. When se=TRUE, estimator variability is shown by overlaying
contour plots at plus and minus 1 s.e. relative to the main
estimate. If se is a positive number then contour plots are at plus or minus se multiplied
by the s.e. Contour levels are chosen to try and ensure reasonable
separation of the contours of the different plots, but this is not
always easy to achieve. Note that these plots can not be modified to the same extent as the other plot.
Smooths of more than 2 variables are not currently dealt with, but
simply generate a warning, but see vis.gam.
Fine control of plots for parametric terms can be obtained by calling
termplot directly, taking care to use its terms argument.
Gu and Wahba (1991) Minimizing GCV/GML scores with multiple smoothing parameters via the Newton method. SIAM J. Sci. Statist. Comput. 12:383-398
Wood, S.N. (2000) Modelling and Smoothing Parameter Estimation with Multiple Quadratic Penalties. J.R.Statist.Soc.B 62(2):413-428
Wood, S.N. (2003) Thin plate regression splines. J.R.Statist.Soc.B 65(1):95-114
Wood, S.N. (2004) Stable and efficient multiple smoothing parameter estimation for generalized additive models. J. Amer. Statist. Ass. 99:637-686
gam, predict.gam, vis.gamlibrary(mgcv)
set.seed(0)
n<-200
sig2<-4
x0 <- rep(1:4,50)
x1 <- runif(n, 0, 1)
x2 <- runif(n, 0, 1)
x3 <- runif(n, 0, 1)
y <- 2 * x0
y <- y + exp(2 * x1) - 3.75887
y <- y+0.2*x2^11*(10*(1-x2))^6+10*(10*x2)^3*(1-x2)^10-1.396
e <- rnorm(n, 0, sqrt(abs(sig2)))
y <- y + e
x0 <- factor(x0)
b<-gam(y~x0+s(x1)+s(x2)+s(x3))
plot(b,pages=1,residuals=TRUE,all.terms=TRUE,shade=TRUE,shade.col=2)
# just parametric term alone
termplot(b,terms="x0",se=TRUE)
# example with 2-d plots
b1<-gam(y~x0+s(x1,x2)+s(x3))
op<-par(mfrow=c(2,2))
plot(b1,all.terms=TRUE)
par(op)Run the code above in your browser using DataLab