Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
strengejacke committed Oct 24, 2023
1 parent e2c16cd commit 309e3db
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
14 changes: 13 additions & 1 deletion R/binned_residuals.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand All @@ -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)))
Expand Down Expand Up @@ -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
}
Expand Down
8 changes: 7 additions & 1 deletion man/binned_residuals.Rd

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

0 comments on commit 309e3db

Please sign in to comment.