如何从MuMIn model.avg()摘要进行绘图 [英] How to plot from MuMIn model.avg() summary

查看:513
本文介绍了如何从MuMIn model.avg()摘要进行绘图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以直接从MuMIn model.avg()中绘制带有置信带的不同变量的模型平均摘要输出.以前,我一直使用ggplot和ggpredict从实际模型中绘制项,但是我一直无法找到一种方法来绘制平均模型的结果.

Is there a way to directly plot model average summary outputs from MuMIn model.avg() for different variables with confidence bands. Previously I had been using ggplot and ggpredict to plot terms from the actual models, but I haven't been able to find a way to plot the results of the averaged models.

很明显,我可以手动绘制斜率并进行截距,但是获取准确的置信带并通过confint()绘制并不理想,而且我还没有从看起来正确的区间中获得置信带.

Clearly I can plot the slope and intercept manually, but getting accurate confidence bands and plotting from confint() is not ideal and I have yet to get confidence bands from the intervals that look correct.

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)

Dredged <- dredge(lm(a ~ b + c + d, data=df), rank=AIC)
ModelAvg <- model.avg(Dredged, subset=delta<=2)


CI <- confint(ModelAvg, full=T) # get confidence intervals
summary(ModelAvg)


#I want to be able to create a graph for each term from the averaged output with its estimate, SE, and Confidence bands


#Output - I've only left the relevant part of the output, my actual data ends up with 5 component models
#Call:
#model.avg(object = Dredged, subset = delta <= 2)
#Component models: 
#    df logLik   AIC delta weight
#12   4  -1.32 10.63  0.00   0.69
#123  5  -1.10 12.21  1.58   0.31

#Model-averaged coefficients:  
#(full average) 
#             Estimate Std. Error Adjusted SE z value Pr(>|z|)
#(Intercept)  4.933497   1.308953    7.725454   0.639    0.523
#b            0.021946   0.010320    0.048539   0.452    0.651
#c           -0.044848   0.012076    0.067954   0.660    0.509
#d           -0.002275   0.014081    0.088694   0.026    0.980


推荐答案

我不太确定我是否理解您为什么要质疑"confint()"输出,并且其输出的有效性确实是与图表不同的问题问题.

I'm not quite sure I understand why you are questioning "confint()" output, and the validity of its output is really a distinct question from the graphing question.

要绘制系数+/- SE,adj. SE和95%CI,请尝试以下方法.由于您在CI中使用了full=T参数,因此使用了完整的模型平均值.

To graph the coefficient +/- SE, adj. SE and 95% CIs, try the following. This uses the full model average, since you used the full=T argument in the CI.

该图不是最漂亮,但是可以完成工作-如果您想要更好的图,请告诉我.我没有绘制截距图,因为在这种情况下估算值远大于系数,但是所有数据都采用易于绘制的格式.

The graph is not the prettiest, but it does the job - let me know if you want a nicer one. I haven't graphed the intercept because the estimates are much greater than the coefficients in this case, but all the data is in an easily graphable format.

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,调整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) 

将产生以下图形.红色是SE,蓝色是adj. SE和粉红色是95%CI.

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")

这篇关于如何从MuMIn model.avg()摘要进行绘图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆