binned_residuals() fails for models fitted with na.action = na.exclude

Open Beginner friendly
#1,038 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
78/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
r

Research direction

Start with the binned_residuals() implementation and reproduce the provided glm() example with na.action = na.exclude. Inspect the existing test-check_model.R cases, including the overdispersion tests, then add a regression test for the missing-predictor case. Done means excluded observations are handled without length mismatch, binned_residuals(m) succeeds, and the check_model() Binned Residuals panel is shown.

Written by the indexing model from the issue text.

Description

binned_residuals() errors for a logistic regression fitted with na.action = na.exclude when a predictor has a missing value:

library(performance)
d <- transform(mtcars, x = replace(wt, 1, NA_real_))
m <- glm(am ~ x, data = d, family = binomial, na.action = na.exclude)
binned_residuals(m)
#> Error in binned_residuals(m): 'x' must be nonnegative and integer
#> In addition: Warning message:
#> In y0 - fitted_values :
#>   longer object length is not a multiple of shorter object length

The response still includes the excluded row, but the fitted values don't, so the two vectors have different lengths. With the default na.omit it works. check_model() calls binned_residuals() inside .safe(), so for these models the Binned Residuals panel just goes missing without a message. The package's tests already use na.exclude with glm fits in check_model() (test-check_model.R, the overdispersion tests).

Dominant language
R
Stars
1.2k
Forks
113
Avg merge
9h 8m
Merged PRs (30d)
27

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from easystats/performance

All issues in easystats/performance

Similar issues

More R issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.