添加控制和案例编号而不是 add_nevent()

Add Control and Cases numbers instead of add_nevent()

以下代码生成“N”的 N 列和“事件 N”作为单变量回归的一部分 table。 我有一个病例对照数据集,我希望“病例”和“对照”列给出病例和对照的数量。

“案例”和“控制”由以下代码中的变量“响应”确定。例如响应(1)=“案例”,而响应(0)=“控制”。

我该怎么做?

谢谢, 耐莉

tbl_uv_nevent_ex <-
trial[c("response", "trt", "age", "grade")] %>%
tbl_uvregression(
method = glm,
y = response,
method.args = list(family = binomial)
) %>%
add_nevent()

您可以通过将控件数量添加到 .$table_body 数据框来实现。我在下面包含了一个示例。目前有一个症结点....在将控件的数量添加到将要打印的数据框之后,我们需要将新列添加到内部指令集中以在 gtsummary 中打印。这一步现在很头疼,但我们正在研究一个解决方案,让用户可以访问它。这是该函数的初稿:http://www.danieldsjoberg.com/gtsummary/dev/reference/modify_table_header.html

同时,您可以通过以下方式完成此操作:

library(gtsummary)

tbl <-
  trial[c("response", "trt", "age")] %>%
  tbl_uvregression(
    method = glm,
    y = response,
    method.args = list(family = binomial),
    exponentiate = TRUE
  ) %>%
  add_nevent()

# add the number of controls to table
tbl$table_body <-
  tbl$table_body %>%
  dplyr::mutate(
    n_nonevent = N - nevent
  ) %>%
  dplyr::relocate(n_nonevent, .after = nevent)

# updating internal info with new column (this part will not be required in the future)
tbl$table_header <- 
  gtsummary:::table_header_fill_missing(tbl$table_header, 
                                        tbl$table_body)

# print tbl with Case and Control Ns
tbl %>%
  modify_header(
    list(nevent ~ "**Case N**",
         n_nonevent ~ "**Control N**")
  )