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

Should check_overdispersion give warning when applied to quasipoisson? #734

Open jmgirard opened 3 months ago

jmgirard commented 3 months ago

check_overdispersion() seems to just be returning the same results for poisson and quasipoisson. I think the latter should be based on simulated residuals, but that's not enabled yet so maybe that's why?

library(easystats)
#> # Attaching packages: easystats 0.7.2
#> ✔ bayestestR  0.13.2.2   ✔ correlation 0.8.4   
#> ✔ datawizard  0.11.0.2   ✔ effectsize  0.8.8.1 
#> ✔ insight     0.20.1     ✔ modelbased  0.8.8   
#> ✔ performance 0.12.0     ✔ parameters  0.21.7.4
#> ✔ report      0.5.8      ✔ see         0.8.4

Poisson - correct

fit <- glm(
  formula = DriversKilled ~ PetrolPrice,
  family = poisson(link = "log"),
  data = Seatbelts
)
check_overdispersion(fit)
#> # Overdispersion test
#> 
#>        dispersion ratio =   4.470
#>   Pearson's Chi-Squared = 849.362
#>                 p-value = < 0.001
#> Overdispersion detected.
simulate_residuals(fit)
#> Simulated residuals from a model of class `glm` based on 250
#>   simulations. Use `check_residuals()` to check uniformity of residuals or
#>   `residuals()` to extract simulated residuals. It is recommended to refer
#>   to `?DHARMa::simulateResiudals` and `vignette("DHARMa")` for more
#>   information about different settings in particular situations or for
#>   particular models.

Quasi-poisson - incorrect?

fit2 <- glm(
  formula = DriversKilled ~ PetrolPrice,
  family = quasipoisson(link = "log"),
  data = Seatbelts
)
check_overdispersion(fit2)
#> # Overdispersion test
#> 
#>        dispersion ratio =   4.470
#>   Pearson's Chi-Squared = 849.362
#>                 p-value = < 0.001
#> Overdispersion detected.
simulate_residuals(fit2)
#> Error in simulate.lm(object, nsim = nsim, ...): family 'quasipoisson' not implemented

Created on 2024-06-13 with reprex v2.1.0

strengejacke commented 3 months ago

@bwiernik Not sure whether the same check can be applied to quasi-poisson or not?