Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@

## Bug fixes

* `binned_residuals()` now uses the fitted observations for models fitted with
`na.action = na.exclude` (#1038).

* `check_model()` no longer shows the Homogeneity of Variance panel for
binomial models with a binary outcome. For these models, the panel's
reference line is curved even when the model is correct, so earlier plots
Expand Down
4 changes: 2 additions & 2 deletions R/binned_residuals.R
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ binned_residuals <- function(
c("deviance", "pearson", "response")
)

fitted_values <- stats::fitted(model)
fitted_values <- .fitted_rows(stats::fitted(model), model)
mf <- insight::get_data(model, verbose = FALSE)

if (is.null(term)) {
Expand All @@ -157,7 +157,7 @@ binned_residuals <- function(
residuals,
response = y0 - fitted_values,
pearson = .safe((y0 - fitted_values) / sqrt(fitted_values * (1 - fitted_values))),
deviance = .safe(stats::residuals(model, type = "deviance"))
deviance = .fitted_rows(.safe(stats::residuals(model, type = "deviance")), model)
)

# make sure we really have residuals
Expand Down
14 changes: 14 additions & 0 deletions tests/testthat/test-binned_residuals.R
Original file line number Diff line number Diff line change
Expand Up @@ -335,3 +335,17 @@ test_that("binned_residuals, exact CI respects ci argument", {
expected_width_1 <- diff(stats::binom.test(0, res_50$n[1], conf.level = 0.50)$conf.int)
expect_equal(widths_50[1], expected_width_1, tolerance = 1e-6)
})


test_that("binned_residuals uses fitted observations with na.exclude", {
d <- mtcars
d$wt[c(4, 15)] <- NA_real_
m <- glm(am ~ wt + mpg, data = d, family = binomial, na.action = na.exclude)
ref <- update(m, na.action = na.omit)

expect_equal(binned_residuals(m), binned_residuals(ref))
expect_equal(
binned_residuals(m, term = "mpg", residuals = "deviance"),
binned_residuals(ref, term = "mpg", residuals = "deviance")
)
})
Loading