Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
bbolker committed Oct 24, 2023
2 parents c5c7277 + 3408a7c commit e9c9b46
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 5 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
9 changes: 9 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
# performance 0.10.7

## Changes to functions

* `binned_residuals()` - like `check_model()` - gains a `show_dots` argument to
show or hide data points that lie inside error bounds. This is particular
useful for models with many observations, where generating the plot would be
very slow.

# performance 0.10.6

## General
Expand Down
18 changes: 15 additions & 3 deletions 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,8 +72,14 @@ binned_residuals <- function(model, term = NULL, n_bins = NULL, ...) {
pred <- mf[[term]]
}

y0 <- .recode_to_zero(insight::get_response(model, verbose = FALSE))
y <- y0 - fv
# 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
>>>>>>> upstream/main

if (is.null(n_bins)) n_bins <- round(sqrt(length(pred)))

Expand Down Expand Up @@ -114,6 +125,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
4 changes: 4 additions & 0 deletions R/check_outliers.R
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,10 @@
#' statistical models. Journal of Open Source Software, 6(60), 3139.
#' \doi{10.21105/joss.03139}
#'
#' - Thériault, R., Ben-Shachar, M. S., Patil, I., Lüdecke, D., Wiernik, B. M.,
#' and Makowski, D. (2023). Check your outliers! An introduction to identifying
#' statistical outliers in R with easystats. https://doi.org/10.31234/osf.io/bu6nt
#'
#' - Rousseeuw, P. J., and Van Zomeren, B. C. (1990). Unmasking multivariate
#' outliers and leverage points. Journal of the American Statistical
#' association, 85(411), 633-639.
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.

3 changes: 3 additions & 0 deletions man/check_outliers.Rd

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

0 comments on commit e9c9b46

Please sign in to comment.