我想为我在 R-Markdown 中的同事使用qwraps::summary_table
. data.frame 包含不同曝光的信息。所有变量都编码为二进制。
library(qwraps2)
library(dplyr)
pop <- rbinom(n = 1000, size = 1, prob = runif(n = 10, min = 0, max = 1))
exp <- rbinom(n = 1000, size = 1, prob = .5)
ID <- c(1:500)
therapy <- factor(sample(x = pop, size = 500, replace = TRUE), labels = c("Control", "Intervention"))
exp_1 <- sample(x = exp, size = 500, replace = TRUE)
exp_2 <- sample(x = exp, size = 500, replace = TRUE)
exp_3 <- sample(x = exp, size = 500, replace = TRUE)
exp_4 <- sample(x = exp, size = 500, replace = TRUE)
df <- data.frame(ID, exp_1, exp_2, exp_3, exp_4, therapy)
head(df)
在下一步中,我将创建一个简单的汇总表,如下所示。在表中,我希望将组(控制与干预)作为列,将暴露作为行:
my_summary <-
list(list("Exposure 1" = ~ n_perc(exp_1 %in% 1),
"Exposure 2" = ~ n_perc(exp_2 %in% 1),
"Exposure 3" = ~ n_perc(exp_3 %in% 1),
"Exposure 4" = ~ n_perc(exp_4 %in% 1))
)
my_table <- summary_table(group_by(df, therapy), my_summary)
my_table
在下一步中,我想添加另一列,其中包含控制组和干预组之间组差异的 p 值,例如fisher.test
。我读到?qwraps::summary_table
那cbind
是一个适合 class 的方法qwraps2_summary_table
,但老实说,我正在努力解决这个问题。我尝试了不同的方法,但不幸的是失败了。
有没有一种方便的方法可以qwraps::summary_table
根据分组列通过特别是 p 值添加单个列?
谢谢你的帮助!
最好的,
弗洛里安