Skip to content

Commit

Permalink
Error for R2 for beta binomial glmmTMB model
Browse files Browse the repository at this point in the history
Fixes #787
  • Loading branch information
strengejacke committed Dec 20, 2024
1 parent 14a121f commit e5293ca
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Type: Package
Package: performance
Title: Assessment of Regression Models Performance
Version: 0.12.4.14
Version: 0.12.4.15
Authors@R:
c(person(given = "Daniel",
family = "Lüdecke",
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,7 @@ S3method(r2_mcfadden,clm)
S3method(r2_mcfadden,clm2)
S3method(r2_mcfadden,cpglm)
S3method(r2_mcfadden,glm)
S3method(r2_mcfadden,glmmTMB)
S3method(r2_mcfadden,glmx)
S3method(r2_mcfadden,logitmfx)
S3method(r2_mcfadden,logitor)
Expand Down
3 changes: 3 additions & 0 deletions R/r2.R
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,9 @@ r2.glmmTMB <- function(model, ci = NULL, tolerance = 1e-5, verbose = TRUE, ...)
attr(out, "model_type") <- "Logistic"
names(out$R2_Tjur) <- "Tjur's R2"
class(out) <- c("r2_pseudo", class(out))
} else if (info$is_betabinomial) {
# betabinomial default to mcfadden, see pscl:::pR2Work
out <- r2_mcfadden(model)
} else if (info$is_binomial && !info$is_bernoulli) {
# currently, non-bernoulli binomial models are not supported
if (verbose) {
Expand Down
4 changes: 2 additions & 2 deletions R/r2_coxsnell.R
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ r2_coxsnell.glm <- function(model, verbose = TRUE, ...) {
info <- suppressWarnings(insight::model_info(model, verbose = FALSE))
}
# Cox & Snell's R2 is not defined for binomial models that are not Bernoulli models
if (info$is_binomial && !info$is_bernoulli && class(model)[1] == "glm") {
if (info$is_binomial && !info$is_betabinomial && !info$is_bernoulli && class(model)[1] == "glm") {
if (verbose) {
insight::format_alert("Can't calculate accurate R2 for binomial models that are not Bernoulli models.")
}
Expand All @@ -96,7 +96,7 @@ r2_coxsnell.glmmTMB <- function(model, verbose = TRUE, ...) {
info <- suppressWarnings(insight::model_info(model, verbose = FALSE))
}
# Cox & Snell's R2 is not defined for binomial models that are not Bernoulli models
if (info$is_binomial && !info$is_bernoulli) {
if (info$is_binomial && !info$is_bernoulli && !info$is_betabinomial) {
if (verbose) {
insight::format_alert("Can't calculate accurate R2 for binomial models that are not Bernoulli models.")
}
Expand Down
5 changes: 4 additions & 1 deletion R/r2_mcfadden.R
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ r2_mcfadden.glm <- function(model, verbose = TRUE, ...) {
info <- suppressWarnings(insight::model_info(model, verbose = FALSE))
}

if (info$is_binomial && !info$is_bernoulli && class(model)[1] == "glm") {
if (info$is_binomial && !info$is_betabinomial && !info$is_bernoulli && class(model)[1] == "glm") {
if (verbose) {
insight::format_warning("Can't calculate accurate R2 for binomial models that are not Bernoulli models.")
}
Expand Down Expand Up @@ -99,6 +99,9 @@ r2_mcfadden.brmultinom <- r2_mcfadden.glm
#' @export
r2_mcfadden.censReg <- r2_mcfadden.glm

#' @export
r2_mcfadden.glmmTMB <- r2_mcfadden.glm

#' @export
r2_mcfadden.truncreg <- r2_mcfadden.glm

Expand Down

0 comments on commit e5293ca

Please sign in to comment.