Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

check_model check notmality in GLMs? #501

Closed
Tracked by #643
mattansb opened this issue Oct 23, 2022 · 10 comments
Closed
Tracked by #643

check_model check notmality in GLMs? #501

mattansb opened this issue Oct 23, 2022 · 10 comments
Labels
3 investigators ❔❓ Need to look further into this issue

Comments

@mattansb
Copy link
Member

Is there a reason for this? What am I missing...

library(performance)

set.seed(3)
mu <- rpois(500, lambda = 3)
x <- rnorm(500, mu, mu*3) |> ceiling() |> pmax(0)

quine.nb1 <- MASS::glm.nb(x ~ mu)

check_normality(quine.nb1)
#> Checking normality of residuals is only useful an appropriate assumption
#>   for linear models.
#> NULL

But…

check_model(quine.nb1)

Created on 2022-10-23 by the reprex package (v2.0.1)

@strengejacke strengejacke added the 3 investigators ❔❓ Need to look further into this issue label Oct 23, 2022
@bwiernik
Copy link
Contributor

the current normality check isn't really appropriate generally except for linear models. something like the DhARMA QQ plots would be more appropriate

@strengejacke
Copy link
Member

MASS package provides a QQ plot (with plot()), using std. Pearson resid. Maybe we fall back to this plot for now?

@strengejacke
Copy link
Member

Wait, we're already doing this:

library(performance)
set.seed(3)
mu <- rpois(500, lambda = 3)
x <- rnorm(500, mu, mu*3) |> ceiling() |> pmax(0)

quine.nb1 <- MASS::glm.nb(x ~ mu)
check_model(quine.nb1, check = "qq")

plot(quine.nb1)

@mattansb
Copy link
Member Author

MASS package provides a QQ plot (with plot()), using std. Pearson resid. Maybe we fall back to this plot for now?

Aren't these also irrelevant?

@bbolker
Copy link

bbolker commented May 9, 2023

This is a classic GLM approach. When sample sizes are reasonably large (e.g. Poisson with 'large' mean (>5?), Binomial with n*p*(1-p) 'large'), the Pearson residuals for a GLM approach normality. This is how Q-Q plotting was traditionally done before randomized/simulated residuals (don't know if anyone suggested simulated residuals prior to Ben and Yohai 2004?) were computationally feasible (and hence why plot.lm is used for GLMs (whose class is c("glm", "lm")). (Furthermore, when you plot quine.nb1 above, the plot() method is not coming from MASS; instead, it's falling back to stats::plot.lm (class(quine.nb1) is c("negbin", "glm", "lm").)

Ben, Marta García, and Víctor J Yohai. 2004. “Quantile–Quantile Plot for Deviance Residuals in the Generalized Linear Model.” Journal of Computational and Graphical Statistics 13 (1): 36–47. https://doi.org/10.1198/1061860042949_a.

Augustin, Nicole H., Erik-André Sauleau, and Simon N. Wood. 2012. “On Quantile Quantile Plots for Generalized Linear Models.” Computational Statistics & Data Analysis 56 (8): 2404–9. https://doi.org/10.1016/j.csda.2012.01.026.

@strengejacke
Copy link
Member

Also note that we have changed the behaviour and adopted the new computation for QQ-plot for GLMs that is implemented in R 4.3 (#571). That maybe resolves this issue?

@bbolker
Copy link

bbolker commented May 9, 2023

To be honest I don't fully understand the advantages of the base-R change, but I'm fine with this. I think it's a matter of taste whether you want to present these plots, or take something from mgcv::qq.gam or DHARMa, or not show anything at all ...

@epertham
Copy link

epertham commented Jun 8, 2023

the current normality check isn't really appropriate generally except for linear models. something like the DhARMA QQ plots would be more appropriate

Hello, thanks a lot for this package very useful and user-frienfly. What do you think about integrating the DHARMA check of residuals for (generalized) mixed models ? Best, Emeline

@strengejacke
Copy link
Member

We have an older issue where we discussed integrating DHARMa (#376), but I personally have rarely used that package, and I'm not sure if other easystats-members currently find the time to work on this. But it's definitely not forgotten...

@strengejacke
Copy link
Member

Should be fixed in #643

library(performance)
set.seed(3)
mu <- rpois(500, lambda = 3)
x <- rnorm(500, mu, mu * 3) |>
  ceiling() |>
  pmax(0)

quine.nb1 <- MASS::glm.nb(x ~ mu)
check_normality(quine.nb1)
#> There's no formal statistical test for normality for generalized linear
#>   model.
#>   Instead, please use `simulate_residuals()` and `check_residuals()` to
#>   check for uniformity of residuals.
check_residuals(quine.nb1)
#> Warning: Non-uniformity of simulated residuals detected (p < .001).
plot(simulate_residuals(quine.nb1))

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3 investigators ❔❓ Need to look further into this issue
Projects
None yet
Development

No branches or pull requests

5 participants