From murdoch@stats.uwo.ca  Tue Dec 19 19:56:11 2000
From: murdoch@stats.uwo.ca (murdoch@stats.uwo.ca)
Date: Tue, 19 Dec 2000 20:56:11 +0100 (MET)
Subject: [Rd] Bug in glm.fit() or plot.lm() (PR#778)
Message-ID: <200012191956.UAA09023@pubhealth.ku.dk>

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
plot.

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.

>set.seed(1)
>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:

>qqnorm(residuals(fit))

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--

Version:
 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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._


[Rd] Bug in glm.fit() or plot.lm() (PR#778)
murdoch@stats.uwo.ca