r - 使用 sjTools 包的 Plot_models 在绘图中显示分类变量的参考类别 OR
问题描述
使用plot_models
R 包中的函数,sjTools
我绘制了基于 GRE 分数(连续)、GPA 分数(连续)和高中排名(分类)预测大学录取几率的逻辑回归模型的估计值(OR)。但是,该图没有显示我的分类变量的参考类别(即高中排名;参考类别估计显然是 OR=1.00)。
有没有办法plot_models
做到这一点?
# Load packages and data
library(tidyverse)
library(sjPlot)
mydata <- read.csv("https://stats.idre.ucla.edu/stat/data/binary.csv")
str(mydata)
# Convert high school rank variable to factor.
mydata$rank <- factor(mydata$rank)
# Fit model.
mylogit1 <- glm(admit ~ gre + gpa + rank, data = mydata, family = "binomial")
# Produce forest plot
plot1 <- plot_models(mylogit1, title="Odds for admission to university
for high school students",
show.legend=FALSE)
plot1
这会产生一个不显示排名参考类别的图(即 rank .
我试过的:
- 我尝试添加
show.reflvl=TRUE
which 是 sjPlot 表的参数,但这不起作用。 - 我尝试为每个级别创建一个虚拟变量
rank
并运行包括所有四个变量的回归,但这会产生警告:Model matrix is rank deficient. Parameters rank_1 were not estimable.
# Plot using dummy variables
library(fastDummies)
mydata <- dummy_cols(mydata, select_columns='rank')
# Fit model.
mylogit2 <- glm(admit ~ gre + gpa + rank_4 + rank_3 + rank_2 + rank_1, data=mydata, family="binomial")
# Produce forest plot
plot2 <- plot_models(mylogit2, title="Odds for admission to university
for high school students",
show.legend=FALSE)
plot2
有什么想法吗?谢谢!
解决方案
推荐阅读
- amazon-web-services - 具有子域的 Amazon SES
- c++ - 链表显示乱码
- c++ - glDrawElements GL 错误类型 = 0x824c,严重性 = 0x9146,消息 = GL_INVALID_OPERATION
- java - 为什么要使用 guice-hk2-bridge?
- javascript - Postman always valid as true a response with the schema using tv4
- angular - Angular 5:无法使依赖注入工作
- gridview - Yii2 PJAX - 模式重新加载错误
- reactjs - typescript 3.0 和 react defaultProps
- python - 如何从列表中获取“子”列表的所有组合
- ios - IOS/Objective-C:如何访问括号内的 JSON