svycipop --> gtsummary

How to display svyciprop (survey package) results in gt summary ?

table90 <- svyciprop(~I(covered_prop==1), dclus1, method="me", level=0.90, df=degf(dclus1))

                              5%  95%
I(covered_prop == 1) 0.451 0.277 0.63

Here's an example how to merge the CI into the table. Happy Programming!

library(gtsummary)
packageVersion("gtsummary")
#> [1] '1.5.0'

svy <- survey::svydesign(~1, data = as.data.frame(Titanic), weights = ~Freq) 

# put the CI in a tibble with the variable name
tbl_ci <-
  survey::svyciprop(~I(Sex == "Female"), svy) %>%
  attr("ci") %>%
  style_sigfig(scale = 100) %>%
  paste0("%", collapse = ", ") %>%
  {tibble::tibble(variable = "Sex", ci = .)}

tbl <-
  svy %>%
  tbl_svysummary(
    include = Sex,
    value = Sex ~ "Female"
  ) %>%
  # merge in the CI to the gtsummary table
  modify_table_body(
    ~.x %>%
      dplyr::left_join(
        tbl_ci, 
        by = "variable"
      )
  ) %>%
  modify_header(ci = "**95% CI**")

Created on 2021-11-23 by the reprex package (v2.0.1)

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.