glm
.
plot.glm(glm.obj, residuals = NULL, smooths = F, rugplot = F, id.n = F, ask = F, which.plots = NULL, ...)
glm
object.
residuals
is a vector with the same length as each fitted term
in
glm.obj
,
then these are taken to be the residuals to be used in plotting.
This is useful when a type other than
"deviance"
residuals is wanted
in the plots produced.
TRUE
, smooth curves are approximated to the scatterplots
using
loess.smooth
and added to the appropriate plots.
TRUE
, 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.
id.n
largest points in absolute value. Set to
FALSE
if no identified
points are desired.
TRUE
,
plot.glm
operates in interactive mode.
glm.obj
.
These plots can be
adorned with smooth fits, a rugplot, or labels for the largest
(in absolute value) y-values,
depending on the choice of options. These diagnostic plots can be one or all
of the following:
1: Residuals against Fitted Values
This is useful for diagnosing:
(1) whether the relationship between the response and explanatory variables is linear -- if any curvature is observed than the model might be improved by adding additional, nonlinear terms to the model,
(2) whether the conditional variance of the residuals depends on the explanatory variables -- if the residuals are larger (positive and negative) for larger predicted values, then a nonlinear transformation of the response such as a square-root or log transformation may be useful.
Caution -- the use of this plot is not as easy for some probability models
as for the normal probability model (used in
lm
).
2: Square Root of the Absolute value of Residuals against Predicted (Linear) Values
This is also useful for diagnosing whether the conditional variance of the residuals is constant. The square-root transformation reduces the visual impact of large residuals, but also undesirably inflates small differences in magnitudes for residuals near zero.
3: Response against Fitted Values
4: Normal QQplot of Standardized Residuals
This is useful for diagnosing whether the distribution of the residuals is normal (Gaussian). This is irrelevant for probability models other than Gaussian.
This function is a method for the generic function for class glm. 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.glm
displays a menu listing all the plots that can be produced.
If the menu is not desired but a pause between plots is still wanted
one must set
par(ask=T)
before invoking this command with argument
ask=F
.
# create sample glm object, see glm helpfile for others glmob <- glm(ozone^(1/3) ~ bs(radiation, 5) + poly(wind, temperature, degree = 2), data = air) plot(glmob, ask = T) # interactive version par(mfrow=c(2,2)) plot(glmob, smooths = T, rugplot = T) plot(glmob, id.n = 8)