plot.gam(x, y=NULL, residuals=<<see below>>, rugplot=T, se=F, scale=0, ask=F, fit=T, ...)
gam
object, or a
preplot.gam
object.
The first thing
plot.gam
does is check if
x
has a
component called
preplot
; if not, it computes one using
preplot.gam
.
Either way, it is this
preplot.gam
object that is
required for plotting a
gam
object.
TRUE
, partial deviance residuals are plotted along with the
fitted terms---default is
FALSE
.
If
residuals
is a vector with the same length as each fitted term in
x
,
then these are taken to be the overall residuals to be used
for constructing the partial residuals.
TRUE
(the default), a univariate histogram or
rugplot
is
displayed along the base of each plot, showing the
occurrence of each x-value; ties are broken by jittering.
TRUE
, upper and lower pointwise twice-standard-error curves
are included for each plot. The default is
FALSE
.
scale=0
, in which case each plot uses the range of
the functions being plotted to create their
ylim
.
By setting
scale
to be the maximum value of
diff(ylim)
for all the plots,
then all subsequent plots will produced in the same vertical units.
This is essential for comparing the importance of fitted terms
in additive models.
TRUE
,
plot.gam
operates in interactive mode.
TRUE
then the fitted terms are included on each plot.
Use
residuals=T
,
fit=F
to get partial residual plots with no fit displayed.
x
.
The function currently knows how to plot all main-effect functions of
one or two predictors. So in particular, interactions are not plotted.
An appropriate x-y plot is produced to display each of the terms,
adorned with residuals, standard-error curves, and a rugplot,
depending on the choice of options. The form of the plot is different,
depending on whether the x-value for each plot is numeric,
a factor, or a matrix.
This function is a method for the generic function
for class gam.
It can be invoked by calling
for an object x of the appropriate class, or directly by calling
regardless of the class of the object.
When
ask=T
, rather than produce each plot sequentially,
plot.gam
displays a menu listing all the terms that can be plotted,
as well as switches for all the options. The switches displayed in the
menu are currently off, they must be selected to turn them on!
An additional switch called
browser
allows users to temporarily
regain control, and is useful for setting
par
options,
or for adding additional information to the current plot.
A
preplot.gam
object is a list of precomputed terms.
Each such term (also a
preplot.gam
object) is a list with
components
x
,
y
and others---the basic ingredients needed for each
term plot.
These are in turn handed to the specialized plotting function
gplot
,
which has methods for different classes of the leading
x
argument.
In particular, a different plot is produced if
x
is numeric,
a category or factor, a matrix, or a list.
Experienced users can extend this range by creating more
gplot
methods for other classes.
Graphical parameters do not affect how residuals are plotted.
# create a sample object to plot using the kyphosis data set gamob <- gam(Kyphosis ~ s(Age) + s(Number), data=kyphosis, family=binomial) plot(gamob, ask=F) # non-interactive version, plots all terms plot(gamob, residuals=T, se=T, rug=F) gamob$preplot <- preplot(gamob) plot(gamob) # now set ask=T to interact with the menu plot(gamob, ask=T) # The browser option can be used to change par parameters. # Selecting "plot all terms" will cause the both plots to flash # by on the screen. To show them both at the same time # select the browser option and type at the prompt: par(mfrow(2,1)) # now the plots should appear in a column when "plot all terms" # is selected