使用(gtsummary)tbl_svysummaary 函数显示survey.design 对象的置信区间?
问题说明
我正在使用 tbl_svysummary() 函数从 {survey} 包创建的survey.design 对象生成汇总统计表.使用 add_stat() 函数的方法.但是,我在尝试使用 add_stat() 函数时遇到错误.
I am using the tbl_svysummary() function for producing summary statistics tables from survey.design objects created by the {survey} package. The way one would go about it using the add_stat() function. However, I am facing an error when trying to use the add_stat() function.
ci <- function(vv1, vv2, dsgn) {
svyby( as.formula( paste0( "~" , vv1)) , by = as.formula( paste0( "~" , vv2)), DHSdesign, svyciprop, vartype="ci")
}
tbl_svysummary_ex2 <-
survey::svydesign(id= folate$EA_ID, strata=NULL,
weights = folate$weight,
data = folate) %>%
tbl_svysummary(by = "folate_deficiency",
percent = "row", include = c(folate_deficiency,
age_group,Region_Name, serum_folate,rbc_folate)) %>%
add_stat(
fns = everything() ~ "Ci",
location = "level",
header = "**95% CI**"
) %>%
modify_footnote(everything() ~ NA)
希望有人能帮帮我.
正确答案
您正在寻找的示例表以及我可以在我的机器上运行的代码将有助于您准确找到您正在寻找的内容为了.我在下面创建了一个可重复的示例,我认为它至少可以让您接近您正在寻找的内容?
An example table of what you're looking for along with code that I can run on my machine would have been helpful to get you exactly what you're looking for. I've created a reproducible example below that I think gets you at least close to what you're looking for?
library(gtsummary)
library(survey)
svy_trial <-
svydesign(~1, data = trial %>% select(trt, response, death), weights = ~1)
ci <- function(variable, by, data, ...) {
svyby(as.formula( paste0( "~" , variable)) , by = as.formula( paste0( "~" , by)), data, svyciprop, vartype="ci") %>%
tibble::as_tibble() %>%
dplyr::mutate_at(vars(ci_l, ci_u), ~style_number(., scale = 100) %>% paste0("%")) %>%
dplyr::mutate(ci = stringr::str_glue("{ci_l}, {ci_u}")) %>%
dplyr::select(all_of(c(by, "ci"))) %>%
tidyr::pivot_wider(names_from = all_of(by), values_from = ci) %>%
set_names(paste0("add_stat_", seq_len(ncol(.))))
}
ci("response", "trt", svy_trial)
#> # A tibble: 1 x 2
#> add_stat_1 add_stat_2
#> <glue> <glue>
#> 1 21%, 40% 25%, 44%
svy_trial %>%
tbl_svysummary(by = "trt", missing = "no") %>%
add_stat(everything() ~ "ci") %>%
modify_table_body(
dplyr::relocate, add_stat_1, .after = stat_1
) %>%
modify_header(starts_with("add_stat_") ~ "**95% CI**") %>%
modify_footnote(everything() ~ NA)
这篇好文章是转载于:学新通技术网
- 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
- 本站站名: 学新通技术网
- 本文地址: /reply/detail/tanhcfhfbf
-
YouTube API 不能在 iOS (iPhone/iPad) 工作,但在桌面浏览器工作正常?
it1352 07-30 -
iPhone,一张图像叠加到另一张图像上以创建要保存的新图像?(水印)
it1352 07-17 -
保持在后台运行的 iPhone 应用程序完全可操作
it1352 07-25 -
使用 iPhone 进行移动设备管理
it1352 07-23 -
在android同时打开手电筒和前置摄像头
it1352 09-28 -
扫描 NFC 标签时是否可以启动应用程序?
it1352 08-02 -
检查邮件是否发送成功
it1352 07-25 -
Android微调工具-删除当前选择
it1352 06-20 -
希伯来语的空格句子标记化错误
it1352 06-22 -
Android App 和三星 Galaxy S4 不兼容
it1352 07-20