【问题标题】:How to add significance stars on p-value produced by add_glance_table {gtsummary}如何在 add_glance_table {gtsummary} 产生的 p 值上添加重要性星
【发布时间】:2021-12-31 06:29:47
【问题描述】:

使用 {gtsummary} 制作回归表时, p值可以通过add_glance_table(p.value)添加:

  library(gtsumary)
  trial %>%
  na.exclude() %>%
  lm(ttdeath ~ age + marker + response,.) %>%
  tbl_regression() %>%
  add_glance_table(p.value)

我想在 Glance 表中的 p 值中添加重要性星。 我试过add_significance_stars(),但它只是将tbl_regression()创建的原始p值替换为星星。

有什么方法可以在概览表中的 p 值上添加重要性星标?

编辑:我想对我最初的问题表示歉意,因为它缺乏信息和清晰度。已编辑以获取更多信息。

【问题讨论】:

  • 我正在投票重新打开它,因为您已经使它更加完整,但是数据样本会使其变得更好
  • 我已经投票决定关闭这个问题,因为目前还不清楚您希望 p 值出现在哪里。也不清楚您所说的“原始 p 值”是什么意思。你是说整体意义吗? From Review
  • 这是一个明确的问题,专门询问从add_glance_table() 函数添加的 p 值(表底部的 p 值)。该帖子也已更新,以包含使用来自 gtsummary 包的试用数据集的完全可执行代码。请投票重新开放。

标签: r gtsummary


【解决方案1】:

add_significance_stars() 函数可以为模型协变量 p 值添加星号。我们也可以添加一个函数来格式化具有显着性星的模型 p 值。下面的例子

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

# write a function to round p-values and add stars
style_pvalue_stars <- function(x) {
  dplyr::case_when(
    x < 0.001 ~ paste0(style_pvalue(x), "***"),
    x < 0.01 ~ paste0(style_pvalue(x), "**"),
    x < 0.05 ~ paste0(style_pvalue(x), "*"),
    TRUE ~ style_pvalue(x)
  )
}

style_pvalue_stars(c(0.0001, 0.04, 0.50))
#> [1] "<0.001***" "0.040*"    "0.5"

tbl <-
  lm(ttdeath ~ age + marker + response, trial) %>%
  tbl_regression() %>%
  # add significance stars to the covariate p-values
  add_significance_stars(pattern = "{p.value}{stars}", 
                         hide_ci = FALSE, hide_p = FALSE) %>%
  add_glance_table(p.value) %>%
  # add stars to the model p-value
  modify_fmt_fun(
    update = estimate ~ style_pvalue_stars,
    rows = row_type == "glance_statistic" & label == "p-value"
  )

reprex package (v2.0.1) 于 2022-01-01 创建

编程愉快!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-08-07
    • 2018-05-27
    • 1970-01-01
    • 2021-02-09
    • 1970-01-01
    • 2023-02-14
    • 1970-01-01
    • 2016-10-09
    相关资源
    最近更新 更多