Comments (8)
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, add_difference()
does not change the default tests when applied to a tbl_svysummary()
from gtsummary.
I was thinking more about the tbl_svysummary()
table itself. The unobserved columns appear in the table, even if we make the underlying column character.
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()
Characteristic | Amarela, N = 0 | Branca, N = 91,037,722 | Ignorado, N = 0 | Indígena, N = 0 | Parda, N = 0 | Preta, N = 21,786,515 |
---|---|---|---|---|---|---|
C006 | ||||||
Homem | 0 (NA%) | 42,682,905 (47%) | 0 (NA%) | 0 (NA%) | 0 (NA%) | 10,691,164 (49%) |
Mulher | 0 (NA%) | 48,354,817 (53%) | 0 (NA%) | 0 (NA%) | 0 (NA%) | 11,095,351 (51%) |
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 add_stat()
for this, and hide the unobserved columns themselves.
from gtsummary.
Probably because somewhere the levels are still declared. pns.2$variables$C009 <- as.character(pns.2$variables$C009)
did not change metadata stored within the survey object.
It is much safier to use fct_drop() through srvyr::mutate()
from gtsummary.
But a question remains open: if this is a tbl_svysummary table, should we apply, by default, a relevant test?
from gtsummary.
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
from gtsummary.
But, yes, I better default is warrented!
from gtsummary.
If I remember, as.character keeps the levels attributes, while forcats::fct_drop() remove unobserved levels.
from gtsummary.
Same issue with forcats::fct_drop()
unfortunately
from gtsummary.
Related Issues (20)
- Question / Feature request: type "dichotomous" option in tbl_summary not displaying both levels HOT 3
- v2.0 `modify_footnote()` updates HOT 1
- v2.0 README
- Wording in `tbl_uregression()` documentation: univariable instead of univariate? HOT 2
- Compatibility with VGAM HOT 3
- Improve `style_number()` speed?
- Feature request: Informative caption when using `tbl_regression()` with `mice::mira` HOT 2
- v2.0 Add arguments `style_*(prefix, suffix)` ?
- Feature request: Automated suppression of small counts HOT 1
- v2.0 `tbl_stack()`, `tbl_merge()`, `tbl_strata()`, etc.
- `show_header_names()` updates HOT 1
- Feature request: Extend `tbl_merge` to all `gt` tables HOT 2
- Review `tbl_custom_summary()`
- Bug Report: Factor level with `NA` label causes "Column stat_n doesn't exist" error (e.g. created by forcats). HOT 3
- Improve `tbl_summary()` error message for continuous2 type
- v2.0 Add unit test HOT 1
- tbl_strata coding issues HOT 1
- Bug Report: tbl_strata does not treat the values in a small stratum (i.e. with only 7 values) as continuous (despite specification that it should), treats them as categorical HOT 1
- v2.0 Create `card_continuous()`
- Questions about `card_*()` functions.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gtsummary.