首页 > 解决方案 > 使用 sjTools 包的 Plot_models 在绘图中显示分类变量的参考类别 OR

问题描述

使用plot_modelsR 包中的函数,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 .

我试过的:

# 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

有什么想法吗?谢谢!

标签: rggplot2logistic-regressionsjplotforestplot

解决方案


推荐阅读