jamesbang

V1

2022/09/13阅读：32主题：雁栖湖

# 🤩 autoReg | 分分钟输出各种发表级回归图表（二）

## 2用到的包

``rm(list = ls())#devtools::install_github("cardiomoon/autoReg")library(autoReg)library(tidyverse)library(ggsci)``

## 3示例数据

``library(survival)data(cancer) ``

## 4多因素logistic回归

### 4.1 建模

``fit <- glm(status~rx+sex+age+obstruct+perfor+nodes,           data=colon,           family="binomial")summary(fit)``

### 4.2 整理数据为table

``autoReg(fit) %>%    myft()``

### 4.3 更改label

``colon\$status.factor <- factor(colon\$status,labels=c("Alive","Died"))colon\$obstruct.factor <- factor(colon\$obstruct,labels=c("No","Yes"))colon\$perfor.factor <- factor(colon\$perfor,labels=c("No","Yes"))colon\$sex.factor <- factor(colon\$sex,labels=c("Female","Male"))fit <- glm(status.factor~rx+sex.factor+age+obstruct.factor+perfor.factor+nodes,           data=colon,           family="binomial")result <- autoReg(fit) result %>%  myft()``

### 4.4 设置变量的label

`变量名``label`的话，我们就用`setLabel`函数吧。

``colon\$status.factor <- setLabel(colon\$status.factor,"Mortality")colon\$rx <- setLabel(colon\$rx,"Treatment")colon\$age <- setLabel(colon\$age,"Age(Years)")colon\$sex.factor <- setLabel(colon\$sex.factor,"Sex")colon\$obstruct.factor <- setLabel(colon\$obstruct.factor,"Obstruction")colon\$perfor.factor <- setLabel(colon\$perfor.factor,"Perforation")colon\$nodes <- setLabel(colon\$nodes,"Positive nodes")fit <- glm(status.factor~rx+sex.factor+age+obstruct.factor+perfor.factor+nodes,           data=colon,           family="binomial")result <- autoReg(fit) result %>%  myft()``

### 4.5 不显示reference

``shorten(result) %>% myft()``

## 5单+多因素logistic回归

### 5.1 加入单因素回归

``autoReg(fit, uni=TRUE) %>%   myft()``

### 5.2 纳入所有变量

``autoReg(fit, uni=TRUE,threshold=1) %>%   myft()``

### 5.3 建立最终模型

``autoReg(fit, uni=TRUE,threshold=1, final=TRUE) %>%   myft()``

## 6回归结果的可视化

### 6.1 单一结果可视化

``modelPlot(fit,change.pointsize = T)``

### 6.2 多结果可视化

``p2 <- modelPlot(fit,uni=TRUE,          threshold=1,          show.ref=FALSE,          change.pointsize = T)p2\$p <- p2\$p+  scale_fill_nejm()+  scale_color_nejm()p2``

##### jamesbang
V1

wx🔍: Grassssss 卷起来了