【问题标题】:How do I display test statistic (F value) for anova using tbl_summary如何使用 tbl_summary 显示方差分析的检验统计量(F 值)
【发布时间】:2021-12-04 22:09:28
【问题描述】:

这是我用来输出方差分析汇总表的代码:

hiv %>% 
  select(education, sexfirsttime) %>% 
  mutate(education=
  factor(education, levels= c("no education", "primary","secondary","college"))) %>% 
  tbl_summary(missing="no", 
              by=education,
    statistic = all_continuous() ~"{mean} ({sd})", 
    label = sexfirsttime ~ "Age of first time sex") %>% 
  add_p(test= all_continuous() ~ "aov") %>% 
  modify_header(statistic ~ "**Test Statistic**") 

执行代码后,我收到以下错误消息: 错误:update= 参数输入错误。从“变量”、“test_name”、“var_type”、“var_label”、“row_type”、“label”、“stat_1”、“stat_2”、“stat_3”、“stat_4”、“test_result”、“p.value”中选择'

当我尝试将 modify_header 中的 statistic 替换为 test_result 时,我得到的输出如下图所示。

我对使用 gtsummary 还很陌生。任何帮助将不胜感激。谢谢。

【问题讨论】:

    标签: r statistics anova gtsummary


    【解决方案1】:

    使用最新版本的 gtsummary 并重试。在最新版本中,“aov”测试的处理与其他测试更加一致,包括返回“statistic”列。

    library(gtsummary)
    packageVersion("gtsummary")
    #> [1] '1.5.0'
    
    tbl <- 
      trial %>%
      select(grade, age, marker) %>%
      tbl_summary(
        by = grade, 
        missing = "no"
      ) %>%
      add_p(all_continuous() ~ "aov") %>%
      # add a header (which also unhides a hidden column)
      modify_header(statistic ~ "**Test Statistic**") %>%
      # add a function to format the column
      modify_fmt_fun(statistic ~ style_sigfig)
    

    reprex package (v2.0.1) 于 2021-10-17 创建

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-02-17
      • 2011-02-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多