Skip to content

checking overdispersion when modelling proportions

2 messages · Kristen Mancuso, Ben Bolker

2 days later
#
Kristen Mancuso <kmancuso88 at ...> writes:
I just added this to http://glmm.wikidot.com/faq -- comments welcome.
 
How can I test for overdispersion?

    with the usual caveats (e.g. see Venables and Ripley MASS p. 209), plus a
few extras ? counting degrees of freedom, etc. ? the usual procedure of
calculating the sum of squared Pearson residuals and comparing it to the
residual degrees of freedom should give at least a crude idea of overdispersion.
The following crude attempt counts each variance or covariance parameter as one
model degree of freedom and presents the sum of squared Pearson residuals, the
ratio of (SSQ residuals/rdf), the residual df, and the $$p$$-value based on the
(approximately!!) appropriate $$\chi^2$ distribution.

overdisp_fun <- function(model) {
  ## number of variance parameters in 
  ##   an n-by-n variance-covariance matrix
  vpars <- function(m) {
    nrow(m)*(nrow(m)+1)/2
  }
  model.df <- sum(sapply(VarCorr(model),vpars))+length(fixef(model))
  (rdf <- nrow(model at frame)-model.df)
  rp <- residuals(model)
  Pearson.chisq <- sum(rp^2)
  prat <- Pearson.chisq/rdf
  pval <- pchisq(Pearson.chisq, df=rdf, lower.tail=FALSE)
  c(chisq=Pearson.chisq,ratio=prat,rdf=rdf,p=pval)
}