plotGlm: Plot diagnostics for a binomial 'glm' model

Description Usage Arguments Value Note Examples

Description

Standard diagnostic plots.

Usage

1
2
3
4
5
## S3 method for class '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] vs. h[i]

Probability vs. leverage.

P[i] vs. dChisq[i]

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

P[i] vs. dDev[i]

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

P[i] vs. dBhat[i]

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

P[i] vs. dChisq[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 dBhat[i]:

A[i] = pi r[i]^2, r[i] = (dBhat[i] / P[i])^0.5

For details see:
?graphics::symbols

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

h[i] vs. dChisq[i]

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

h[i] vs. dDev[i]

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

h[i] vs. dBhat[i]

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

The correlation of dChisq, dDev and dBhat. is shown in a pairs plot. See:
?graphics::pairs

The Value of dx is also returned, invisibly.

Note

A choice of colors can be found with e.g.
grDevices::colours()[grep("blue", grDevices::colours())]

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
## 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)

Example output

Call:
glm(formula = DFREE ~ AGE + NDRGFP1 + NDRGFP2 + IVHX + RACE + 
    TREAT + SITE + AGE:NDRGFP1 + RACE:SITE, family = binomial, 
    data = uis)

Deviance Residuals: 
    Min       1Q   Median       3Q      Max  
-1.3036  -0.7914  -0.5783   0.9902   2.6024  

Coefficients:
                 Estimate Std. Error z value Pr(>|z|)    
(Intercept)     -6.607764   1.177521  -5.612 2.00e-08 ***
AGE              0.116601   0.028859   4.040 5.34e-05 ***
NDRGFP1          0.690191   0.209629   3.292 0.000993 ***
NDRGFP2         -0.461492   0.123824  -3.727 0.000194 ***
IVHXprevious    -0.633915   0.298774  -2.122 0.033862 *  
IVHXrecent      -0.705257   0.261631  -2.696 0.007026 ** 
RACEother        0.686261   0.264195   2.598 0.009389 ** 
TREATlong        0.433709   0.203791   2.128 0.033320 *  
SITEB            0.516694   0.254937   2.027 0.042688 *  
AGE:NDRGFP1     -0.015260   0.006026  -2.532 0.011329 *  
RACEother:SITEB -1.431087   0.529872  -2.701 0.006917 ** 
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

(Dispersion parameter for binomial family taken to be 1)

    Null deviance: 653.73  on 574  degrees of freedom
Residual deviance: 597.92  on 564  degrees of freedom
AIC: 619.92

Number of Fisher Scoring iterations: 4

dev.new(): using pdf(file="Rplots1.pdf")
dev.new(): using pdf(file="Rplots2.pdf")
dev.new(): using pdf(file="Rplots3.pdf")
dev.new(): using pdf(file="Rplots4.pdf")
dev.new(): using pdf(file="Rplots5.pdf")
dev.new(): using pdf(file="Rplots6.pdf")
I(0.08 * rnorm(n = 100, mean = 0, sd = sqrt(9))) 
                                       0.8093208 
dev.new(): using pdf(file="Rplots7.pdf")
dev.new(): using pdf(file="Rplots8.pdf")
dev.new(): using pdf(file="Rplots9.pdf")
dev.new(): using pdf(file="Rplots10.pdf")
dev.new(): using pdf(file="Rplots11.pdf")
dev.new(): using pdf(file="Rplots12.pdf")
dev.new(): using pdf(file="Rplots13.pdf")

LogisticDx documentation built on May 2, 2019, 6:15 p.m.