使用 sjTools 包的 Plot_models 在图中显示分类变量的参考类别 OR

问题描述

使用 R 包 plot_models 中的函数 sjTools,我绘制了逻辑回归模型的估计值 (OR),该模型根据 GRE 分数(连续)、GPA 分数(连续)预测大学录取几率),以及高中排名(分类)。但是,该图并未显示我的分类变量的参考类别(即高中排名;参考类别估计显然是 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

产生一个不显示排名的参考类别(即排名

我尝试过的:

  • 我尝试添加 show.reflvl=TRUE,它是 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,show.legend=FALSE)
plot2

有什么想法吗?谢谢!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)