R 绘制clmm的随机截距

R 绘制clmm的随机截距,r,ordinal,ggplot2,R,Ordinal,Ggplot2,我很难在31个国家的clmm模型中绘制出随机截获,有4个随机效应 我试着跟随这篇文章:然而,我无法得到置信区间。我设法用点图按国家划分截获量 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 i

我很难在31个国家的clmm模型中绘制出随机截获,有4个随机效应

我试着跟随这篇文章:然而,我无法得到置信区间。我设法用点图按国家划分截获量

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],))
dotchartdf[,2]中出错,labels=df[,1]+geom_errorbarhaesxmax=df[,:二进制运算符的非数值参数

根据第5页找到了解决方案

首先绘制所有31个国家/地区的截距点,使用轴添加标签,然后使用线段添加CI

可以将此代码放入另一个循环以绘制随机效果的Beta

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