-
Notifications
You must be signed in to change notification settings - Fork 130
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
Bug Report: tbl_summary throws error when grouping and data contains a factor filled with NAs #977
Comments
Thank you @erikvona for reporting the bug! I am surprised this hasn't been addressed previously. We'll ensure this fix makes it into the next release |
The issue here is that the factor variable has no levels, FYI. If there is a level, the function doesn't return an error. trial %>%
dplyr::mutate(
has_banana = factor(NA, levels = "level") # We don't know which patients have a banana
) %>%
tbl_summary(by = trt, include = has_banana) |
@ddsjoberg That's true, but if the factor has levels, |
Thanks for adding the second example. I am surprised to see that the > with(df, table(has_banana, trt))
trt
has_banana Drug A Drug B
Yes 0 0
No 0 0
> with(df, table(has_banana, trt)) %>%
+ fisher.test()
Fisher's Exact Test for Count Data
data: .
p-value = 1
alternative hypothesis: true odds ratio is not equal to 1
95 percent confidence interval:
0 Inf
sample estimates:
odds ratio
0 |
I'm using tbl_summary programmatically.
If I have a table with a factor variable and all values happen to be NA, an error occurs:
Reprex:
If the factor has levels,
tbl_summary
works, butadd_p
fails:(I tend to run a
fct_drop
across all factors so mine don't have levels, but it would be nice if both could get fixed so tbl_summary and add_p could produce valid output for any factor).The text was updated successfully, but these errors were encountered: