gt table merge: merging as_survey design with prevalence and confidence interval

I want to merge three tables; code below-

baro_weightedpointprevalence_srvyr <- table3_baro %>%
as_survey_design(ids=grappe_no,fpc=fpc, weights=HH_weight_normalized)

  table <- baro_weightedpointprevalence_srvyr  %>%
  group_by(GAM_any) %>%
  summarize(proportion=survey_prop(vartype="ci", level=.95),
            total=survey_total(na.rm=TRUE))             
  
  table3_baro <- table %>% select(-starts_with("total_"))


gt(table3_baro)  |>
 gt::cols_label(GAM_any = "GAM- any",
  proportion = "Prevalence",
  proportion_low = "Lower Bound- 95% CI",
  proportion_upp="Upper Bound- 95% CI",
  total = "Count") |> 
  tab_spanner("Proportion", contains("prop")) |> 
  tab_spanner("Total", contains("total")) |> 
  tab_header(title=md("**Baro**")) |>
  fmt_percent(contains("prop"), drop_trailing_zeros = T, decimals=1) |> 
  cols_width(proportion:total ~ px(75))

#95% CI. 
melfi_weightedpointprevalence_srvyr <- table3_melfi %>%
as_survey_design(ids=grappe_no,fpc=fpc, weights=HH_weight_normalized)

  table <- melfi_weightedpointprevalence_srvyr  %>%
  group_by(GAM_any) %>%
  summarize(proportion=survey_prop(vartype="ci", level=.95),
            total=survey_total(na.rm=TRUE))             
  
  table3_melfi <- table %>% select(-starts_with("total_"))


gt(table3_melfi)  |>
 gt::cols_label(GAM_any = "GAM- any",
  proportion = "Prevalence",
  proportion_low = "Lower Bound- 95% CI",
  proportion_upp="Upper Bound- 95% CI",
  total = "Count") |> 
  tab_spanner("Proportion", contains("prop")) |> 
  tab_spanner("Total", contains("total")) |> 
  tab_header(title=md("**Melfi**")) |>
  fmt_percent(contains("prop"), drop_trailing_zeros = T, decimals=1) |> 
  cols_width(proportion:total ~ px(75))

#95% CI. 
mangalme_weightedpointprevalence_srvyr <- table3_mangalme %>%
as_survey_design(ids=grappe_no,fpc=fpc, weights=HH_weight_normalized)

  table <- mangalme_weightedpointprevalence_srvyr  %>%
  group_by(GAM_any) %>%
  summarize(proportion=survey_prop(vartype="ci", level=.95),
            total=survey_total(na.rm=TRUE))             
  
  table3_mangalme <- table %>% select(-starts_with("total_"))


gt(table3_mangalme)  |>
 gt::cols_label(GAM_any = "GAM- any",
  proportion = "Prevalence",
  proportion_low = "Lower Bound- 95% CI",
  proportion_upp="Upper Bound- 95% CI",
  total = "Count") |> 
  tab_spanner("Proportion", contains("prop")) |> 
  tab_spanner("Total", contains("total")) |> 
  tab_header(title=md("**Mangalme**")) |>
  fmt_percent(contains("prop"), drop_trailing_zeros = T, decimals=1) |> 
  cols_width(proportion:total ~ px(75))

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.