Skip to content

Commit

Permalink
fix for nbinom2?
Browse files Browse the repository at this point in the history
  • Loading branch information
strengejacke committed Feb 6, 2024
1 parent 43c71b1 commit ed4d85b
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion R/check_model_diagnostics.R
Original file line number Diff line number Diff line change
Expand Up @@ -300,9 +300,16 @@
d <- data.frame(Predicted = stats::predict(model, type = "response"))
d$Residuals <- insight::get_residuals(model, type = "pearson")
d$Res2 <- d$Residuals^2
d$V <- insight::get_sigma(model)^2 * stats::family(model)$variance(d$Predicted)
d$StdRes <- insight::get_residuals(model, type = "pearson")
if (faminfo$family == "nbinom1") {
# for nbinom1, we can use "sigma()"
d$V <- insight::get_sigma(model)^2 * stats::family(model)$variance(d$Predicted)
} else {
# for nbinom2, "sigma()" has "inverse meaning" (see #654)
d$V <- (1 / insight::get_sigma(model)^2) * stats::family(model)$variance(d$Predicted)
}
} else {
## FIXME: this is not correct for glm.nb models?
d <- data.frame(Predicted = stats::predict(model, type = "response"))
d$Residuals <- insight::get_response(model) - as.vector(d$Predicted)
d$Res2 <- d$Residuals^2
Expand Down

0 comments on commit ed4d85b

Please sign in to comment.