-
-
Notifications
You must be signed in to change notification settings - Fork 94
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
performance::r2_nakagawa() and r.squaredGLMM() give different values for Gaussian glmmTMB models without random effects #653
Conversation
…for Gaussian glmmTMB models without random effects Fixes #652
@IndrajeetPatil This new lintr is a bit odd:
The related code is: if (info$is_binomial && !info$is_bernoulli) {
if (verbose) {
insight::format_alert("Can't calculate accurate R2 for binomial models that are not Bernoulli models.")
}
return(NULL)
} How can I reduce this nesting? |
@strengejacke This lint is actually relevant for the entire if/else block: 'r2_nagelkerke.glm <- function(model, verbose = TRUE, ...) {
info <- list(...)$model_info
if (is.null(info)) {
info <- suppressWarnings(insight::model_info(model, verbose = FALSE))
}
if (info$is_binomial && !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.")
}
return(NULL)
} else {
r2cox <- r2_coxsnell(model)
if (is.na(r2cox) || is.null(r2cox)) {
return(NULL)
}
r2_nagelkerke <- r2cox / (1 - exp(-model$null.deviance / insight::n_obs(model, disaggregate = TRUE)))
names(r2_nagelkerke) <- "Nagelkerke\'s R2"
r2_nagelkerke
}
}' -> code
library(lintr)
lint(text = code, linters = unnecessary_nesting_linter())
#> <text>:6:3: warning: [unnecessary_nesting_linter] Reduce the nesting of this if/else statement by unnesting the portion without an exit clause (i.e., stop(), return(), abort(), quit(), q()).
#> if (info$is_binomial && !info$is_bernoulli && class(model)[1] == "glm") {
#> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Created on 2023-11-22 with reprex v2.0.2 Note that, since you are returning early in r2_nagelkerke.glm <- function(model, verbose = TRUE, ...) {
info <- list(...)$model_info
if (is.null(info)) {
info <- suppressWarnings(insight::model_info(model, verbose = FALSE))
}
if (info$is_binomial && !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.")
}
return(NULL)
}
r2cox <- r2_coxsnell(model)
if (is.na(r2cox) || is.null(r2cox)) {
return(NULL)
}
r2_nagelkerke <- r2cox / (1 - exp(-model$null.deviance / insight::n_obs(model, disaggregate = TRUE)))
names(r2_nagelkerke) <- "Nagelkerke\'s R2"
r2_nagelkerke
} Lemme know if you think those are not equivalent. |
Ah, I see! Makes sense. Thanks! |
Fixes #652
summary.lm()
: