-
Notifications
You must be signed in to change notification settings - Fork 108
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
Do not coerce to factor in tbl_svysummary()
#1602
Comments
Because the default (t.test) is not implemented for tbl_svysummary(). You should use "smd", cf. https://www.danieldsjoberg.com/gtsummary/reference/tests.html#tbl-svysummary-add-difference- Currently, |
I was thinking more about the library(gtsummary)
library(PNSIBGE)
pns <- get_pns(year = 2019, labels = TRUE)
pns.2 <- subset(pns, C009 %in% c("Branca", "Preta"))
pns.2$variables$C009 <- as.character(pns.2$variables$C009)
pns.2 |>
gtsummary::tbl_svysummary(by = C009, include = c(C006)) |>
gtsummary::as_kable()
But I just tried to tabulate directly with the survey package, and it still shows all levels, even when the column has previously been converted to a character. So what they are dealing with is a non-standard situation, and they'd just need to write their own method in |
Probably because somewhere the levels are still declared. It is much safier to use fct_drop() through srvyr::mutate() |
But a question remains open: if this is a tbl_svysummary table, should we apply, by default, a relevant test? |
Even dropping the levels with srvry, the unobserved levels appear from the survey function. pns.2 <-
srvyr::as_survey_design(pns) |>
srvyr::filter(C009 %in% c("Branca", "Preta")) |>
srvyr::mutate(C009 = as.character(C009))
survey::svytable(~C009,pns.2)
#> C009
#> Amarela Branca Ignorado Indígena Parda Preta
#> 0 91037722 0 0 0 21786515 |
But, yes, I better default is warrented! |
If I remember, as.character keeps the levels attributes, while forcats::fct_drop() remove unobserved levels. |
Same issue with |
@larmarange see this SO post: https://stackoverflow.com/questions/77957551
Is this something we should address? It seems that the survey method for
subset()
doesn't remove rows, but puts the weights to 0, and users can't remove unobserved levels from by variables intbl_svysummary()
.The text was updated successfully, but these errors were encountered: