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

QQ plot blank in check model for glmmTMB with tweedie distribution #693

Merged
merged 3 commits into from
Mar 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.10.9.2
Version: 0.10.9.3
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 @@ -457,6 +457,7 @@ S3method(r2_mcfadden,poissonirr)
S3method(r2_mcfadden,poissonmfx)
S3method(r2_mcfadden,polr)
S3method(r2_mcfadden,probitmfx)
S3method(r2_mcfadden,serp)
S3method(r2_mcfadden,truncreg)
S3method(r2_mcfadden,vglm)
S3method(r2_mckelvey,default)
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

* Rudimentary support for models of class `serp` from package *serp*.

## General

* Improved error messages for `check_model()` when QQ-plots cannot be created.

## Bug fixes

* Fixed issue in `check_normality()` for t-tests.
Expand Down
2 changes: 1 addition & 1 deletion R/check_model.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#' @param check Character vector, indicating which checks for should be performed
#' and plotted. May be one or more of `"all"`, `"vif"`, `"qq"`, `"normality"`,
#' `"linearity"`, `"ncv"`, `"homogeneity"`, `"outliers"`, `"reqq"`, `"pp_check"`,
#' `"binned_residuals"` or `"overdispersion"`, Not that not all check apply
#' `"binned_residuals"` or `"overdispersion"`. Note that not all check apply
#' to all type of models (see 'Details'). `"reqq"` is a QQ-plot for random
#' effects and only available for mixed models. `"ncv"` is an alias for
#' `"linearity"`, and checks for non-constant variance, i.e. for
Expand Down Expand Up @@ -49,7 +49,7 @@
#'
#' @details For Bayesian models from packages **rstanarm** or **brms**,
#' models will be "converted" to their frequentist counterpart, using
#' [`bayestestR::bayesian_as_frequentist`](https://easystats.github.io/bayestestR/reference/convert_bayesian_as_frequentist.html).

Check warning on line 52 in R/check_model.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/check_model.R,line=52,col=121,[line_length_linter] Lines should not be more than 120 characters. This line is 130 characters.
#' A more advanced model-check for Bayesian models will be implemented at a
#' later stage.
#'
Expand Down Expand Up @@ -77,7 +77,7 @@
#' plots are helpful to check model assumptions, they do not necessarily indicate
#' so-called "lack of fit", e.g. missed non-linear relationships or interactions.
#' Thus, it is always recommended to also look at
#' [effect plots, including partial residuals](https://strengejacke.github.io/ggeffects/articles/introduction_partial_residuals.html).

Check warning on line 80 in R/check_model.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/check_model.R,line=80,col=121,[line_length_linter] Lines should not be more than 120 characters. This line is 134 characters.
#'
#' @section Homogeneity of Variance:
#' This plot checks the assumption of equal variance (homoscedasticity). The
Expand Down
19 changes: 15 additions & 4 deletions R/check_model_diagnostics.R
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,23 @@
}
}

if (is.null(res_)) {
if (is.null(res_) || all(is.na(res_))) {
if (verbose) {
if (is.null(model_info$family)) {
fam <- "model"

Check warning on line 57 in R/check_model_diagnostics.R

View check run for this annotation

Codecov / codecov/patch

R/check_model_diagnostics.R#L57

Added line #L57 was not covered by tests
} else {
fam <- paste0("`", model_info$family, "`")
}
insight::format_alert(
sprintf(
"QQ plot could not be created. Cannot extract residuals from objects of class `%s`.",
class(model)[1]
paste(
sprintf(
"QQ plot could not be created. Cannot extract residuals from objects of class `%s`.",
class(model)[1]
),
sprintf(
"Maybe the model class or the %s family does not support the computation of (deviance) residuals?",
fam
)
)
)
}
Expand Down
2 changes: 1 addition & 1 deletion man/check_model.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions tests/testthat/test-check_model.R
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,24 @@ test_that("`check_model()` works for quantreg", {
x <- check_model(qm, verbose = FALSE)
expect_s3_class(x, "check_model")
})

test_that("`check_model()` warnings for tweedie", {
skip_if_not_installed("glmmTMB")
skip_if_not_installed("lme4")
data(sleepstudy, package = "lme4")
set.seed(123)
d <- sleepstudy[sample.int(50), ]
m <- suppressWarnings(glmmTMB::glmmTMB(Reaction ~ Days,
data = d,
family = glmmTMB::tweedie
))
expect_message(
expect_message(
expect_message(
check_model(m, iterations = 1, verbose = TRUE),
regex = "Not enough model terms"
),
regex = "QQ plot could not"
)
)
})
Loading