gtsummary - 在 GT 回归中设置指定的因子水平作为参考?
问题描述
我正在使用 gtsummary 包从逻辑回归生成表。
例如,我想使用试验数据中的阶段级别“T3”作为参考级别,而不是默认的“T1”。我怎样才能在这个示例代码中做到这一点?
我的目标是对单变量和多变量逻辑回归都这样做,所以我假设答案适用于这两种情况。
library(gtsummary)
library(dplyr)
trial %>%
dplyr::select(age, trt, marker, stage, response, death, ttdeath) %>%
tbl_uvregression(
method = glm,
y = death,
method.args = list(family = binomial),
exponentiate = TRUE,
pvalue_fun = function(x) style_pvalue(x, digits = 2)) %>%
# overrides the default that shows p-values for each level
add_global_p() %>%
# adjusts global p-values for multiple testing (default method: FDR)
add_q() %>%
# bold p-values under a given threshold (default 0.05)
bold_p() %>%
# now bold q-values under the threshold of 0.10
bold_p(t = 0.10, q = TRUE) %>%
bold_labels() %>% as_gt()
真诚的,耐莉
解决方案
我设法通过使用 forcats 函数“fct_relevel”将分类变量的所需级别设置为参考来解决我自己的问题。
trial$stage <- forcats::fct_relevel(trial$stage, "T3")
推荐阅读
- styled-components - 跨不同文件重用带有样式组件的“混合”?
- c++ - 视觉工作室访问冲突读取位置0xc0000005
- php - Isset 返回未定义的索引,尽管它已设置
- javascript - 我有 2 个输入文本。当用户尝试将某些内容转换为另一个输入文本时,我想禁用一个输入文本。我使用 HTML CSS PHP 谢谢
- wordpress - 在 WordPress 中显示帖子的最后更新日期
- c++ - 用向量构造一个CGAL点
- python - 从 IP 摄像机获取视频源时发生错误(OpenCV python 3.3)
- javascript - 增加类型号后动态添加下拉列表
- r - 如何以 sqrt(x) 格式格式化 x 轴刻度标签?
- java - 为什么我收到 Stream Closed 错误?