Confidence Interval for a Chi-Square & T-Student in R

50 Views Asked by At

So I have this code in R ...

Tabla2 <- tbl_svysummary(data = Beta18.1Pond, by = CTBC, missing = "no", 
                         digits = list(all_continuous() ~ c(2,2)), 
                         include = c(SR, QS23, QS23R, QSSEXO, QS500, QS501U, QS501C, QS50328,
                                     QS505A, QS505B, QS505C, QS505D, QS506, QS2425N, QS25AA, 
                                     QS26, QS27R, QS102, QS109, HV270, Region, HV025, HV009, HV115, 
                                     CTBC)) %>% 
  add_p(test = list(all_continuous() ~ 
                      "svy.t.test", all_categorical() ~ 
                      "svy.adj.chisq.test"), include = everything()) %>%
  modify_header(label ~ "**Variable**") %>%
  modify_spanning_header(c("stat_1", "stat_2") ~ 
                           "**Conocimiento sobre tuberculosis pulmonar**")  %>%
  modify_caption("**Tabla 2. Análisis descriptivo**") 
Tabla2

And i want to add a comand to calculate the confidence interval for a chi-square (in this case a confidence interval for the difference in proportions) and t-test in my table. Anyone knows how could i do it?

Thanks for your responses.

1

There are 1 best solutions below

0
Amira Bedhiafi On

For t-tests, you can simply use add_ci() since it's designed to handle continuous data. For categorical data, I think you need some to transform your chi-square test results into a measure that allows for confidence interval computation, such as converting the chi-square test into a test for proportions if applicable :

Tabla2 <- tbl_svysummary(data = Beta18.1Pond, by = CTBC, missing = "no", 
                         digits = list(all_continuous() ~ c(2,2)), 
                         include = c(SR, QS23, QS23R, QSSEXO, QS500, QS501U, QS501C, QS50328,
                                     QS505A, QS505B, QS505C, QS505D, QS506, QS2425N, QS25AA, 
                                     QS26, QS27R, QS102, QS109, HV270, Region, HV025, HV009, HV115, 
                                     CTBC)) %>% 
  add_p(test = list(all_continuous() ~ 
                      "svy.t.test", all_categorical() ~ 
                      "svy.adj.chisq.test"), include = everything()) %>%
  add_ci(conf.level = 0.95, test = list(all_continuous() ~ "svy.t.test")) %>% # Add CI for t-tests
  modify_header(label ~ "**Variable**") %>%
  modify_spanning_header(c("stat_1", "stat_2") ~ 
                           "**Conocimiento sobre tuberculosis pulmonar**")  %>%
  modify_caption("**Tabla 2. Análisis descriptivo**") 
Tabla2