[R] Dispersion in summary.glm() with binomial & poisson link

John Maindonald john.maindonald at anu.edu.au
Tue May 9 02:12:31 CEST 2000


Following p.206 of "Statistical Models in S", I wish to change
the code for summary.glm() so that it estimates the dispersion
for binomial & poisson models when the parameter dispersion is
set to zero.  The following changes [insertion of ||dispersion==0
at one point; and !is.null(dispersion) at another] will do the trick:

"summary.glm" <-
function(object, dispersion = NULL,
			correlation = FALSE, ...)
{
    Qr <- .Alias(object$qr)
    est.disp <- FALSE
    df.r <- object$df.residual
    if(is.null(dispersion)||dispersion==0)	# calculate dispersion if needed
	dispersion <-
	    if(any(object$family$family == c("poisson",
"binomial"))&&is.null(dispersion))
		1
	    else if(df.r > 0) {
		est.disp <- TRUE
		if(any(object$weights==0))
		    warning(paste("observations with zero weight",
				  "not used for calculating dispersion"))
		sum(object$weights*object$residuals^2)/ df.r
	    } else Inf
    ## calculate scaled and unscaled covariance matrix
......

Here is an example:

> counts <- c(18,17,15,20,10,20,25,13,12)
> outcome <- gl(3,1,9)
> treatment <- gl(3,3)
> print(d.AD <- data.frame(treatment, outcome, counts))
> glm.D93 <- glm(counts ~ outcome + treatment, family=poisson())
> anova(glm.D93)
> summary(glm.D93,dispersion=0)  #current code
......
Coefficients:
              Estimate Std. Error z value Pr(>|z|)
(Intercept)  3.045e+00  0.000e+00     Inf   <2e-16
outcome2    -4.543e-01  0.000e+00    -Inf   <2e-16
outcome3    -2.930e-01  0.000e+00    -Inf   <2e-16
treatment2   1.924e-08  0.000e+00     Inf   <2e-16
treatment3   8.383e-09  0.000e+00     Inf   <2e-16

(Dispersion parameter for poisson family taken to be 0)

    Null deviance: 10.5814  on 8  degrees of freedom
Residual deviance:  5.1291  on 4  degrees of freedom
AIC: 56.761

Number of Fisher Scoring iterations: 3

Warning message: 
NAs introduced by coercion 

> summary(glm.D93,dispersion=0)  # with above change
.......
Coefficients:
              Estimate Std. Error  t value Pr(>|t|)
(Intercept)  3.045e+00  1.943e-01   15.667  9.7e-05
outcome2    -4.543e-01  2.299e-01   -1.976    0.119
outcome3    -2.930e-01  2.192e-01   -1.337    0.252
treatment2   1.924e-08  2.274e-01 8.46e-08    1.000
treatment3   8.383e-09  2.274e-01 3.69e-08    1.000

(Dispersion parameter for poisson family taken to be 1.293029)

    Null deviance: 10.5814  on 8  degrees of freedom
Residual deviance:  5.1291  on 4  degrees of freedom
AIC: 56.761

Number of Fisher Scoring iterations: 3


John Maindonald               email : john.maindonald at anu.edu.au        
Statistical Consulting Unit,  phone : (6249)3998        
c/o CMA, SMS,                 fax   : (6249)5549  
John Dedman Mathematical Sciences Building
Australian National University
Canberra ACT 0200
Australia

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help 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-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list