Skip to content
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

Fix ref_grid with missing levels #509

Merged
merged 1 commit into from
Sep 26, 2024
Merged

Conversation

banfai
Copy link
Contributor

@banfai banfai commented Sep 26, 2024

@rvlenth
Copy link
Owner

rvlenth commented Sep 26, 2024

OK, I have look at this as well as the tests in #500, and think this is the right fix for the problem.

@rvlenth rvlenth merged commit ca91c9c into rvlenth:master Sep 26, 2024
1 check passed
@banfai banfai deleted the 508-fix-mising-levs branch September 26, 2024 16:34
@banfai
Copy link
Contributor Author

banfai commented Sep 26, 2024

thanks a lot for the quick review

@rvlenth
Copy link
Owner

rvlenth commented Sep 26, 2024

PS -- I added tests for the case where we allow factors to have NA levels:

# Missing and NA levels
miss.df = data.frame(x = factor(c("a", "a", "b", NA), levels = c("a", "b", "c", NA)), y = 1:4)
miss.lm = lm(y ~ x, data = miss.df)
miss.rg1 = ref_grid(miss.lm)
miss.rg2 = ref_grid(miss.lm, data = miss.df)
# Now try allowing NA levels
miss.dfa = transform(miss.df, x = factor(x, exclude = NULL))
miss.lma = lm(y ~ x, data = miss.dfa)
miss.rg1a = ref_grid(miss.lma)
miss.rg2a = ref_grid(miss.lma, data = miss.dfa)
test_that("Reference grid handles missing values", {
    expect_equal(length(miss.rg1@levels$x), 2)
    expect_equal(length(miss.rg2@levels$x), 2)
    expect_equal(length(miss.rg1a@levels$x), 3)
    expect_equal(length(miss.rg2a@levels$x), 3)
    emm_options(allow.na.levs = FALSE)
    expect_error(ref_grid(miss.lma))
    emm_options(allow.na.levs = NULL) # revert to default
})

Happy to say they all pass!

Thanks for the contribution!

@rvlenth
Copy link
Owner

rvlenth commented Sep 26, 2024

Please confirm that this is correct for you in the DESCRIPTION file:

    person("Balasz", "Banfai", role = "ctb"),

@banfai
Copy link
Contributor Author

banfai commented Sep 26, 2024

Please confirm that this is correct for you in the DESCRIPTION file:

z and s are the other way around:

    person("Balazs", "Banfai", role = "ctb"),

PS -- I added tests for the case where we allow factors to have NA levels:
Happy to say they all pass!
Thanks for the contribution!

That's great, thanks for expanding the tests. Happy to contribute to this amazing package!

rvlenth added a commit that referenced this pull request Oct 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Inconsistent results with missing levels since #500
2 participants