这并不能直接解决问题,但如果没有其他解决方案出现,它可能仍然是一种可以改进的解决方法。
通过@Limey 的评论源于对 OP 的编辑:
您可以自己从模型对象中绘制所有内容,该对象接近绘制的值。我意识到这并不完美,也许有人对这些值如何完美重叠提出了建议。rstanarm
绘图默认为 50% 和 90%的可信区间。我在这里使用了 t 表和 50% 和 90%的置信区间,它们并不相同,但结果很接近。
color_scheme_set("gray")
vars<-c(2,5,9,11) # select values from fit$coefficients
# (this is assumed to match with names(mtcars))
# Note I have switched `sigma` to `carb` for ease of model retrieval
plot(fit, pars = c(names(mtcars)[vars]))+ # the original plot, now in grey
# the first error bar. With a t table, 1.645 is a 90% confidence interval,
# which isn't the same here as the 90% credible interval from rstanarm, but it
# gets us close
geom_errorbarh(aes(xmin=(fit$coefficients[vars]-fit$ses[vars]*1.645),
xmax=(fit$coefficients[vars]+fit$ses[vars]*1.645),
y=names(fit$coefficients)[vars]),
height=0,alpha=0.5,color="yellow" # transparency is so you can see grey through the yellow.. I know this isn't pretty
)+
geom_errorbarh(aes(xmin=(fit$coefficients[vars]-fit$ses[vars]*.675), # this is .675, which corresponds to a 50% confidence interval (again not the same as a credible interval, but it is getting us close
xmax=(fit$coefficients[vars]+fit$ses[vars]*.675),
y=names(fit$coefficients)[vars]),
height=0,lwd=2,alpha=0.5,color="yellow"
)+
# now plot the points over the lines:
geom_point(aes(x=fit$coefficients[vars],
y=names(fit$coefficients)[vars]),
color="yellow",size=3,alpha=0.5)
这不漂亮,也不准确(你可以看到黄色边缘有点灰色),但它很接近。如果您可以修改每个值集的颜色,那么您可以交替使用颜色:
colors=c("red","blue","red","blue") # selecting colors one by one
colors=rep(c("red","blue"),2) # or just have alternating colors repeat (2 times here)
ggplot()+ # note that I have removed `rstanarm` object, which is no longer necessary
geom_errorbarh(aes(xmin=(fit$coefficients[vars]-fit$ses[vars]*1.645),
xmax=(fit$coefficients[vars]+fit$ses[vars]*1.645),
y=names(fit$coefficients)[vars]),
height=0,alpha=0.5,color=colors
)+
geom_errorbarh(aes(xmin=(fit$coefficients[vars]-fit$ses[vars]*.675),
xmax=(fit$coefficients[vars]+fit$ses[vars]*.675),
y=names(fit$coefficients)[vars]),
height=0,lwd=2,alpha=0.5,color=colors
)+
geom_point(aes(x=fit$coefficients[vars],
y=names(fit$coefficients)[vars]),
color=colors,size=3,alpha=0.5)
或完全古怪的东西:
colors=c("red","blue","green","yellow")
colors2=rev(colors)
ggplot()+
geom_errorbarh(aes(xmin=(fit$coefficients[vars]-fit$ses[vars]*1.645),
xmax=(fit$coefficients[vars]+fit$ses[vars]*1.645),
y=names(fit$coefficients)[vars]),
height=0,alpha=0.5,color=colors
)+
geom_errorbarh(aes(xmin=(fit$coefficients[vars]-fit$ses[vars]*.675),
xmax=(fit$coefficients[vars]+fit$ses[vars]*.675),
y=names(fit$coefficients)[vars]),
height=0,lwd=2,alpha=0.5,color=colors
)+
geom_point(aes(x=fit$coefficients[vars],
y=names(fit$coefficients)[vars]),
color=colors2,size=3,alpha=0.5)