From 309e3db8432200db0bdb9970efb99684d3f036a8 Mon Sep 17 00:00:00 2001 From: Daniel Date: Tue, 24 Oct 2023 12:33:27 +0200 Subject: [PATCH] #382 --- DESCRIPTION | 2 +- R/binned_residuals.R | 14 +++++++++++++- man/binned_residuals.Rd | 8 +++++++- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index d72f3909f..cf4108aa7 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Type: Package Package: performance Title: Assessment of Regression Models Performance -Version: 0.10.6.1 +Version: 0.10.6.2 Authors@R: c(person(given = "Daniel", family = "Lüdecke", diff --git a/R/binned_residuals.R b/R/binned_residuals.R index 355ab63c4..286323968 100644 --- a/R/binned_residuals.R +++ b/R/binned_residuals.R @@ -11,6 +11,11 @@ #' @param n_bins Numeric, the number of bins to divide the data. If #' `n_bins = NULL`, the square root of the number of observations is #' taken. +#' @param show_dots Logical, if `TRUE`, will show data points in the plot. Set +#' to `FALSE` for models with many observations, if generating the plot is too +#' time-consuming. By default, `show_dots = NULL`. In this case `binned_residuals()` +#' tries to guess whether performance will be poor due to a very large model +#' and thus automatically shows or hides dots. #' @param ... Currently not used. #' #' @return A data frame representing the data that is mapped in the accompanying @@ -57,7 +62,7 @@ #' } #' #' @export -binned_residuals <- function(model, term = NULL, n_bins = NULL, ...) { +binned_residuals <- function(model, term = NULL, n_bins = NULL, show_dots = NULL, ...) { fv <- stats::fitted(model) mf <- insight::get_data(model, verbose = FALSE) @@ -67,6 +72,12 @@ binned_residuals <- function(model, term = NULL, n_bins = NULL, ...) { pred <- mf[[term]] } + # set default for show_dots, based on "model size" + if (is.null(show_dots)) { + n <- .safe(insight::n_obs(model)) + show_dots <- is.null(n) || n <= 1e5 + } + y <- .recode_to_zero(insight::get_response(model, verbose = FALSE)) - fv if (is.null(n_bins)) n_bins <- round(sqrt(length(pred))) @@ -112,6 +123,7 @@ binned_residuals <- function(model, term = NULL, n_bins = NULL, ...) { attr(d, "resid_ok") <- resid_ok attr(d, "resp_var") <- insight::find_response(model) attr(d, "term") <- term + attr(d, "show_dots") <- show_dots d } diff --git a/man/binned_residuals.Rd b/man/binned_residuals.Rd index ff6fb5784..b8aee666e 100644 --- a/man/binned_residuals.Rd +++ b/man/binned_residuals.Rd @@ -4,7 +4,7 @@ \alias{binned_residuals} \title{Binned residuals for binomial logistic regression} \usage{ -binned_residuals(model, term = NULL, n_bins = NULL, ...) +binned_residuals(model, term = NULL, n_bins = NULL, show_dots = NULL, ...) } \arguments{ \item{model}{A \code{glm}-object with \emph{binomial}-family.} @@ -18,6 +18,12 @@ plotted.} \code{n_bins = NULL}, the square root of the number of observations is taken.} +\item{show_dots}{Logical, if \code{TRUE}, will show data points in the plot. Set +to \code{FALSE} for models with many observations, if generating the plot is too +time-consuming. By default, \code{show_dots = NULL}. In this case \code{binned_residuals()} +tries to guess whether performance will be poor due to a very large model +and thus automatically shows or hides dots.} + \item{...}{Currently not used.} } \value{