Skip to content

Commit

Permalink
add transform argument
Browse files Browse the repository at this point in the history
  • Loading branch information
strengejacke committed Mar 16, 2024
1 parent 958fa48 commit bfa9221
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ Imports:
Suggests:
brms,
curl,
DHARMa,
emmeans,
factoextra,
ggdist,
Expand Down
18 changes: 16 additions & 2 deletions R/plot.performance_simres.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,18 @@
#' The `plot()` method for the `performance::check_residuals()` resp.
#' `performance::simulate_residuals()` function.
#'
#' @param transform Function to transform the residuals. If `NULL` (default),
#' no transformation is applied and uniformly distributed residuals are expected.
#' See argument `quantileFuntion` in `?DHARMa:::residuals.DHARMa` for more details.
#'
#' @inheritParams plot.see_check_normality
#' @inheritParams plot.see_check_model
#'
#' @return A ggplot2-object.
#'
#' @seealso See also the vignette about [`check_model()`](https://easystats.github.io/performance/articles/check_model.html).
#'
#' @examplesIf require("performance") && require("glmmTMB") && require("qqplotr")
#' @examplesIf require("performance") && require("glmmTMB") && require("qqplotr") && require("DHARMa")
#' data(Salamanders, package = "glmmTMB")
#' model <- glmmTMB::glmmTMB(
#' count ~ mined + spp + (1 | site),
Expand All @@ -33,13 +37,23 @@ plot.see_performance_simres <- function(x,
dot_alpha = 0.8,
colors = c("#3aaf85", "#1b6ca8"),
detrend = FALSE,
transform = NULL,
style = theme_lucid,
...) {
dp <- list(min = 0, max = 1, lower.tail = TRUE, log.p = FALSE)

# need DHARMa to be installed
insight::check_if_installed("DHARMa")

if (is.null(transform)) {
res <- stats::residuals(x)
} else {
res <- stats::residuals(x, quantileFunction = transform)
}

# base plot information
gg_init <- ggplot2::ggplot(
data.frame(scaled_residuals = stats::residuals(x)),
data.frame(scaled_residuals = res),
ggplot2::aes(sample = .data$scaled_residuals)
)

Expand Down
7 changes: 6 additions & 1 deletion man/plot.see_performance_simres.Rd

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

0 comments on commit bfa9221

Please sign in to comment.