最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

r - Using multiple by groups with tbl_ard_summary from GTSUMMARY - Stack Overflow

programmeradmin5浏览0评论

I am trying to generate table from ARDs generated by CARDS package using GTSUMMARY tbl_ard_summary function. I have successfully generated this using tbl_strata & tbl_summary as follows:

#Summary by TRT & GRADE
trial %>%
  mutate(grade = paste("Grade", grade)) %>%
  tbl_strata(
    strata = trt,
    .tbl_fun = ~.x %>%
      tbl_summary(
        by = grade,
        include = c(age, ttdeath),
        type = c(age, ttdeath) ~ "continuous2",
        statistic = c(age, ttdeath) ~ c("{N_obs}", "{mean} ({sd})",
                                        "{median} ({p25}, {p75})", "{min}, {max}")) %>%
    add_n(),
    .header = "**{strata}**, N = {n}"
    )

I am having trouble creating the same with tbl_ard_summary with multiple groups. I have generated ARDs using following:

#ARD table for AGE, TTDEATH by TRT & GRADE
ard.cont <- ard_continuous(
  trial,
  by = c(trt, grade),
  variables = c(age, ttdeath)) %>%
  bind_ard(
    ard_attributes(
      trial,
      variables = c(trt, grade, age, ttdeath)))

When I try to generate the report table using the ARD above, it's not working. Below is the code I tried.

#Summary from ARD
trial %>% tbl_strata(
  strata = trt,
  ~.x %>%
    tbl_ard_summary(
      cards = ard.cont,
      by = grade,
      include = c(age, ttdeath),
      type = c(age, ttdeath) ~ "continuous2",
      statistic = c(age, ttdeath) ~ c("{N}", "{mean} ({sd})", "{median} ({p25}, {p75})", "{min}, {max}")
    ))

Is it feasible to generate this from ARDs currently? Any help is really appreciated!

I am trying to generate table from ARDs generated by CARDS package using GTSUMMARY tbl_ard_summary function. I have successfully generated this using tbl_strata & tbl_summary as follows:

#Summary by TRT & GRADE
trial %>%
  mutate(grade = paste("Grade", grade)) %>%
  tbl_strata(
    strata = trt,
    .tbl_fun = ~.x %>%
      tbl_summary(
        by = grade,
        include = c(age, ttdeath),
        type = c(age, ttdeath) ~ "continuous2",
        statistic = c(age, ttdeath) ~ c("{N_obs}", "{mean} ({sd})",
                                        "{median} ({p25}, {p75})", "{min}, {max}")) %>%
    add_n(),
    .header = "**{strata}**, N = {n}"
    )

I am having trouble creating the same with tbl_ard_summary with multiple groups. I have generated ARDs using following:

#ARD table for AGE, TTDEATH by TRT & GRADE
ard.cont <- ard_continuous(
  trial,
  by = c(trt, grade),
  variables = c(age, ttdeath)) %>%
  bind_ard(
    ard_attributes(
      trial,
      variables = c(trt, grade, age, ttdeath)))

When I try to generate the report table using the ARD above, it's not working. Below is the code I tried.

#Summary from ARD
trial %>% tbl_strata(
  strata = trt,
  ~.x %>%
    tbl_ard_summary(
      cards = ard.cont,
      by = grade,
      include = c(age, ttdeath),
      type = c(age, ttdeath) ~ "continuous2",
      statistic = c(age, ttdeath) ~ c("{N}", "{mean} ({sd})", "{median} ({p25}, {p75})", "{min}, {max}")
    ))

Is it feasible to generate this from ARDs currently? Any help is really appreciated!

Share Improve this question edited Mar 25 at 13:55 Daniel D. Sjoberg 12k2 gold badges18 silver badges35 bronze badges asked Mar 25 at 12:22 BlueKnight2025BlueKnight2025 575 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

There is an open issue about this, and should be addressed shortly. https://github/ddsjoberg/gtsummary/issues/1852

In the meantime, the example below includes two ways to use tbl_strata() with ARDs. Hope it helps!

library(gtsummary)
library(cards)

# build ARD outside the `tbl_strata()` function
ard.cont <- 
  trial %>%
  mutate(grade = paste("Grade", grade)) %>%
  ard_continuous(
    by = c(grade, trt),
    variables = c(age, ttdeath)
  )

ard.cont |>
  tbl_strata(
    strata = group2_level,
    ~.x %>%
      dplyr::select(-all_ard_group_n(2)) |> 
      tbl_ard_summary(
        by = grade,
        include = c(age, ttdeath),
        type = c(age, ttdeath) ~ "continuous2",
        statistic = c(age, ttdeath) ~ c("{N}", "{mean} ({sd})", "{median} ({p25}, {p75})", "{min}, {max}"),
        label = list(age = "Age", ttdeath = "Time to Death")
      ) 
  )



# build ARD in the `tbl_strata()` function
trial %>%
  mutate(grade = paste("Grade", grade)) %>%
  tbl_strata(
    strata = trt,
    .tbl_fun = ~.x |> 
      ard_stack(
        .by = grade, 
        ard_continuous(variables = c(age, ttdeath)),
        .attributes = TRUE, 
        .missing = TRUE,
        .total_n = TRUE
      ) |> 
      tbl_ard_summary(
        by = grade,
        include = c(age, ttdeath),
        type = c(age, ttdeath) ~ "continuous2",
        statistic = c(age, ttdeath) ~ c("{N_obs}", "{mean} ({sd})",
                                        "{median} ({p25}, {p75})", "{min}, {max}")
      ),
    .header = "**{strata}**, N = {n}"
  )

发布评论

评论列表(0)

  1. 暂无评论