From bb1a2f36b9f1d0a81ae9a9738d49ce09df13e68b Mon Sep 17 00:00:00 2001 From: Michael McCarthy <51542091+mccarthy-m-g@users.noreply.github.com> Date: Thu, 26 Oct 2023 16:19:03 -0700 Subject: [PATCH] draft `check_residuals()` --- R/check_residuals.R | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 R/check_residuals.R diff --git a/R/check_residuals.R b/R/check_residuals.R new file mode 100644 index 000000000..e5b649307 --- /dev/null +++ b/R/check_residuals.R @@ -0,0 +1,22 @@ +#' Check uniformity of simulated residuals +#' +#' `check_residuals()` checks generalized linear (mixed) models for uniformity +#' of randomized quantile residuals, which can be used to identify typical model +#' misspecification problems, such as over/underdispersion, zero-inflation, and +#' residual spatial and temporal autocorrelation. +#' +#' @export +check_residuals <- function(x, ...) { + # TODO: This should be an S3 method instead of using ifelse + if (any(class(x) %in% c("performance_simres", "DHARMa"))) { + # tests if the overall distribution conforms to expectations; equivalent to: + # ks.test(residuals(simulated_residuals), "punif") + DHARMa::testUniformity(x, plot = FALSE, ...) + } else { + stop("Unsupported input") + } +} + +# methods ------------------------------ + +# TODO: Add print method