Plot Components of a GAM Object

DESCRIPTION:
Creates an appropriate plot for each term in a generalized additive model object.

USAGE:
plot.gam(x, y = NULL, residuals = <<see below>>, rugplot = T, se = F,
         scale = 0, ask  =  F, ...)

REQUIRED ARGUMENTS:
x:
a 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.

OPTIONAL ARGUMENTS:
residuals:
if 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.
rugplot:
if 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.
se:
if TRUE, upper and lower pointwise twice-standard-error curves are included for each plot. The default is FALSE.
scale:
a lower limit for the number of units covered by the limits on the y-axis for each plot. The default is 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.
ask:
if TRUE, plot.gam operates in interactive mode.

Graphical parameters may also be supplied as arguments to this function (see par).


SIDE EFFECTS:
a plot is produced for each of the terms in the object 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.

DETAILS:
This function is a method for the generic function plot for class "gam". It can be invoked by calling plot for an object of the appropriate class, or directly by calling plot.gam 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.


BUGS:
Graphical parameters do not affect how residuals are plotted.

SEE ALSO:
gam.object , gplot , plot , predict.gam , preplot .

EXAMPLES:
# create a sample object to plot using the kyphosis dataset
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