Skip to content

Commit

Permalink
allow to directly pass models
Browse files Browse the repository at this point in the history
  • Loading branch information
strengejacke committed Mar 15, 2024
1 parent 85817fe commit 764dcdf
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
14 changes: 8 additions & 6 deletions R/check_residuals.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,18 @@ check_residuals <- function(x, ...) {
UseMethod("check_residuals")
}

#' @rdname check_residuals
#' @export
check_residuals.default <- function(x, ...) {
insight::format_error("`check_residuals()` only works with objects returned by `simulate_residuals()` or `DHARMa::simulateResiduals()`.") # nolint
check_residuals.default <- function(x, alternative = c("two.sided", "less", "greater"), ...) {
if (insight::is_model(x)) {
check_residuals(simulate_residuals(x, ...), alternative = alternative)
} else {
insight::format_error("`check_residuals()` only works with objects supported by `simulate_residuals()` or `DHARMa::simulateResiduals()`.") # nolint
}
}

#' @rdname check_residuals
#' @export
check_residuals.performance_simres <- function(x,
alternative = c("two.sided", "less", "greater"),
...) {
check_residuals.performance_simres <- function(x, alternative = c("two.sided", "less", "greater"), ...) {
alternative <- match.arg(alternative)
ts <- suppressWarnings(

Check warning on line 45 in R/check_residuals.R

View workflow job for this annotation

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

file=R/check_residuals.R,line=45,col=3,[object_overwrite_linter] 'ts' is an exported object from package 'stats'. Avoid re-using such symbols.
stats::ks.test(
Expand Down
4 changes: 2 additions & 2 deletions man/check_residuals.Rd

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

10 changes: 10 additions & 0 deletions tests/testthat/test-check_residuals.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,14 @@ test_that("check_singularity, lme4", {
capture.output(print(out)),
"Warning: Non-uniformity of simulated residuals detected (p = 0.019)."
)
skip_if_not_installed("MASS")
set.seed(3)
mu <- rpois(500, lambda = 3)
x <- rnorm(500, mu, mu * 3)
x <- ceiling(x)
x <- pmax(x, 0)
quine.nb1 <- MASS::glm.nb(x ~ mu)
set.seed(123)
result <- check_residuals(quine.nb1)
expect_equal(result, 0.000665414, tolerance = 1e-3)
})

0 comments on commit 764dcdf

Please sign in to comment.