Skip to content

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

Done

Description

@jmgirard

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions