-
-
Notifications
You must be signed in to change notification settings - Fork 104
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?
Changes from 1 commit
be2373d
37d1de8
f188f3f
a058222
6566a4c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -206,3 +206,53 @@ test_that("`check_model()` with transformed response when named as function", { | |
| out <- check_predictions(model) | ||
| expect_s3_class(out, "performance_pp_check") | ||
| }) | ||
|
|
||
|
|
||
| test_that("`check_model()` with show_dots parameter", { | ||
| data(mtcars) | ||
| m <- lm(mpg ~ factor(cyl) + wt, data = mtcars) | ||
|
|
||
| # Test with show_dots = FALSE | ||
| result <- check_model(m, show_dots = FALSE, verbose = FALSE) | ||
|
|
||
| expect_s3_class(result, "check_model") | ||
| expect_false(attr(result, "show_dots")) | ||
| }) | ||
|
|
||
|
|
||
| test_that("`check_model()` auto-detects categorical predictors", { | ||
| skip_if_not_installed("curl") | ||
|
|
||
| # Load test data | ||
| star <- tryCatch( | ||
| { | ||
| read.csv("https://drmankin.github.io/disc_stats/star.csv") | ||
| }, | ||
| error = function(e) { | ||
| NULL | ||
| } | ||
| ) | ||
|
|
||
| skip_if(is.null(star), message = "Could not download test data") | ||
|
|
||
| star$star2 <- factor(star$star2) | ||
|
|
||
| m <- lm(math2 ~ star2, data = star, na.action = na.exclude) | ||
| 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")) | ||
| }) | ||
|
|
||
|
|
||
| test_that("`check_model()` keeps dots for mixed continuous/categorical models", { | ||
| data(mtcars) | ||
| m <- lm(mpg ~ factor(cyl) + wt + hp, data = mtcars) | ||
|
|
||
| result <- check_model(m, verbose = FALSE) | ||
|
|
||
| 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")) | ||
ANAMASGARD marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| }) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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"))
}) |
||
Uh oh!
There was an error while loading. Please reload this page.