LogisticDx (version 0.2)

plot.glm: Plot diagnostics for a binomial glm model

Description

Standard diagnostic plots.

Usage

# S3 method for glm
plot(x, y = NULL, ..., toPdf = FALSE, file = "dxPlots.pdf",
  palette = c("Dark2", "Set2", "Accent", "Blues"), usePalette = TRUE,
  bg = NULL, col = "white", alpha = 0.4, cex = 2, pch = 21,
  cex.main = 1.5, inches = 0.25, identify = FALSE, devNew = TRUE)

Arguments

x

A regression model with class glm and x$family$family == "binomial".

y

Not used. Present for compatibility with generic plot() function.

...

Additional arguments, which can be passed to the plotting functions. See:

?graphics::plot.default

?graphics::symbols

?graphics::par

toPdf
  • If toPdf=TRUE the output will be directed to a .pdf file.

  • If toPdf=FALSE a new device is opened for each plot.

file

Filename if writing to .pdf as above, e.g. "plots.pdf".

palette

Palette of colors to use as the 'fill'/ 'background' colors for the plots.

The options are taken from color_brewer.

usePalette

Use the colorscheme in palette above.

  • If usePalette=TRUE (the default), this colorscheme will be passed to the argument bg below:

    • graphics::plot.default(bg= )

    • graphics::symbols(bg= )

  • If usePalette=FALSE, then the color specified in bg below will be used instead.

bg

The 'fill' or background color(s) to use, if usePalette=FALSE.

This can be a vector of colors.

col

The 'edge' or 'foreground' color used to outline points in the plot.

The default, "white" is used to make overlapping points easier to see.

This is passed as an argument to

  • graphics::plot.default(col= )

  • graphics::symbols(fg= )

alpha

Transparency for colors above.

Should be in the range 0 (transparent) to 1 (opaque). See:

?grDevices::adjustcolor

cex

Character expansion.

A multiplier used for size of the plotting symbols/ characters. See:

?graphics::par

pch

Plotting character. The symbol/ character to for the plot. The default, pch=21 shows filled circles at each point. See:

?graphics::points

cex.main

Character expansion for the plot title and the labels for the axes.

inches

Width of circles for the bubble plot. See

?graphics::symbols

identify

If TRUE will give option to identify individual points on a number of the plots produced.

The number which appears next to the point corresponds to the relevant row as given by dx.

This may be useful for identifying outliers. See:

?graphics::identify

devNew

If devNew==TRUE (the default), dev.new will be called before each plot. This is useful in interactive mode. devNew==FALSE is used for vignette building by package:knitr.

Value

There is one point per observation.

The following show probability \(P_i\) on the \(x\)-axis:

\(P_i \times h_i\)

Probability vs. leverage.

\(P_i \times \Delta P \chi^2_i\)

Probability vs. the change in the standardized Pearsons chi-squared with observation \(i\) excluded.

\(P_i \times \Delta D_i\)

Probability vs. the change in the standardized deviance with observation \(i\) excluded.

\(P_i \times \Delta \hat{\beta}_i\)

Probability vs. the change in the standardized maximum likelihood estimators of the model coefficients with observation \(i\) excluded.

\(P_i \times \Delta P \chi^2_i\)

Bubbleplot of probability vs. the change in the standardized Pearsons chi-squared with observation \(i\) excluded. The area \(A_i\) of each circle is proportional to \(\Delta \hat{\beta}_i\): $$A_i = \pi r_i^2 \quad r_i = \sqrt{\frac{\Delta \hat{\beta}_i}{P_i}}$$ For details see: ?graphics::symbols

The following show leverage h_ih[i] on the x-axis:

\(h_i \times \Delta P \chi^2_i\)

Leverage vs. the change in the standardized Pearsons chi-squared with observation \(i\) excluded.

\(h_i \times \Delta D_i\)

Leverage vs. the change in the standardized deviance with observation \(i\) excluded.

\(h_i \times \Delta \hat{\beta}_i\)

Leverage vs. the change in the standardized maximum likelihood estimators of the model coefficients with observation \(i\) excluded.

The correlation of \Delta \chi^2_i, \Delta D_i \mathrm{and} \hat{\beta}_i dChisq, dDev and dBhat. is shown in a pairs plot. See:

?graphics::pairs

The Value of dx is also returned, invisibly.

Examples

Run this code
# NOT RUN {
## H&L 2nd ed. Table 4.9. Figures 5.5-5.8. Pages 177-180.
data(uis)
uis <- within(uis, {
    NDRGFP1 <- 10 / (NDRGTX + 1)
    NDRGFP2 <- NDRGFP1 * log((NDRGFP1 + 1) / 10)
})
summary(g1 <- glm(DFREE ~ AGE + NDRGFP1 + NDRGFP2 + IVHX +
                  RACE + TREAT + SITE +
                  AGE:NDRGFP1 + RACE:SITE,
                  family=binomial, data=uis))
plot(g1)
## H&L. Similar to Figure 5.3.
set.seed(133)
(g1 <- glm(sample(c(0, 1), size=100,
                  replace=TRUE, prob=c(0.5, 0.5))
           ~ 0 + I(0.08 * rnorm(n=100, mean=0, sd=sqrt(9))),
           family=binomial))$coef # approx. 0.8
plot(g1)
# }

Run the code above in your browser using DataLab