我不太确定我理解您为什么质疑“confint()”输出,并且其输出的有效性实际上是与绘图问题不同的问题。
要绘制系数 +/- SE,可调整。 SE 和 95% CI,请尝试以下操作。这使用完整模型平均值,因为您使用了full=T
CI 中的争论。
该图表不是最漂亮的,但它可以完成工作 - 如果您想要一个更好的图表,请告诉我。我没有绘制截距图,因为在这种情况下,估计值远大于系数,但所有数据都采用易于绘制的格式。
library(MuMIn)
#Dummy Data
a <- seq(1:5)
set.seed(1)
b <- sample(1:100,5)
c <- sample(1:100,5)
d <-sample(1:100,5)
df <- data.frame(a,b,c,d)
options(na.action = "na.fail") # needed for dredge to work
Dredged <- dredge(lm(a ~ b + c + d, data=df), rank=AIC)
ModelAvg <- model.avg(Dredged)
mA<-summary(ModelAvg) #pulling out model averages
df1<-as.data.frame(mA$coefmat.full) #selecting full model coefficient averages
CI <- as.data.frame(confint(ModelAvg, full=T)) # get confidence intervals for full model
df1$CI.min <-CI$`2.5 %` #pulling out CIs and putting into same df as coefficient estimates
df1$CI.max <-CI$`97.5 %`# order of coeffients same in both, so no mixups; but should check anyway
setDT(df1, keep.rownames = "coefficient") #put rownames into column
names(df1) <- gsub(" ", "", names(df1)) # remove spaces from column headers
包含所有三个误差线的图(SE、adj. SE、95% CI)
ggplot(data=df1[2:4,], aes(x=coefficient, y=Estimate))+ #excluding intercept because estimates so much larger
geom_point(size=10)+ #points for coefficient estimates
theme_classic(base_size = 20)+ #clean graph
geom_errorbar(aes(ymin=Estimate-Std.Error, ymax=Estimate+Std.Error), colour ="red", # SE
width=.2, lwd=3) +
geom_errorbar(aes(ymin=Estimate-AdjustedSE, ymax=Estimate+AdjustedSE), colour="blue", #adj SE
width=.2, lwd=2) +
geom_errorbar(aes(ymin=CI.min, ymax=CI.max), colour="pink", # CIs
width=.2,lwd=1)
Which produces the following graph. The red is SE, blue is adj. SE and pink is 95% CIs.
用更好的图表编辑:
ggplot(data=df1[2:4,], aes(x=coefficient, y=Estimate))+ #again, excluding intercept because estimates so much larger
geom_hline(yintercept=0, color = "red",linetype="dashed", lwd=1.5)+ #add dashed line at zero
geom_errorbar(aes(ymin=Estimate-AdjustedSE, ymax=Estimate+AdjustedSE), colour="blue", #adj SE
width=0, lwd=1.5) +
coord_flip()+ # flipping x and y axes
geom_point(size=8)+theme_classic(base_size = 20)+ ylab("Coefficient")