微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决使用 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 举报,一经查实,本站将立刻删除。