【问题标题】:How to generate effect size [90%CI] in the summary table using R package “gtsummary”? New ES package calculation and qualitative indice in the table如何使用 R 包“gtsummary”在汇总表中生成效果大小 [90%CI]?表中新增ES包计算和定性指标
【发布时间】:2021-03-11 13:27:40
【问题描述】:

我要再次感谢 Daniel Sjoberg 和其他合作者不断实现 gtsummary 包中的功能。对我来说,这是 R 中最有效的套件之一,用于在表格/行中处理和报告结果。

不久前,我寻求帮助,将效应大小 [90%CI] 包含在 gtsummary 包生成的分析表中。然而,在这篇新文章中,我打算更改 ES 计算包,以便为我提供大量索引并获得它们的定性大小。我试图在新代码中实现这个其他包。但是,返回此消息:

变量“年龄”出现错误: .deal_with_cohens_d_arguments (x, y, data) 中的错误:请提供数据参数。

我相信我无法配置函数(CohenD 对象)。有人可以帮我写代码吗?

我在下面复制了它:

CohenD <- function(data, variable, by, ...) {
  # Cohen's d, Hedges's g (correction=TRUE or FALSE) and Glass’s delta
  ES <- effectsize::cohens_d(data[[variable]] ~ as.factor(data[[by]]),
                             ci=.90,
                             pooled_sd=TRUE,
                             paired=FALSE,
                             correction=TRUE)
 
  # Formatting statistic with CI
  est <- style_sigfig(abs(ES$Cohens_d))
  ci_lower <- style_sigfig(ES$CI_low)
  ci_upper <- style_sigfig(ES$CI_high)
 
  # Returning estimate with CI together
  str_glue("{est} ({ci_lower, ci_upper})")
}

Table <-
  trial %>%
  select(trt, age) %>%
  tbl_summary(by = trt, missing = "no", label = list (age ~ "Age (yrs)"),
              statistic = list(all_continuous() ~ "{mean} ± {sd}"),
              digits = list(all_continuous() ~ c(1,1))) %>%
  bold_labels() %>%
  italicize_levels() %>%
  add_p(test = everything() ~ t.test, pvalue_fun = partial(style_pvalue, digits = 2)) %>%
  add_stat(
    fns = everything() ~ CohenD,
    fmt_fun = NULL,
    header = "**ES (90% CI)**"
  ) %>%
  modify_footnote(add_stat_1 ~ "Hedges's g (90% CI)") %>%
  modify_header(label = "**Variables**", stat_by = "**{level}** (N= {n})")
Table

是否可以在 Table 中包含一个新列,或者与该函数已经提供的 ES +/- CI 连接,观察到的 ES 的定性大小(根据一组规则解释一个值)?建议针对此功能:

effectsize::interpret_d(ES$Cohens_d, rules = "cohen1988")

干杯, 克里斯蒂亚诺

【问题讨论】:

    标签: r size effect gtsummary


    【解决方案1】:

    您遇到的问题在于您的用户定义函数CohenD():它不喜欢您传递公式的方式。在下面的示例中,我更正了语法。我还包括了对效果大小的解释。

    library(gtsummary)
    library(tidyverse)
    
    # function that returns either Cohen's D or the 1988 interpretation of its size
    CohenD <- function(data, variable, by, ...) {
      # Cohen's d, Hedges's g (correction=TRUE or FALSE) and Glass’s delta
      ES <- effectsize::cohens_d(data[[variable]], factor(data[[by]]),
                                 ci=.90,
                                 pooled_sd=TRUE,
                                 paired=FALSE,
                                 correction=TRUE)
      
      # Formatting statistic with CI
      est <- style_sigfig(ES$Cohens_d)
      ci_lower <- style_sigfig(ES$CI_low)
      ci_upper <- style_sigfig(ES$CI_high)
      
      # Returning estimate with CI together
      tibble(
        cohen_d = stringr::str_glue("{est} ({ci_lower}, {ci_upper})"),
        interpret_d = stringr::str_glue("{effectsize::interpret_d(ES$Cohens_d, rules = 'cohen1988')}")
      )
      
    }
    
    tbl <-
      trial %>%
      select(trt, age, marker) %>%
      tbl_summary(by = trt, missing = "no", statistic = all_continuous() ~ "{mean} ± {sd}") %>%
      add_p(test = everything() ~ t.test) %>%
      add_stat(fns = everything() ~ CohenD) %>%
      modify_header(cohen_d = "**ES (90% CI)**", interpret_d = "**Interpretation**")
    

    reprex package (v2.0.0) 于 2021-04-15 创建

    【讨论】:

    • 嗨丹尼尔,我有一个工作的代码。但是,我需要恢复工作。现在,当我尝试获取表格时(类似于此论坛帖子 [表格由 ES 和 90%CI 和解释] 组成),我收到此错误: UseMethod("add_p") 中的错误:'add_p 没有适用的方法' 应用于“公式”类的对象
    • 已解决...缺少参数分隔符!
    猜你喜欢
    • 2021-07-19
    • 1970-01-01
    • 2020-08-19
    • 2023-01-08
    • 2020-10-08
    • 1970-01-01
    • 2023-04-07
    • 1970-01-01
    • 2020-06-23
    相关资源
    最近更新 更多