check_overdispersion: Check overdispersion of GL(M)M's

Description Usage Arguments Details Value References Examples

View source: R/check_overdispersion.R

Description

check_overdispersion() checks generalized linear (mixed) models for overdispersion.

Usage

1

Arguments

x

Fitted model of class merMod, glmmTMB, glm, or glm.nb (package MASS).

...

Currently not used.

Details

Overdispersion occurs when the observed variance is higher than the variance of a theoretical model. For Poisson models, variance increases with the mean and, therefore, variance usually (roughly) equals the mean value. If the variance is much higher, the data are "overdispersed".

Interpretation of the Dispersion Ratio

If the dispersion ratio is close to one, a Poisson model fits well to the data. Dispersion ratios larger than one indicate overdispersion, thus a negative binomial model or similar might fit better to the data. A p-value < .05 indicates overdispersion.

Overdispersion in Poisson Models

For Poisson models, the overdispersion test is based on the code from Gelman and Hill (2007), page 115.

Overdispersion in Mixed Models

For merMod- and glmmTMB-objects, check_overdispersion() is based on the code in the GLMM FAQ, section How can I deal with overdispersion in GLMMs?. Note that this function only returns an approximate estimate of an overdispersion parameter, and is probably inaccurate for zero-inflated mixed models (fitted with glmmTMB).

How to fix Overdispersion

Overdispersion can be fixed by either modeling the dispersion parameter, or by choosing a different distributional family (like Quasi-Poisson, or negative binomial, see Gelman and Hill (2007), pages 115-116).

Value

A list with results from the overdispersion test, like chi-squared statistics, p-value or dispersion ratio.

References

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
if (require("glmmTMB")) {
  data(Salamanders)
  m <- glm(count ~ spp + mined, family = poisson, data = Salamanders)
  check_overdispersion(m)

  m <- glmmTMB(
    count ~ mined + spp + (1 | site),
    family = poisson,
    data = Salamanders
  )
  check_overdispersion(m)
}

Example output

Loading required package: glmmTMB
# Overdispersion test

       dispersion ratio =    2.324
  Pearson's Chi-Squared = 1475.875
                p-value =  < 0.001

Overdispersion detected.
Warning message:
In checkMatrixPackageVersion() : Package version inconsistency detected.
TMB was built with Matrix version 1.2.15
Current Matrix version is 1.2.17
Please re-install 'TMB' from source using install.packages('TMB', type = 'source') or ask CRAN for a binary version of 'TMB' matching CRAN's 'Matrix' package

performance documentation built on Oct. 1, 2021, 5:08 p.m.