plot - 使用 R 中的 forest_model 将多个逻辑回归模型放入一个森林图
问题描述
我想使用forestmodel
R 中的包将多个逻辑回归模型(某些预测变量的 95%CI 的 OR)绘制成一个图形。
使用这个包我可以生成单独的森林图,但我不知道如何合并它们。
# Load packages and data
library(tidyverse)
library(forestmodel)
mydata <- read.csv("https://stats.idre.ucla.edu/stat/data/binary.csv")
str(mydata)
> 'data.frame': 400 obs. of 4 variables:
> $ admit: int 0 1 1 1 0 1 1 0 1 0 ...
> $ gre : int 380 660 800 640 520 760 560 400 540 700 ...
> $ gpa : num 3.61 3.67 4 3.19 2.93 3 2.98 3.08 3.39 3.92 ...
> $ rank : Factor w/ 4 levels "1","2","3","4": 3 3 1 4 4 2 1 2 3 2 ..
# Convert rank to factor.
mydata$rank <- factor(mydata$rank)
# Fit two models predicting university admission based on rank of high school and gpa or gre.
mylogit1 <- glm(admit ~ gre + rank, data = mydata, family = "binomial")
mylogit2 <- glm(admit ~ gpa + rank, data = mydata, family = "binomial")
# Produce forest plots
plot1 <- forest_model(mylogit1)
plot1
plot2 <- forest_model(mylogit2)
plot2
我尝试了几种方法将两个模型绘制成一个图形:
# I tried several solutions:
forest_model(mylogit1, mylogit2) # after each other, or combined with c("mylogit1", "mylogit2")
forest_model(model_list = c(plot1, plot2)) #the same but with the model_list function
plotlist <- list(plot1, plot2) #making a list first and putting that in.
forest_model(model_list = c("plot1", "plot2"))
遗憾的是,没有任何效果。有什么帮助吗?谢谢!
解决方案
我发现如果您使用函数而不是 制作单独的森林图,这是可行forest_model
的,并使用包中的函数forest_models
排列它们,如下所示:ggarrange
ggpubr
library(ggpubr)
ggarrange(plot1, plot2, ncol=2, nrow=1)
推荐阅读
- ethereum - 如何运行远程 wss/http geth 节点?
- android - 如何在画中画模式下创建自定义布局?
- amazon-web-services - 使用配置文件作为变量的 aws cli 命令
- c# - 是否可以从字段中复制文本并将文本打印到行终止符中?
- javascript - 刀片上的 Laravel 自定义 javascript 不起作用
- svg - 如何自动创建适合完整内容的最小尺寸的视图?
- apache-kafka - 已使用消息的复制器过滤器
- javascript - ReactJS 控制组件中的级联下拉菜单
- html - 如果 *ngFor 让 HTML 绑定中的对象的对象返回一个空数组,如何显示占位符
- javascript - 在 Firebase 中使用 set() 时发生的事件顺序是什么?