From 5842c1534cd01b71ed65a99352431a133feceb1d Mon Sep 17 00:00:00 2001 From: Daniel Date: Fri, 15 Mar 2024 18:32:01 +0100 Subject: [PATCH] fixes --- R/check_residuals.R | 4 ++-- R/check_zeroinflation.R | 14 ++++++++++---- man/check_zeroinflation.Rd | 10 +++++++++- 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/R/check_residuals.R b/R/check_residuals.R index 628c5cfd0..b04328f25 100644 --- a/R/check_residuals.R +++ b/R/check_residuals.R @@ -42,7 +42,7 @@ check_residuals.default <- function(x, alternative = c("two.sided", "less", "gre #' @export check_residuals.performance_simres <- function(x, alternative = c("two.sided", "less", "greater"), ...) { alternative <- match.arg(alternative) - ts <- suppressWarnings( + ts_test <- suppressWarnings( stats::ks.test( stats::residuals(x), "punif", @@ -51,7 +51,7 @@ check_residuals.performance_simres <- function(x, alternative = c("two.sided", " ) ) - p.val <- ts$p.value + p.val <- ts_test$p.value attr(p.val, "data") <- x attr(p.val, "object_name") <- insight::safe_deparse_symbol(substitute(x)) diff --git a/R/check_zeroinflation.R b/R/check_zeroinflation.R index d8e42fbe0..e392137d1 100644 --- a/R/check_zeroinflation.R +++ b/R/check_zeroinflation.R @@ -7,9 +7,13 @@ #' @param x Fitted model of class `merMod`, `glmmTMB`, `glm`, or `glm.nb` #' (package **MASS**). #' @param tolerance The tolerance for the ratio of observed and predicted -#' zeros to considered as over- or underfitting zeros. A ratio -#' between 1 +/- `tolerance` is considered as OK, while a ratio -#' beyond or below this threshold would indicate over- or underfitting. +#' zeros to considered as over- or underfitting zeros. A ratio +#' between 1 +/- `tolerance` is considered as OK, while a ratio +#' beyond or below this threshold would indicate over- or underfitting. +#' @param alternative A character string specifying the alternative hypothesis. +#' @param ... Arguments passed down to [`simulate_residuals()`]. This only applies +#' for models with zero-inflation component, or for models of class `glmmTMB` +#' from `nbinom1` or `nbinom2` family. #' #' @return A list with information about the amount of predicted and observed #' zeros in the outcome, as well as the ratio between these two values. @@ -23,7 +27,9 @@ #' or hurdle models, the results from `check_zeroinflation()` are likely to be #' unreliable. In such cases, it is recommended to use `simulate_residuals()` #' first, followed by `check_zeroinflation()` to check for zero-inflation, -#' e.g.: `check_zeroinflation(simulate_residuals(model))`. +#' e.g.: `check_zeroinflation(simulate_residuals(model))`. Usually, such models +#' are detected automatically and `check_zeroinflation()` internally calls +#' `simulate_residuals()` if necessary. #' #' @family functions to check model assumptions and and assess model quality #' diff --git a/man/check_zeroinflation.Rd b/man/check_zeroinflation.Rd index 724e2be00..32a2c2143 100644 --- a/man/check_zeroinflation.Rd +++ b/man/check_zeroinflation.Rd @@ -21,10 +21,16 @@ check_zeroinflation(x, ...) \item{x}{Fitted model of class \code{merMod}, \code{glmmTMB}, \code{glm}, or \code{glm.nb} (package \strong{MASS}).} +\item{...}{Arguments passed down to \code{\link[=simulate_residuals]{simulate_residuals()}}. This only applies +for models with zero-inflation component, or for models of class \code{glmmTMB} +from \code{nbinom1} or \code{nbinom2} family.} + \item{tolerance}{The tolerance for the ratio of observed and predicted zeros to considered as over- or underfitting zeros. A ratio between 1 +/- \code{tolerance} is considered as OK, while a ratio beyond or below this threshold would indicate over- or underfitting.} + +\item{alternative}{A character string specifying the alternative hypothesis.} } \value{ A list with information about the amount of predicted and observed @@ -44,7 +50,9 @@ In case of negative binomial models, models with zero-inflation component, or hurdle models, the results from \code{check_zeroinflation()} are likely to be unreliable. In such cases, it is recommended to use \code{simulate_residuals()} first, followed by \code{check_zeroinflation()} to check for zero-inflation, -e.g.: \code{check_zeroinflation(simulate_residuals(model))}. +e.g.: \code{check_zeroinflation(simulate_residuals(model))}. Usually, such models +are detected automatically and \code{check_zeroinflation()} internally calls +\code{simulate_residuals()} if necessary. } \examples{ \dontshow{if (require("glmmTMB") && require("DHARMa")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf}