gtsummary
gtsummary copied to clipboard
NA values instead of values when using tbl_svysummary for percentages
Hi team! I am having an issue with tbl_svysummary when trying to calculate percentages. The function shows NA values instead of real numbers. I know that there are numbers there, because I am reproducing the results using your package to reduce the amount of code that I typically use for that purpose. Also, when I use tbl_strata(strata = instead of by= parameter, I get the numbers shown. But I would like to use by= because then I can also use add_overall function. I have also tried the dev version of the package (1.7.2.9001).
I am including a subset of the data in CSV and XLSX uploaded to wetransfer. I would very much appreciate, if you could look into this.
https://we.tl/t-098MZlsqyc
The code:
library(srvyr)
sdf <- subset_smoke_vars %>%
as_survey_design(ids=psu, strata=stratum, weights=weight)
sdf %>%
tbl_svysummary(
include = d,
by = sex,
statistic = list(d ~ c("{n_unweighted} ({p}%)")),
value = d ~ "1) daily and non-daily smokers",
digits = d ~ c(0, 1)
) %>%
add_overall(last = TRUE) %>%
add_n(statistic = "{N_obs_unweighted}") %>%
add_ci(
method = all_categorical() ~ "svyprop.mean",
statistic = all_categorical() ~ "{conf.low}-{conf.high}",
style_fun = everything() ~ purrr::partial(style_number, scale = 100, digits = 1)) %>%
modify_header(label = "**Variable**",
all_stat_cols() ~ "**{level}**<br>N = {n_unweighted} ({style_percent(p, digits=1)}%)")
The code when using tbl_strata(strata =:
sdf %>%
tbl_strata(
strata = sex,
~.x %>%
tbl_svysummary(
include = d,
statistic = list(all_categorical() ~ c("{n_unweighted} ({p}%)")),
value = d ~ "1) daily and non-daily smokers",
digits = d ~ c(0, 1),
) %>%
modify_header(stat_0 = "N = {N_unweighted}") %>%
add_ci(
method = all_categorical() ~ "svyprop.mean",
statistic = all_categorical() ~ "{conf.low}-{conf.high}",
style_fun = everything() ~ purrr::partial(style_number, scale = 100, digits = 1))
)
Hi. Can you reproduce the bug with a public datasey? We need a reproductive example to investigate the issue.
Thank you @monitoringhsd , thanks for the post. Please update your example with code I can run on my machine and we can investigate
also to set expectations, there are some other larger changes underway at the moment, and this probably won't be addressed for a couple of months.
Thanks for responding. I have shared the dataset subset and provided the code in my original post. Is it not visible? What is the problem with the data I shared? There was the same issue previously reported on StackOverflow (here), which I could find, and the author claimed that the issue could be overcome by changing factors to character, which did not help in my case, unfortunately.
This could wait for a few months of course. I just hope it is ever addressed or there is a workaround...
The link in your first post does not link to data. Are the subset_smoke_vars or sdf objects available in a package?
Can you please update your post using a proper reprex and please make the example as minimal as possible to illustrate the issue. https://reprex.tidyverse.org/
The link is where you can download the raw data either in CSV or XSLX. It is a website for sharing files. Those data are not available in a package, as those are real data we collected, just a subset to needed columns: psu, strata, weight, indicators. All anonymized of course.
To use the data you need to load either CSV or XLSX into R. Then, use the data as subset_smoke_vars to create the survey design, which is sdf object.
That is the shortest I can get with reprex:
library(here)
library(readr)
subset_smoke_vars <- read_csv("subset_smoke_vars.csv")
library(srvyr)
sdf <- subset_smoke_vars %>%
as_survey_design(ids=psu, strata=stratum, weights=weight)
library(gtsummary)
sdf %>%
tbl_svysummary(
include = d,
by = sex,
statistic = list(d ~ c("{p}")),
) %>%
add_overall(last = TRUE)
If there are any issues with downloading the raw data, here is a sample data presented with reprex. Hope this helps.
# load sample data
sample50 <- tibble::tribble(
~d, ~sex, ~psu, ~stratum, ~weight,
"2) non-smoker", "Women", 129, 1, 570.428745232451,
"2) non-smoker", "Women", 122, 1, 980.098513338906,
"2) non-smoker", "Women", 77, 1, 349.781668236621,
"2) non-smoker", "Women", 23, 2, 508.041871616785,
"2) non-smoker", "Women", 126, 1, 250.966914602411,
"2) non-smoker", "Women", 143, 1, 216.792551887689,
"2) non-smoker", "Women", 52, 2, 1009.4504219415,
"2) non-smoker", "Women", 57, 2, 376.186891669808,
"2) non-smoker", "Women", 53, 1, 486.306994304662,
"2) non-smoker", "Men", 66, 2, 652.304535217158,
"2) non-smoker", "Women", 72, 2, 137.091255196811,
"2) non-smoker", "Women", 110, 1, 1206.34192385692,
"2) non-smoker", "Women", 29, 2, 299.005950970927,
"2) non-smoker", "Women", 38, 2, 651.660408323396,
"2) non-smoker", "Women", 6, 2, 769.065771125992,
"2) non-smoker", "Women", 65, 2, 301.354575385275,
"2) non-smoker", "Men", 61, 2, 502.058631895085,
"2) non-smoker", "Women", 122, 1, 1080.39979714447,
"1) daily and non-daily smokers", "Men", 97, 2, 721.51777433766,
"2) non-smoker", "Women", 84, 1, 523.001879614923,
"2) non-smoker", "Women", 93, 2, 990.72600963312,
"2) non-smoker", "Men", 114, 1, 1861.5526061139,
"2) non-smoker", "Women", 121, 1, 135.345666449381,
"2) non-smoker", "Women", 137, 1, 891.425130787405,
"2) non-smoker", "Women", 14, 1, 150.856962818023,
"2) non-smoker", "Women", 136, 1, 519.696390207245,
"2) non-smoker", "Women", 85, 1, 367.994169125624,
"2) non-smoker", "Women", 10, 2, 156.881331406324,
"2) non-smoker", "Women", 78, 2, 432.323019540056,
"2) non-smoker", "Men", 66, 2, 2609.21814086863,
"2) non-smoker", "Women", 2, 1, 409.307356674454,
"2) non-smoker", "Women", 54, 1, 125.990091739405,
"2) non-smoker", "Women", 108, 1, 120.79925095603,
"2) non-smoker", "Women", 85, 1, 185.225585395517,
"2) non-smoker", "Women", 84, 1, 1046.00375922985,
"2) non-smoker", "Women", 111, 1, 179.543576825804,
"2) non-smoker", "Women", 85, 1, 199.494801469194,
"2) non-smoker", "Women", 4, 1, 904.391314507949,
"2) non-smoker", "Men", 73, 2, 278.627736515156,
"2) non-smoker", "Women", 100, 2, 687.442537296451,
"2) non-smoker", "Men", 90, 2, 714.14643147494,
"2) non-smoker", "Women", 85, 1, 391.686799891435,
"2) non-smoker", "Women", 23, 2, 503.8112834364,
"2) non-smoker", "Women", 12, 2, 336.775946481883,
"2) non-smoker", "Women", 91, 2, 337.523213558805,
"2) non-smoker", "Women", 142, 1, 262.755413086918,
"2) non-smoker", "Women", 136, 1, 695.592570682277,
"2) non-smoker", "Women", 20, 2, 291.945872730565,
"2) non-smoker", "Men", 51, 2, 532.079247284924,
"2) non-smoker", "Women", 57, 2, 564.280337504713
)
library(srvyr)
#>
#> Attaching package: 'srvyr'
#> The following object is masked from 'package:stats':
#>
#> filter
sdf <- sample50 %>%
as_survey_design(ids=psu, strata=stratum, weights=weight)
library(gtsummary)
# show that the values are diplayed as NA
sdf %>%
tbl_svysummary(
include = d,
by = sex,
statistic = list(all_categorical() ~ c("{p}%")),
value = d ~ "1) daily and non-daily smokers",
digits = d ~ c(0, 1)
) %>%
add_overall(last = TRUE)
| Characteristic | Men, N = 7,8721 | Women, N = 20,6041 | Overall, N = 28,4751 |
|---|---|---|---|
| d | NA% | NA% | 3% |
| 1 % | |||
# show that with using tbl_strata() it works sometimes to display the values
sdf %>%
tbl_strata(
strata = sex,
~.x %>%
tbl_svysummary(
include = d,
statistic = list(all_categorical() ~ c("{p}%")),
value = d ~ "1) daily and non-daily smokers",
digits = d ~ c(0, 1)
)
)
| Characteristic | Men | Women |
|---|---|---|
| N = 7,8721 | N = 20,6041 | |
| d | 9% | 0% |
| 1 % | ||
Created on 2024-02-05 with reprex v2.0.2
I have decided to test previous versions one by one (which are available on GitHub) and apparently it worked in version 1.6.0, after which the issue was introduced (from 1.6.1).
# load sample data
sample50 <- tibble::tribble(
~d, ~sex, ~psu, ~stratum, ~weight,
"2) non-smoker", "Women", 129, 1, 570.428745232451,
"2) non-smoker", "Women", 122, 1, 980.098513338906,
"2) non-smoker", "Women", 77, 1, 349.781668236621,
"2) non-smoker", "Women", 23, 2, 508.041871616785,
"2) non-smoker", "Women", 126, 1, 250.966914602411,
"2) non-smoker", "Women", 143, 1, 216.792551887689,
"2) non-smoker", "Women", 52, 2, 1009.4504219415,
"2) non-smoker", "Women", 57, 2, 376.186891669808,
"2) non-smoker", "Women", 53, 1, 486.306994304662,
"2) non-smoker", "Men", 66, 2, 652.304535217158,
"2) non-smoker", "Women", 72, 2, 137.091255196811,
"2) non-smoker", "Women", 110, 1, 1206.34192385692,
"2) non-smoker", "Women", 29, 2, 299.005950970927,
"2) non-smoker", "Women", 38, 2, 651.660408323396,
"2) non-smoker", "Women", 6, 2, 769.065771125992,
"2) non-smoker", "Women", 65, 2, 301.354575385275,
"2) non-smoker", "Men", 61, 2, 502.058631895085,
"2) non-smoker", "Women", 122, 1, 1080.39979714447,
"1) daily and non-daily smokers", "Men", 97, 2, 721.51777433766,
"2) non-smoker", "Women", 84, 1, 523.001879614923,
"2) non-smoker", "Women", 93, 2, 990.72600963312,
"2) non-smoker", "Men", 114, 1, 1861.5526061139,
"2) non-smoker", "Women", 121, 1, 135.345666449381,
"2) non-smoker", "Women", 137, 1, 891.425130787405,
"2) non-smoker", "Women", 14, 1, 150.856962818023,
"2) non-smoker", "Women", 136, 1, 519.696390207245,
"2) non-smoker", "Women", 85, 1, 367.994169125624,
"2) non-smoker", "Women", 10, 2, 156.881331406324,
"2) non-smoker", "Women", 78, 2, 432.323019540056,
"2) non-smoker", "Men", 66, 2, 2609.21814086863,
"2) non-smoker", "Women", 2, 1, 409.307356674454,
"2) non-smoker", "Women", 54, 1, 125.990091739405,
"2) non-smoker", "Women", 108, 1, 120.79925095603,
"2) non-smoker", "Women", 85, 1, 185.225585395517,
"2) non-smoker", "Women", 84, 1, 1046.00375922985,
"2) non-smoker", "Women", 111, 1, 179.543576825804,
"2) non-smoker", "Women", 85, 1, 199.494801469194,
"2) non-smoker", "Women", 4, 1, 904.391314507949,
"2) non-smoker", "Men", 73, 2, 278.627736515156,
"2) non-smoker", "Women", 100, 2, 687.442537296451,
"2) non-smoker", "Men", 90, 2, 714.14643147494,
"2) non-smoker", "Women", 85, 1, 391.686799891435,
"2) non-smoker", "Women", 23, 2, 503.8112834364,
"2) non-smoker", "Women", 12, 2, 336.775946481883,
"2) non-smoker", "Women", 91, 2, 337.523213558805,
"2) non-smoker", "Women", 142, 1, 262.755413086918,
"2) non-smoker", "Women", 136, 1, 695.592570682277,
"2) non-smoker", "Women", 20, 2, 291.945872730565,
"2) non-smoker", "Men", 51, 2, 532.079247284924,
"2) non-smoker", "Women", 57, 2, 564.280337504713
)
library(srvyr)
#>
#> Attaching package: 'srvyr'
#> The following object is masked from 'package:stats':
#>
#> filter
sdf <- sample50 %>%
as_survey_design(ids=psu, strata=stratum, weights=weight)
library(gtsummary)
# show that the values are diplayed as NA
sdf %>%
tbl_svysummary(
include = d,
by = sex,
statistic = list(all_categorical() ~ c("{p}%")),
value = d ~ "1) daily and non-daily smokers",
digits = d ~ c(0, 1)
) %>%
add_overall(last = TRUE)
#> Warning: Since gt v0.6.0 the `fmt_missing()` function is deprecated and will soon be
#> removed.
#> • Use the `sub_missing()` function instead.
#> This warning is displayed once every 8 hours.
| Characteristic | Men, N = 7,8721 | Women, N = 20,6041 | Overall, N = 28,4761 |
|---|---|---|---|
| d | 9% | 0% | 3% |
| 1 % | |||
# show that with using tbl_strata() it works sometimes to display the values
sdf %>%
tbl_strata(
strata = sex,
~.x %>%
tbl_svysummary(
include = d,
statistic = list(all_categorical() ~ c("{p}%")),
value = d ~ "1) daily and non-daily smokers",
digits = d ~ c(0, 1)
)
)
#> ! Use of `vars()` is now deprecated and support will soon be removed. Please replace calls to `vars()` with `c()`.
#> ! Use of `vars()` is now deprecated and support will soon be removed. Please replace calls to `vars()` with `c()`.
| Characteristic | Men | Women |
|---|---|---|
| N = 7,8721 | N = 20,6041 | |
| d | 9% | 0% |
| 1 % | ||
Created on 2024-02-05 with reprex v2.1.0
Session info
sessioninfo::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#> setting value
#> version R version 4.2.2 (2022-10-31)
#> os macOS Ventura 13.6.4
#> system aarch64, darwin20
#> ui X11
#> language (EN)
#> collate en_US.UTF-8
#> ctype en_US.UTF-8
#> date 2024-02-05
#> pandoc 3.1.1 @ /Applications/RStudio.app/Contents/Resources/app/quarto/bin/tools/ (via rmarkdown)
#>
#> ─ Packages ───────────────────────────────────────────────────────────────────
#> package * version date (UTC) lib source
#> broom.helpers 1.14.0 2023-08-07 [1] CRAN (R 4.2.0)
#> cli 3.6.1 2023-03-23 [1] CRAN (R 4.2.0)
#> commonmark 1.9.0 2023-03-17 [1] CRAN (R 4.2.0)
#> DBI 1.1.3 2022-06-18 [1] CRAN (R 4.2.0)
#> digest 0.6.33 2023-07-07 [1] CRAN (R 4.2.0)
#> dplyr 1.1.3 2023-09-03 [1] CRAN (R 4.2.0)
#> evaluate 0.21 2023-05-05 [1] CRAN (R 4.2.0)
#> fansi 1.0.4 2023-01-22 [1] CRAN (R 4.2.0)
#> fastmap 1.1.1 2023-02-24 [1] CRAN (R 4.2.0)
#> forcats 1.0.0 2023-01-29 [1] CRAN (R 4.2.0)
#> fs 1.6.3 2023-07-20 [1] CRAN (R 4.2.0)
#> generics 0.1.3 2022-07-05 [1] CRAN (R 4.2.0)
#> glue 1.6.2 2022-02-24 [1] CRAN (R 4.2.0)
#> gt 0.10.1 2024-01-17 [1] CRAN (R 4.2.3)
#> gtsummary * 1.6.0 2024-02-05 [1] local
#> htmltools 0.5.6 2023-08-10 [1] CRAN (R 4.2.0)
#> knitr 1.43 2023-05-25 [1] CRAN (R 4.2.0)
#> lattice 0.21-8 2023-04-05 [1] CRAN (R 4.2.0)
#> lifecycle 1.0.3 2022-10-07 [1] CRAN (R 4.2.0)
#> magrittr 2.0.3 2022-03-30 [1] CRAN (R 4.2.0)
#> markdown 1.8 2023-08-23 [1] CRAN (R 4.2.2)
#> Matrix 1.5-4.1 2023-05-18 [1] CRAN (R 4.2.0)
#> mitools 2.4 2019-04-26 [1] CRAN (R 4.2.0)
#> pillar 1.9.0 2023-03-22 [1] CRAN (R 4.2.0)
#> pkgconfig 2.0.3 2019-09-22 [1] CRAN (R 4.2.0)
#> purrr 1.0.2 2023-08-10 [1] CRAN (R 4.2.0)
#> R.cache 0.16.0 2022-07-21 [1] CRAN (R 4.2.0)
#> R.methodsS3 1.8.2 2022-06-13 [1] CRAN (R 4.2.0)
#> R.oo 1.25.0 2022-06-12 [1] CRAN (R 4.2.0)
#> R.utils 2.12.2 2022-11-11 [1] CRAN (R 4.2.0)
#> R6 2.5.1 2021-08-19 [1] CRAN (R 4.2.0)
#> reprex 2.1.0 2024-01-11 [1] CRAN (R 4.2.3)
#> rlang 1.1.3 2024-01-10 [1] CRAN (R 4.2.3)
#> rmarkdown 2.25 2023-09-18 [1] CRAN (R 4.2.0)
#> rstudioapi 0.15.0 2023-07-07 [1] CRAN (R 4.2.0)
#> sass 0.4.7 2023-07-15 [1] CRAN (R 4.2.0)
#> sessioninfo 1.2.2 2021-12-06 [1] CRAN (R 4.2.0)
#> srvyr * 1.2.0 2023-02-21 [1] CRAN (R 4.2.0)
#> stringi 1.7.12 2023-01-11 [1] CRAN (R 4.2.0)
#> stringr 1.5.0 2022-12-02 [1] CRAN (R 4.2.0)
#> styler 1.10.1 2023-06-05 [1] CRAN (R 4.2.0)
#> survey 4.2-1 2023-05-03 [1] CRAN (R 4.2.0)
#> survival 3.5-7 2023-08-14 [1] CRAN (R 4.2.0)
#> tibble 3.2.1 2023-03-20 [1] CRAN (R 4.2.0)
#> tidyr 1.3.0 2023-01-24 [1] CRAN (R 4.2.0)
#> tidyselect 1.2.0 2022-10-10 [1] CRAN (R 4.2.0)
#> utf8 1.2.3 2023-01-31 [1] CRAN (R 4.2.0)
#> vctrs 0.6.3 2023-06-14 [1] CRAN (R 4.2.0)
#> withr 2.5.0 2022-03-03 [1] CRAN (R 4.2.0)
#> xfun 0.40 2023-08-09 [1] CRAN (R 4.2.0)
#> xml2 1.3.5 2023-07-06 [1] CRAN (R 4.2.0)
#> yaml 2.3.7 2023-01-23 [1] CRAN (R 4.2.0)
#>
#> [1] /Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library
#>
#> ──────────────────────────────────────────────────────────────────────────────
Something is strange. As long as you transform the vector, everything works OK. Only column percentages are concerned.
library(readr)
subset_smoke_vars <- read_csv("~/subset_smoke_vars.csv")
#> Rows: 2483 Columns: 5
#> ── Column specification ────────────────────────────────────────────────────────
#> Delimiter: ","
#> chr (2): d, sex
#> dbl (3): psu, stratum, weight
#>
#> ℹ Use `spec()` to retrieve the full column specification for this data.
#> ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
subset_smoke_vars$d2 <- as.factor(subset_smoke_vars$d)
subset_smoke_vars$d3 <- as.character(subset_smoke_vars$d2)
subset_smoke_vars$d4 <- subset_smoke_vars$d
library(srvyr)
#>
#> Attachement du package : 'srvyr'
#>
#> L'objet suivant est masqué depuis 'package:stats':
#>
#> filter
sdf <- subset_smoke_vars %>%
as_survey_design(ids=psu, strata=stratum, weights=weight)
library(gtsummary)
sdf %>%
tbl_svysummary(
include = c(d, d2, d3, d4),
by = sex,
statistic = list(all_categorical() ~ c("{p} ({n})")),
) %>%
add_overall(last = TRUE) %>%
as_kable()
| Characteristic | Men, N = 916,263 | Women, N = 838,966 | Overall, N = 1,755,229 |
|---|---|---|---|
| d | |||
| 1) daily and non-daily smokers | NA (277,921) | NA (22,980) | 17 (300,901) |
| 2) non-smoker | 70 (638,342) | 97 (815,985) | 83 (1,454,328) |
| d2 | |||
| 1) daily and non-daily smokers | 30 (277,921) | 2.7 (22,980) | 17 (300,901) |
| 2) non-smoker | 70 (638,342) | 97 (815,985) | 83 (1,454,328) |
| d3 | |||
| 1) daily and non-daily smokers | 30 (277,921) | 2.7 (22,980) | 17 (300,901) |
| 2) non-smoker | 70 (638,342) | 97 (815,985) | 83 (1,454,328) |
| d4 | |||
| 1) daily and non-daily smokers | 30 (277,921) | 2.7 (22,980) | 17 (300,901) |
| 2) non-smoker | 70 (638,342) | 97 (815,985) | 83 (1,454,328) |
sdf %>%
tbl_svysummary(
include = c(d, d2, d3, d4),
by = sex,
statistic = list(all_categorical() ~ c("{p} ({n})")),
percent = "row"
) %>%
add_overall(last = TRUE) %>%
as_kable()
| Characteristic | Men, N = 916,263 | Women, N = 838,966 | Overall, N = 1,755,229 |
|---|---|---|---|
| d | |||
| 1) daily and non-daily smokers | 92 (277,921) | 7.6 (22,980) | 100 (300,901) |
| 2) non-smoker | 44 (638,342) | 56 (815,985) | 100 (1,454,328) |
| d2 | |||
| 1) daily and non-daily smokers | 92 (277,921) | 7.6 (22,980) | 100 (300,901) |
| 2) non-smoker | 44 (638,342) | 56 (815,985) | 100 (1,454,328) |
| d3 | |||
| 1) daily and non-daily smokers | 92 (277,921) | 7.6 (22,980) | 100 (300,901) |
| 2) non-smoker | 44 (638,342) | 56 (815,985) | 100 (1,454,328) |
| d4 | |||
| 1) daily and non-daily smokers | 92 (277,921) | 7.6 (22,980) | 100 (300,901) |
| 2) non-smoker | 44 (638,342) | 56 (815,985) | 100 (1,454,328) |
sdf %>%
tbl_svysummary(
include = c(d, d2, d3, d4),
by = sex,
statistic = list(all_categorical() ~ c("{p} ({n})")),
percent = "cell"
) %>%
add_overall(last = TRUE) %>%
as_kable()
| Characteristic | Men, N = 916,263 | Women, N = 838,966 | Overall, N = 1,755,229 |
|---|---|---|---|
| d | |||
| 1) daily and non-daily smokers | 16 (277,921) | 1.3 (22,980) | 17 (300,901) |
| 2) non-smoker | 36 (638,342) | 46 (815,985) | 83 (1,454,328) |
| d2 | |||
| 1) daily and non-daily smokers | 16 (277,921) | 1.3 (22,980) | 17 (300,901) |
| 2) non-smoker | 36 (638,342) | 46 (815,985) | 83 (1,454,328) |
| d3 | |||
| 1) daily and non-daily smokers | 16 (277,921) | 1.3 (22,980) | 17 (300,901) |
| 2) non-smoker | 36 (638,342) | 46 (815,985) | 83 (1,454,328) |
| d4 | |||
| 1) daily and non-daily smokers | 16 (277,921) | 1.3 (22,980) | 17 (300,901) |
| 2) non-smoker | 36 (638,342) | 46 (815,985) | 83 (1,454,328) |
Created on 2024-02-06 with reprex v2.0.2
Thanks for testing @larmarange. At least, it is a workaround to copy the vector before applying the function. I did not want to downgrade and lose a lot of functionality added over the years.
Hi @larmarange and @monitoringhsd ,
I think this issue is resolved in the dev version of the package. Please re-open if the issue persists!
library(srvyr)
#>
#> Attaching package: 'srvyr'
#> The following object is masked from 'package:stats':
#>
#> filter
library(gtsummary)
packageVersion("gtsummary")
#> [1] '1.9.9.9001'
# load sample data
sample50 <- tibble::tribble(
~d, ~sex, ~psu, ~stratum, ~weight,
"2) non-smoker", "Women", 129, 1, 570.428745232451,
"2) non-smoker", "Women", 122, 1, 980.098513338906,
"2) non-smoker", "Women", 77, 1, 349.781668236621,
"2) non-smoker", "Women", 23, 2, 508.041871616785,
"2) non-smoker", "Women", 126, 1, 250.966914602411,
"2) non-smoker", "Women", 143, 1, 216.792551887689,
"2) non-smoker", "Women", 52, 2, 1009.4504219415,
"2) non-smoker", "Women", 57, 2, 376.186891669808,
"2) non-smoker", "Women", 53, 1, 486.306994304662,
"2) non-smoker", "Men", 66, 2, 652.304535217158,
"2) non-smoker", "Women", 72, 2, 137.091255196811,
"2) non-smoker", "Women", 110, 1, 1206.34192385692,
"2) non-smoker", "Women", 29, 2, 299.005950970927,
"2) non-smoker", "Women", 38, 2, 651.660408323396,
"2) non-smoker", "Women", 6, 2, 769.065771125992,
"2) non-smoker", "Women", 65, 2, 301.354575385275,
"2) non-smoker", "Men", 61, 2, 502.058631895085,
"2) non-smoker", "Women", 122, 1, 1080.39979714447,
"1) daily and non-daily smokers", "Men", 97, 2, 721.51777433766,
"2) non-smoker", "Women", 84, 1, 523.001879614923,
"2) non-smoker", "Women", 93, 2, 990.72600963312,
"2) non-smoker", "Men", 114, 1, 1861.5526061139,
"2) non-smoker", "Women", 121, 1, 135.345666449381,
"2) non-smoker", "Women", 137, 1, 891.425130787405,
"2) non-smoker", "Women", 14, 1, 150.856962818023,
"2) non-smoker", "Women", 136, 1, 519.696390207245,
"2) non-smoker", "Women", 85, 1, 367.994169125624,
"2) non-smoker", "Women", 10, 2, 156.881331406324,
"2) non-smoker", "Women", 78, 2, 432.323019540056,
"2) non-smoker", "Men", 66, 2, 2609.21814086863,
"2) non-smoker", "Women", 2, 1, 409.307356674454,
"2) non-smoker", "Women", 54, 1, 125.990091739405,
"2) non-smoker", "Women", 108, 1, 120.79925095603,
"2) non-smoker", "Women", 85, 1, 185.225585395517,
"2) non-smoker", "Women", 84, 1, 1046.00375922985,
"2) non-smoker", "Women", 111, 1, 179.543576825804,
"2) non-smoker", "Women", 85, 1, 199.494801469194,
"2) non-smoker", "Women", 4, 1, 904.391314507949,
"2) non-smoker", "Men", 73, 2, 278.627736515156,
"2) non-smoker", "Women", 100, 2, 687.442537296451,
"2) non-smoker", "Men", 90, 2, 714.14643147494,
"2) non-smoker", "Women", 85, 1, 391.686799891435,
"2) non-smoker", "Women", 23, 2, 503.8112834364,
"2) non-smoker", "Women", 12, 2, 336.775946481883,
"2) non-smoker", "Women", 91, 2, 337.523213558805,
"2) non-smoker", "Women", 142, 1, 262.755413086918,
"2) non-smoker", "Women", 136, 1, 695.592570682277,
"2) non-smoker", "Women", 20, 2, 291.945872730565,
"2) non-smoker", "Men", 51, 2, 532.079247284924,
"2) non-smoker", "Women", 57, 2, 564.280337504713
)
sdf <- sample50 %>%
as_survey_design(ids=psu, strata=stratum, weights=weight)
sdf %>%
tbl_svysummary(
include = d,
by = sex,
statistic = list(all_categorical() ~ c("{p}%")),
value = d ~ "1) daily and non-daily smokers",
digits = d ~ c(0, 1)
) %>%
add_overall(last = TRUE) |>
as_kable()
| Characteristic | Men N = 7,872 | Women N = 20,604 | Overall N = 28,475 |
|---|---|---|---|
| d | 9.2% | 0% | 2.5% |
Created on 2024-07-01 with reprex v2.1.0
Great for me