-
-
Notifications
You must be signed in to change notification settings - Fork 103
Fix check_model() plots for categorical predictors #874
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Fix check_model() plots for categorical predictors #874
Conversation
- Add show_dots auto-detection for models with only categorical predictors - Implement .has_only_categorical_predictors() helper function - Add comprehensive tests for new functionality - Update documentation and NEWS.md FIXES easystats#873
Summary of ChangesHello @ANAMASGARD, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request addresses a visualization challenge within the Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request introduces a helpful feature to improve plot readability for models with only categorical predictors by automatically hiding data points. The implementation is mostly solid, with good documentation and initial tests.
My review focuses on improving the robustness of the new predictor detection logic and strengthening the tests:
- I've identified and suggested a fix for a couple of bugs in the
.has_only_categorical_predictors()helper function that could lead to misclassifying predictors, particularly for factors not explicitly wrapped infactor()and for binary factors created in the formula. - I've also suggested making one of the new tests more precise and adding another test case to cover a scenario that was initially buggy.
Overall, these are great changes that will improve the user experience. The suggested fixes will make the new feature more reliable across different model specifications.
| expect_s3_class(result, "check_model") | ||
| # Should keep dots by default for mixed models | ||
| expect_true(is.null(attr(result, "show_dots")) || attr(result, "show_dots")) | ||
| }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be beneficial to add a test case for a model with a single binary predictor that is converted to a factor within the formula. This was a scenario where the original implementation had a bug, and adding a test for it would prevent regressions.
Here is a suggested test:
test_that("`check_model()` auto-disables dots for binary factor in formula", {
data(mtcars)
m <- lm(mpg ~ as.factor(am), data = mtcars)
result <- check_model(m, verbose = FALSE)
# Should auto-disable dots for categorical-only models
expect_s3_class(result, "check_model")
expect_false(attr(result, "show_dots"))
})|
Can you show an example before and after image? I'm not following why hiding the dots is the correct fix here |
- Fix binary factor detection (e.g., as.factor(am)) - Improve regex to distinguish continuous vs categorical predictors - Add test for binary factors - Make mixed model test more precise
|
Sir @bwiernik
But @strengejacke makes a good point - hiding the CI bands might be the better fix. The dots aren't really the problem; the CI is what's making the plots unreadable (as originally reported in #642). |
|
Could you paste examples of the before and after images here? |
|


Fixes #873
The linearity and variance plots were hard to read when models had only
categorical predictors - the confidence ribbons were huge and covered up
the actual data pattern.
Now check_model() detects when all predictors are categorical and hides
the dots automatically. Makes the variance across groups way easier to see.
Works with factor(x), as.factor(x), or variables that are already factors.
If your model has both categorical and continuous predictors, it still
shows dots like before.
You can override this with show_dots = TRUE if you want the old behavior.
Added tests, updated docs. Everything passes locally on my system .