deviance residuals in binomial GLM (PR#399)

maechler@stat.math.ethz.ch maechler@stat.math.ethz.ch
Tue, 11 Jan 2000 22:25:07 +0100 (MET)


>>>>> "faraway" == faraway  <faraway@umich.edu> writes:

    faraway> Full_Name: Julian Faraway
    faraway> Version: .90.1
    faraway> OS: Linux+NT
    faraway> Submission from: (NULL) (141.211.66.172)


    faraway> In the following example, the deviance residuals are not
    faraway> correctly calculated:

    >> dead <- c(2,8,15,23,27)
    >> y <- cbind(dead,30-dead)
    >> conc <- 0:4
    >> g <- glm(y ~ conc,family=binomial)
    >> residuals(g)
    faraway> [1] -0.451015  0.359696       NaN  0.064302 -0.204493
    faraway> Warning message: 
    faraway> NaNs produced in: sqrt((object$family$dev.resids)(y, mu, wts)) 

    faraway> The third residual should be zero.

yes, this is a bug.

Diagnosis: 
    A case of cancelation which makes the argument of sqrt(.) 
    negative (~= -5e-21) instead of zero.


The fix is
in  src/library/base/R/glm.R
replace
	       d.res <- sqrt((object$family$dev.resids)(y, mu, wts))
by
	       d.res <- sqrt(pmax(0,(object$family$dev.resids)(y, mu, wts)))

Thanks a lot for the report!

Martin Maechler <maechler@stat.math.ethz.ch>	http://stat.ethz.ch/~maechler/
Seminar fuer Statistik, ETH-Zentrum  LEO D10	Leonhardstr. 27
ETH (Federal Inst. Technology)	8092 Zurich	SWITZERLAND
phone: x-41-1-632-3408		fax: ...-1228			<><

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