根据问题逻辑显示真实的未知数

Show true unknown count based on question logic

我正在进行调查,如果提供了具体答案,就会给出后续问题。例如,如果对 q1 的回答是“是”,则询问 q2。但是,如果我将两个问题都添加到同一个 table,则 q2 的未知计数为 5 但应为 0。不幸的是,我确实缺少数据并希望显示该数据。我如何只显示 q1=="yes"q2==NA 的人的 q2 未知计数?

library(tidyverse)
library(knitr)
library(gtsummary)
packageVersion("gtsummary")
#> [1] '1.6.0'
tibble::tribble(
  ~q1,   ~q2,
  "yes", "yes",
  "yes", "yes",
  "yes",  "no",
  "yes",  "no",
  "yes",  "no",
  "no",    NA,
  "no",    NA,
  "no",    NA,
  "no",    NA,
  "no",    NA
) %>% tbl_summary() %>% as_kable()
Characteristic N = 10
q1 5 (50%)
q2 2 (40%)
Unknown 5

reprex package (v2.0.1)

创建于 2022-05-06

如果您需要不同的分母,最好的办法是制作两个表格并将它们堆叠起来。示例如下!

library(gtsummary)
packageVersion("gtsummary")
#> [1] '1.6.0'

tbl1 <- trial %>% tbl_summary(include = response)
tbl2 <-
  trial %>% 
  dplyr::filter(response == 1) %>%
  tbl_summary(
    include = stage,
    label = stage ~ "Stage Among Responders",
    statistic = stage ~ "{n} / {N} ({p}%)"
  )

tbl <- tbl_stack(list(tbl1, tbl2))
#> ℹ Column headers among stacked tables differ. Headers from the first table are
#> used. Use `quiet = TRUE` to supress this message.

reprex package (v2.0.1)

创建于 2022-05-06