[Rd] Bug in glm.fit() or plot.lm() (PR#778)

murdoch@stats.uwo.ca murdoch@stats.uwo.ca
Tue, 19 Dec 2000 20:56:11 +0100 (MET)

Here's a bug one of my students noticed.

When you call plot() on a glm object, plot.lm gets called.  The second
plot it shows is supposed to give a normal QQ plot of the standard
deviance residuals, but it doesn't.  The glm object created by glm.fit
returns something (the IRLS weights?) in fit$weights which plot.lm
takes as observation weights, so  you get strange residuals in the QQ

For example, here I fit a simulated Poisson model where the model
perfectly fine, but the plot.lm QQ plot makes the residuals look huge,
ranging between -45 and 40.

>x <- seq(4,5,len=1000)
>y <- rpois(1000,exp(x))
>fit <- glm(y ~ x, family=poisson)
>plot(fit, which=2)

If I extract the residuals myself and plot them, I see that the model
is fine:


The problem is that the weights are big; plot.lm should be using
prior.weights, or glm should be returning the big weights under a
different name:

> summary(fit$weights)
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
  54.35   69.90   89.90   93.76  115.60  148.70 

> summary(fit$prior.weights)
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
      1       1       1       1       1       1 

Duncan Murdoch

--please do not edit the information below--

 platform = i386-pc-mingw32
 arch = x86
 os = Win32
 system = x86, Win32
 status = 
 major = 1
 minor = 2.0
 year = 2000
 month = 12
 day = 15
 language = R

Windows 9x 4.10 (build 1998)  

Search Path:
 .GlobalEnv, package:ctest, Autoloads, package:base

r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-devel-request@stat.math.ethz.ch