Produces default plot showing the smooth components of a
fitted GAM, and optionally parametric terms as well, when these can be
handled by termplot
.For smooth terms plot.gam
actually calls plot method functions depending on the
class of the smooth. Currently random.effects
, Markov random fields (mrf
),
Spherical.Spline
and
factor.smooth.interaction
terms have special methods (documented in their help files),
the rest use the defaults described below.
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. scheme == 0
produces a smooth curve with dashed curves
indicating 2 standard error bounds. scheme == 1
illustrates the error bounds using a shaded
region.
For scheme==0
, 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.
For 2-d smooths scheme==1
produces a perspective plot, while scheme==2
produces a heatmap,
with overlaid contours.
Smooths of more than 2 variables are not plotted, 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.
Note that, if seWithMean=TRUE
, the confidence bands include the uncertainty about the overall mean. In other words
although each smooth is shown centred, the confidence bands are obtained as if every other term in the model was
constrained to have average 0, (average taken over the covariate values), except for the smooth concerned. This seems to correspond more closely to how most users interpret componentwise intervals in practice, and also results in intervals with
close to nominal (frequentist) coverage probabilities by an extension of Nychka's (1988) results.
Sometimes you may want a small change to a default plot, and the arguments to plot.gam
just won't let you do it.
In this case, the quickest option is sometimes to clone the smooth.construct
and Predict.matrix
methods for
the smooth concerned, modifying only the returned smoother class (e.g. to foo.smooth
).
Then copy the plot method function for the original class (e.g. mgcv:::plot.mgcv.smooth
), modify the source code to plot exactly as you want and rename the plot method function (e.g. plot.foo.smooth
). You can then use the cloned
smooth in models (e.g. s(x,bs="foo")
), and it will automatically plot using the modified plotting function.