I would like to have an inline_text output with the percentage and ci in parentheses.
I managed to make the table, create the inline_text with the percentage but I couldn’t include the ci.
My table code
tbl1 <- pof_dor_design20 |>
tbl_svysummary(
by = obtem_dor,
include = c(sexo, cor_raca),
label = list(sexo = “Sexo”),
statistic = list(
all_continuous() ~ “{mean}”,
all_categorical() ~ “{p}%”
),
digits = list(
all_continuous() ~ 2,
all_categorical() ~ 1
)
) |>
add_stat_label() |>
add_ci(pattern = “{stat} (CI95%: {ci})”) |>
# add_ci(pattern = ” {stat} ({conf.low}, {conf.high})”) |>
modify_header(all_stat_cols() ~ “{level}“) |>
add_p(
test = list(
all_continuous() ~ “svy.t.test”,
all_categorical() ~ “svy.wald.test”
)
)
print(tbl1)
c0 <- inline_text(tbl1, variable = sexo, level = “1”, column = “1”)
c0
c1 <- inline_text(tbl1, variable = sexo, level = “1”, column = “1”, pattern = “{ci}”)
c1
c2 <- inline_text(tbl1, variable = sexo, level = “1”, column = “1”, pattern = “{conf.low}, {conf.high}”)
c2
Output
enter image description here
ERROR MESSAGE
c0 <- inline_text(tbl1, variable = sexo, level = “1”, column = “1”)
c0
[1] “37.8%”c1 <- inline_text(tbl1, variable = sexo, level = “1”, column = “1”, pattern = “{ci}”)
Error:
! Failed to evaluate glue component {ci}
Caused by error:
! objeto ‘ci’ não encontrado
Runrlang::last_trace()
to see where the error occurred.
Mensagen de aviso:
Use of the “ci” column was deprecated in gtsummary v2.0, and
the column will eventually be removed from the tables.
The “ci” column has been replaced by the merged “conf.low”
and “conf.high” columns (merged with
modify_column_merge()
).
For patterns, replace “{ci}” with “{conf.low},
{conf.high}”.
See deprecated_ci_column for details.
c2 <- inline_text(tbl1, variable = sexo, level = “1”, column = “1”, pattern = “{conf.low}, {conf.high}”)
Error:
! Failed to evaluate glue component {conf.low}
Caused by error:
! objeto ‘conf.low’ não encontrado
Runrlang::last_trace()
to see where the error occurred.
I want
[1] “37.8% (37.0, 39.0)”
1
Here’s an example to get the CI.
library(gtsummary)
packageVersion("gtsummary")
#> [1] '2.0.2'
tbl <- survey::svydesign(~1, data = as.data.frame(Titanic), weights = ~Freq) |>
tbl_svysummary(include = c(Class, Age)) |>
add_ci()
show_header_names(tbl)
#> Column Name Header level* N* n* p* N_unweighted* n_unweighted* p_unweighted*
#> label "**Characteristic**" Overall 2,201 2,201 1.00 32 32 1.00
#> stat_0 "**N = 2,201**" Overall 2,201 2,201 1.00 32 32 1.00
#> ci_stat_0 "**95% CI**" 2,201 32
#> * These values may be dynamically placed into headers (and other locations).
#> ℹ Review the `modify_header()` (`?gtsummary::modify()`) help for examples.
inline_text(tbl, variable = Age, level = "Child", column = "ci_stat_0")
#> 1.5%, 15%
Created on 2024-09-10 with reprex v2.1.0