我需要向多项逻辑回归模型的效应图添加置信区间(或眼)。
下面是一个我正在使用的数据、logit模型和图的可重复示例:
install.packages("effects")
library("effects")
ToyData2 <- data.table(Answer = c("Remained incorrect", "Changed to correct", "Changed to correct", "Remained incorrect",
"Remained correct", "Changed to incorrect", "Remained correct", "Changed to correct",
"Changed to correct", "Changed to incorrect", "Remained incorrect", "Remained incorrect",
"Remained correct", "Changed to incorrect", "Remained correct", "Changed to correct"),
Sex = c("Male", "Male", "Female", "Male", "Female", "Female", "Male", "Male",
"Female", "Male", "Female", "Female", NA, "Male", "Female", "Male"),
Education = c("Less than Bachelors", "Less than Bachelors", "Bachelors",NA,
"Post Bachelors","Post Bachelors","Bachelors", "Less than Bachelors",
"Bachelors",NA,"Post Bachelors","Post Bachelors",
"Post Bachelors", "Less than Bachelors", "Bachelors","Post Bachelors"),
Minutes = c(1, 5, 1, 29, NA, 2, 1, 3, 4, 5, 1, 2, 2, 1, 3, 4),
Problem = c("A","A","A","A", "B","B","B","B", "C","C","C","C", "D","D","D","D"))
ToyData2
ToyData2$Answer <- factor(ToyData2$Answer, ordered = FALSE)
summary(ToyData2$Answer)
ToyData2$Answer <- relevel(ToyData2$Answer, ref = 'Changed to incorrect')
ToyData2$Education <- factor(ToyData2$Education, levels = c("Less than Bachelors","Bachelors","Post Bachelors"))
ToyOutcomeLogit <- multinom(Answer ~ Sex + Education + Minutes + Problem, data = ToyData2)
summary(ToyOutcomeLogit)
table(ToyData2$Minutes)
plot(Effect('Minutes', ToyOutcomeLogit), multiline=T)
table(ToyData2$Education)
plot(Effect('Sex', ToyOutcomeLogit), multiline=T)
以下是由以“plot”开始的行生成的图:
1.影响时间(分钟)
1.(学士)教育的影响
下面是我正在使用的一些库(在我的R文件的其余部分中),以备您需要:
library('pacman')
p_load(
'data.table',
'DescTools',
'effects',
'ggpubr',
'ggsignif',
'glue',
'Hmisc',
'irr',
'lm.beta',
'nnet',
'openxlsx',
'psych',
'scales',
'sjPlot',
'stats',
'tidyr',
'tidyverse'
)
**如何获得此类图的置信区间?**或者,更具体地说:
A.如何调整现有代码以添加置信区间?
*B.我还可以使用其他哪些函数来绘制这些效应 * 和置信区间 ?
C.我还应该使用其他 * 软件包 * 的哪些函数?
(Note:我目前正在运行R 4.2.2,以防与此相关。)
1条答案
按热度按时间j0pj023g1#
显然,在plot命令中将
multiline=T
替换为confint=T
将添加CI带或条。波段:
条形图:
唉,我还没有找到如何将配置项添加到折叠的多行图本身。