Skip to content
Prev 10595 / 20628 Next

Overdispersion and model selection: glmmadmb vs. glmer

Hi Luca,

(To avoid confusion, I'm the Glasgow Paul Johnson, not the Kansas one - incidentally there's also a statistician of the same name in Oxford, a former colleague, whom we can only hope stays out of this discussion).

Below is some code for comparing residuals between Poisson-lognormal glmer and NB glmmadmb fits. I find this useful as a quick way of spotting bad fits (aiming, roughly, for homoscedasticity and absence of a trend). However I agree with the other PJ that plotting the predictions and prediction intervals from both models over the data is a better way to compare the two fits.

Best wishes,
Paul


  plot.glmer<-
    function(mer.fit,type="pearson",overdispersion.term=NULL)
    {
      require(AICcmodavg)
      if(is.null(overdispersion.term))
      {
        Fitted<-fitted(mer.fit)
        Residuals=resid(mer.fit,type)
      } else
        {
          response<-model.frame(mer.fit)[[1]]
          od.ranef<-lme4::ranef(mer.fit)[[overdispersion.term]][[1]]
          if(length(response)!=length(od.ranef) || fam.link.mer(mer.fit)$family!="poisson" || fam.link.mer(mer.fit)$link!="log")
            stop("Model is not lognormal-Poisson. Cannot use overdispersion term.")
          Fitted<-exp(log(fitted(mer.fit))-od.ranef)
          Residuals<-(response - Fitted)/sqrt(Fitted+(Fitted^2)*c(exp(lme4::VarCorr(mer.fit)[[overdispersion.term]])-1))
        }
      plot.data<-data.frame(Fitted=Fitted,Residuals=Residuals)
      plot.data$loess.line<-predict(loess(Residuals~Fitted,data=plot.data))
      plot.data<-plot.data[order(plot.data$Fitted),]
      plot(plot.data[,c("Fitted","Residuals")])
      abline(h=0)
      points(plot.data[,c("Fitted","loess.line")],type="l",col="red")
      hist(plot.data$Residuals,xlab="Residuals",main="")
    }

  par(mfrow=c(3,2))
  plot.glmer(pois.glmm)  # overdispersion effects in the fitted values, so expect a trend
  plot.glmer(pois.glmm,overdispersion.term="ons")   # 'detrended' by moving OD effects to the residuals
  plot.glmer(nb.glmm)  # compare with residuals from NB GLMM
On 2 Sep 2013, at 08:32, Luca Corlatti <luca.corlatti at boku.ac.at> wrote: