作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 gtsummary 包中的 tbl_summary() 函数来汇总我的数据集中的几个连续变量。我想打印均值的 95% 置信区间,并使用 add_ci() 函数来完成此操作。问题是我无法让该列为 CI 打印适当数量的有效数字。
df %>% select("dcs.pre.total", "dcs.post.total") %>%
tbl_summary(percent = "row",
type = everything() ~ "continuous",
statistic = list(all_continuous () ~ "{mean}"),
digits = all_continuous () ~ 2) %>%
add_ci(pattern = "{stat} ({ci})",
style_fun = everything() ~ style_sigfig)
这会生成小数点后两位数字的平均值,但仅为 CI 的四舍五入整数。
我试过:
df %>% select("dcs.pre.total", "dcs.post.total") %>%
tbl_summary(percent = "row",
type = everything() ~ "continuous",
statistic = list(all_continuous () ~ "{mean}"),
digits = all_continuous () ~ 2) %>%
add_ci(pattern = "{stat} ({ci})",
style_fun = everything() ~ style_sigfig(digits = 2))
但是得到这个错误:
Error in eval_tidy(pair$lhs, env = default_env) :
argument "x" is missing, with no default
非常感谢任何帮助。
编辑,数据样本:
dput(head(df[,c(83, 84)]))
structure(list(dcs.pre.total = c(43.75, 70.8333333333333, 68.75,
75, 64.5833333333333, 56.25), dcs.post.total = c(25, 4.16666666666667,
16.6666666666667, 16.6666666666667, 20.8333333333333, 10.4166666666667
)), row.names = c(2L, 3L, 4L, 5L, 6L, 9L), class = "data.frame")
最佳答案
感谢您提供样本数据。您可以使用 purrr::partial
来完成这项任务。与其使用style_sigfig
,还不如使用style_number
。使用 style_sigfig
,示例数据中 dcs.post.total
的下限将显示高达千分之一的值,因为 始终显示 4 位数字数字 = 4
。 style_sigfig
可能适合您的实际数据,但 style_number
通常更适用。
library(gtsummary)
df <-
structure(list(dcs.pre.total = c(43.75, 70.8333333333333, 68.75,
75, 64.5833333333333, 56.25), dcs.post.total = c(25, 4.16666666666667,
16.6666666666667, 16.6666666666667, 20.8333333333333, 10.4166666666667
)), row.names = c(2L, 3L, 4L, 5L, 6L, 9L), class = "data.frame")
df %>% select("dcs.pre.total", "dcs.post.total") %>%
tbl_summary(percent = "row",
type = everything() ~ "continuous",
statistic = list(all_continuous () ~ "{mean}"),
digits = all_continuous () ~ 2) %>%
add_ci(pattern = "{stat} ({ci})",
style_fun = everything() ~ purrr::partial(style_number, digits = 2))
关于r - 修改 gsummary 置信区间中的有效数字时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71166601/
我是一名优秀的程序员,十分优秀!