Skip to content

Commit

Permalink
docs, test
Browse files Browse the repository at this point in the history
  • Loading branch information
strengejacke committed Mar 20, 2024
1 parent 9417ce0 commit 7314c28
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 8 deletions.
3 changes: 2 additions & 1 deletion R/check_residuals.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
#'
#' @inheritSection simulate_residuals Tests based on simulated residuals
#'
#' @seealso [`simulate_residuals()`] and [`check_predictions()`].
#' @seealso [`simulate_residuals()`], [`check_zeroinflation()`],
#' [`check_overdispersion()`] and [`check_predictions()`].
#'
#' @return The p-value of the test statistics.
#'
Expand Down
10 changes: 6 additions & 4 deletions R/simulate_residuals.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
#' [`check_residuals()`]. The returned object is of class `DHARMa` and
#' `performance_simres`.
#'
#' @seealso [`check_residuals()`] and [`check_predictions()`].
#' @seealso [`check_residuals()`], [`check_zeroinflation()`],
#' [`check_overdispersion()`] and [`check_predictions()`].
#'
#' @details This function is a small wrapper around [`DHARMa::simulateResiduals()`].
#' It basically only sets `plot = FALSE` and adds an additional class attribute
Expand Down Expand Up @@ -88,9 +89,10 @@ print.performance_simres <- function(x, ...) {
# DHARMa's method.
msg <- paste0(
"Simulated residuals from a model of class `", class(x$fittedModel)[1],
"` based on ", x$nSim, " simulations. Use `check_residuals()` to check ",
"uniformity of residuals. It is recommended to refer to `?DHARMa::simulateResiudals`",
" and `vignette(\"DHARMa\")` for more information about different settings",
"` based on ", x$nSim, " simulations. Use `check_residuals()` to check",
" uniformity of residuals or `residuals()` to extract simulated residuals.",
" It is recommended to refer to `?DHARMa::simulateResiudals` and",
" `vignette(\"DHARMa\")` for more information about different settings",
" in particular situations or for particular models.\n"
)
cat(insight::format_message(msg))
Expand Down
3 changes: 2 additions & 1 deletion man/check_residuals.Rd

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

3 changes: 2 additions & 1 deletion man/simulate_residuals.Rd

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

14 changes: 13 additions & 1 deletion tests/testthat/test-check_residuals.R
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
test_that("check_singularity, lme4", {
test_that("check_residuals", {
skip_on_cran()
skip_if_not_installed("DHARMa")
set.seed(123)
dat <- DHARMa::createData(sampleSize = 100, overdispersion = 0.5, family = poisson())
m <- glm(observedResponse ~ Environment1, family = poisson(), data = dat)
res <- simulate_residuals(m)
expect_identical(
capture.output(print(res)),
c(
"Simulated residuals from a model of class `glm` based on 250",
" simulations. Use `check_residuals()` to check uniformity of residuals or",
" `residuals()` to extract simulated residuals. It is recommended to refer",
" to `?DHARMa::simulateResiudals` and `vignette(\"DHARMa\")` for more",
" information about different settings in particular situations or for",
" particular models."
)
)

out <- check_residuals(res)
expect_equal(out, 0.01884602, ignore_attr = TRUE, tolerance = 1e-4)
expect_identical(
Expand Down

0 comments on commit 7314c28

Please sign in to comment.