繁体   English   中英

使用 sjTools package 的 Plot_models 显示 plot 中分类变量的参考类别 OR

[英]Show reference category OR of a categorical variable in a plot using Plot_models of the sjTools package

Using the function plot_models from the R package sjTools I plotted the estimates (ORs) from a logistic regression model predicting the odds for university admission based on GRE score (continuous), GPA score (continuous), and rank of high school (categorical). 但是,plot 没有显示我的分类变量的参考类别(即高中排名;参考类别估计显然是 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

这会产生一个 plot不显示排名的参考类别(即 rank .

我试过的:

  • 我尝试添加show.reflvl=TRUE这是 sjPlot 表的参数,但这不起作用。
  • 我已经尝试为每个等级rank创建一个虚拟变量并运行包括所有四个变量的回归,但这会产生警告: Model matrix is rank deficient. Parameters rank_1 were not estimable. 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

有什么想法吗? 谢谢!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM