回归分析整洁表格是生成-基于gtsummary
教程官网地址
https://www.danieldsjoberg.com/gtsummary/articles/tbl_regression.html
英文介绍
The tbl_regression()
function takes a regression model object in R and returns a formatted table of regression model results that is publication-ready.
# 基本用法,逻辑回归
m1 <- glm(response ~ age + stage, trial, family = binomial)
# 返回整洁结果
tbl_regression(m1, exponentiate = TRUE)
结果
函数内科设定参数
函数外配合使用参数
#结果输出前需要用as_gt命令更改格式
m1 %>%
tbl_regression(exponentiate = TRUE) %>%
as_gt() %>%
gt::tab_source_note(gt::md("*This data is simulated*"))#添加文末标题
结果
m1 %>%
tbl_regression(
exponentiate = TRUE,
pvalue_fun = ~style_pvalue(.x, digits = 2),#p值保留2位小数
) %>%
add_global_p() %>%#添加总体p值
bold_p(t = 0.10) %>%#p值小于0.1的时候加粗
bold_labels() %>%#标签加粗
italicize_levels()#分类变量的级别内容斜体
结果
trial %>%
select(response, age, grade) %>%#筛选分析的变量
tbl_uvregression(
method = glm,#确定模型
y = response,
method.args = list(family = binomial),#广义线性模型的连接函数
exponentiate = TRUE,#输出结果
pvalue_fun = ~style_pvalue(.x, digits = 2)#p值保留两位小数
) %>%
add_global_p() %>% # 添加分类变量的整体P值
add_nevent() %>% # 添加事件数
add_q() %>% # 添加矫正后的P值
bold_p() %>% # P值小于0.05后加粗
bold_p(t = 0.10, q = TRUE) %>% # q值小于0.05后加粗
bold_labels() #标签加粗
image.png
网友评论