我很难从一个clmm()模型中随机拦截31个国家的4种随机效应。
我试着遵循这样的帖子:在R中,用qqmath dotplot绘制来自lmer (lme4包)的随机效果:如何使它看起来很漂亮?,但是,我无法得到信任间隔来显示。我已经成功地使用dotchart来按国家绘制拦截图。
library(ggplot2)
library(ordinal)
# create data frame with intercepts and variances of all random effects
# the first column are the grouping factor, followed by 5 columns of intercepts,
# columns 7-11 are the variances.
randoms <- as.data.frame(ranef(nodual.logit, condVar = F))
var <- as.data.frame(condVar(nodual.logit))
df <- merge(randoms, var, by ="row.names")
# calculate the CI
df[,7:11] <- (1.96*(sqrt(df[,7:11])/sqrt(length(df[,1]))))
# dot plot of intercepts and CI.
p <- ggplot(df,aes(as.factor(Row.names),df[,2]))
p <- p + geom_hline(yintercept=0) +
geom_errorbar(aes(xmax=df[,2]+df[,7], xmin=df[,2]-df[,7]), width=0, color="black") +
geom_point(aes(size=2))
p <- p + coord_flip()
print(p)误差:离散值提供给连续标度
这是另一种我试图设计它们的方法:
D <- dotchart(df[,2], labels = df[,1])
D <- D + geom_errorbarh(aes(xmax=df[,2]+df[,7], xmin=df[,2]-df[,7],))错误的点图( df,2,标签=df,1) + geom_errorbarh(aes(xmax = df[,:二进制运算符的非数值参数)
发布于 2014-04-28 16:49:07
找到了一个基于R.H.B Christensen (2013年)“关于从序号包中用clmm2拟合累积链接混合模型的教程” pg的解决方案。5.
首先为所有31个国家设置拦截点,然后使用axis()添加标签,然后使用segments()添加CI。
plot(1:31,df[,2], ylim=range(df[,2]), axes =F, ylab ="intercept")
abline(h = 0, lty=2)
axis(1, at=1:31, labels = df[,1], las =2)
axis(2, at= seq(-2,2, by=.5))
for(i in 1:31) segments(i, df[i,2]+df[i,7], i, df[i,2]-df[i, 7])可以将这些代码放入另一个循环中来绘制随机效果的Betas。
for(n in 2:6) plot(1:31,df[,n], ylim=range(df[,n]),axes =F, ylab =colnames(df[n]))+
abline(h = 0, lty=2)+
axis(1, at=1:31, labels = df[,1], las =2)+
axis(2, at= seq(-2,2, by=.5))+
for(i in 1:31) segments(i, df[i,n]+df[i,(n+5)], i, df[i,n]-df[i, (n+5)])https://stackoverflow.com/questions/23345884
复制相似问题