easystats / performance

:muscle: Models' quality and performance metrics (R2, ICC, LOO, AIC, BF, ...)
https://easystats.github.io/performance/
GNU General Public License v3.0
1.01k stars 87 forks source link

Underdispersion? #263

Closed mattansb closed 6 months ago

mattansb commented 3 years ago

Is there a way to test underdispersion?

bwiernik commented 3 years ago

Similar or even the same regression-based tests can be used to test for under as well as overdispersion, just testing whether the dispersion parameter is less than one as well as grater than one. https://www.rdocumentation.org/packages/AER/versions/1.2-9/topics/dispersiontest

Beyond those, simulation based tests and LR Tetsu's comparing to a generalized Poisson, negative binomial, or CMP model are also common. Personally, I always just use model comparison and graphical tests

strengejacke commented 6 months ago

Do you have an example for underdispersion? It's already detected, but I think the message always says _over_dispersion.

strengejacke commented 6 months ago
library(performance)

# overdispersion
m1 <- glm(count ~ spp + mined, family = poisson, data = glmmTMB::Salamanders)
out <- check_overdispersion(m1)

out
#> # Overdispersion test
#> 
#>        dispersion ratio =    2.946
#>   Pearson's Chi-Squared = 1873.710
#>                 p-value =  < 0.001
#> Overdispersion detected.
plot(out)
#> `geom_smooth()` using method = 'loess' and formula = 'y ~ x'
#> `geom_smooth()` using method = 'loess' and formula = 'y ~ x'


# underdispersion
set.seed(3)
mu <- rpois(500, lambda = 3)
x <- rnorm(500, mu, mu * 3)
x <- ceiling(x)
x <- pmax(x, 0)
m <- MASS::glm.nb(x ~ mu)
out <- check_overdispersion(m)

out
#> # Overdispersion test
#> 
#>  dispersion ratio =   0.410
#>           p-value = < 0.001
#> Underdispersion detected.
plot(out)
#> `geom_smooth()` using method = 'loess' and formula = 'y ~ x'
#> `geom_smooth()` using method = 'loess' and formula = 'y ~ x'

Created on 2024-03-17 with reprex v2.1.0

bwiernik commented 6 months ago

Maybe we should adjust the title to say Over/underdispersion?

strengejacke commented 6 months ago

Or just "Dispersion"? Or is that too short/confusing?

bwiernik commented 6 months ago

Let's do "Misspecified dispersion and zero-inflation"