Skip to content

Commit

Permalink
fix issues
Browse files Browse the repository at this point in the history
  • Loading branch information
strengejacke committed Mar 16, 2024
1 parent d0822ba commit 7111028
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 21 deletions.
4 changes: 2 additions & 2 deletions R/check_model.R
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ check_model.model_fit <- function(x,

dat$VIF <- .diag_vif(model, verbose = verbose)
dat$QQ <- switch(residual_type,
simulated = simulate_residuals(model),
simulated = simulate_residuals(model, ...),
.diag_qq(model, model_info = model_info, verbose = verbose)
)
dat$REQQ <- .diag_reqq(model, level = 0.95, model_info = model_info, verbose = verbose)
Expand Down Expand Up @@ -404,7 +404,7 @@ check_model.model_fit <- function(x,
dat$VIF <- .diag_vif(model, verbose = verbose)
dat$QQ <- switch(
residual_type,
simulated = simulate_residuals(model),
simulated = simulate_residuals(model, ...),
.diag_qq(model, model_info = model_info, verbose = verbose)
)
dat$HOMOGENEITY <- .diag_homogeneity(model, verbose = verbose)
Expand Down
13 changes: 7 additions & 6 deletions R/check_overdispersion.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
#'
#' @param x Fitted model of class `merMod`, `glmmTMB`, `glm`, or `glm.nb`
#' (package **MASS**), or an object returned by `simulate_residuals()`.
#' @param ... Currently not used.
#'
#' @inheritParams check_zeroinflation
#'
#' @return A list with results from the overdispersion test, like chi-squared
#' statistics, p-value or dispersion ratio.
Expand Down Expand Up @@ -153,6 +154,9 @@ print.check_overdisp <- function(x, digits = 3, ...) {

#' @export
check_overdispersion.glm <- function(x, verbose = TRUE, ...) {
# for warning message
model_name <- insight::safe_deparse(substitute(x))

# check if we have poisson
info <- insight::model_info(x)
if (!info$is_count && !info$is_binomial) {
Expand Down Expand Up @@ -295,16 +299,13 @@ check_overdispersion.glmmTMB <- check_overdispersion.merMod

#' @rdname check_overdispersion
#' @export
check_overdispersion.performance_simres <- function(x,
tolerance = 0.1,
alternative = c("two.sided", "less", "greater"),
...) {
check_overdispersion.performance_simres <- function(x, alternative = c("two.sided", "less", "greater"), ...) {
# match arguments
alternative <- match.arg(alternative)

# statistics function
variance <- stats::sd(x$simulatedResponse)^2
dispersion <- function(i) var(i - x$fittedPredictedResponse) / variance
dispersion <- function(i) stats::var(i - x$fittedPredictedResponse) / variance

# compute test results
result <- .simres_statistics(x, statistic_fun = dispersion, alternative = alternative)
Expand Down
4 changes: 3 additions & 1 deletion R/simulate_residuals.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ simulate_residuals <- function(x, iterations = 250, ...) {
# TODO (low priority): Note that DHARMa::simulateResiduals(x, ...) does its own checks for whether
# or not the model passed to it is supported, do we want to use this or do our
# own checks so we can supply our own error message?
#
if (iterations < 2) {
insight::format_error("`iterations` must be at least 2.")
}
# It's important to preserve this object as is, rather than prematurely
# extracting the residuals from it because the object contains important stuff
# in it that we'll want to pass onto other functions later, such as passing
Expand Down
7 changes: 7 additions & 0 deletions inst/WORDLIST
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ DOI
Datenerhebung
Delacre
Deskriptivstatistische
DHARMa
Distinguishability
Dom
Dominicy
Expand Down Expand Up @@ -76,6 +77,7 @@ Gazen
Gelman
Gnanadesikan
Guilford
Hartig
HDI
HJ
Hastie
Expand Down Expand Up @@ -124,6 +126,7 @@ Ley
Leys
Lillo
Liu
Lohse
Lomax
MADs
MSA
Expand Down Expand Up @@ -182,6 +185,7 @@ Sensivity
Shachar
Shinichi
Skrondal
Smyth
Solomons
Somers
Specifity
Expand Down Expand Up @@ -279,6 +283,7 @@ metafor
mfx
mhurdle
mis
misspecification
mlm
mlogit
modelfit
Expand All @@ -302,6 +307,7 @@ quartile
quartiles
rOpenSci
recoding
reimplement
rempsyc
reproducibility
rescaling
Expand All @@ -325,6 +331,7 @@ unadjusted
und
underfitted
underfitting
underdispersion
visualisation
winsorization
winsorize
Expand Down
13 changes: 6 additions & 7 deletions man/check_overdispersion.Rd

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

7 changes: 2 additions & 5 deletions tests/testthat/test-check_model.R
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,8 @@ test_that("`check_model()` warnings for tweedie", {
))
expect_message(
expect_message(
expect_message(
check_model(m, iterations = 1, verbose = TRUE),
regex = "Not enough model terms"
),
regex = "QQ plot could not"
check_model(m, iterations = 2, verbose = TRUE),
regex = "Not enough model terms"
)
)
})
2 changes: 2 additions & 0 deletions tests/testthat/test-check_residuals.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ test_that("check_singularity, lme4", {
capture.output(print(out)),
"Warning: Non-uniformity of simulated residuals detected (p = 0.019)."
)
expect_error(simulate_residuals(m, iterations = 1), "`iterations` must be")

skip_if_not_installed("MASS")
set.seed(3)
mu <- rpois(500, lambda = 3)
Expand Down

0 comments on commit 7111028

Please sign in to comment.