r - clmm后如何使用dotplot

标签 r lattice multi-level ordinal

我尝试在 clmm 之后绘制随机效应,但收到错误消息:“sort.list(y) 中的错误:'x' 对于 `sort.list' 必须是原子的,你知道吗?称为“排序”列表?”以下代码代表我的实际代码。

library(ordinal)
library(lattice)

###I am using the wine data in the ordinal package
d<-data.frame(wine)
result<-clmm(rating~1+temp+contact+(1+temp|judge), data=d)
###In my actual codes, I put "as.ordered(rating)" instead of "rating".

然后,我尝试绘制温度和判断的随机效应:

dotplot(ranef(result, condVar=TRUE))

然后,出现错误消息:“sort.list(y) 中的错误:‘x’对于‘sort.list’必须是原子的,您在列表上调用了‘sort’吗?”

我最好的猜测是,评级是按照 clmm 下的命令实现的,考虑到错误消息,这对我来说似乎是有意义的。然而,这个猜测是高度推测性的,我不知道如何处理这种情况。 具体来说,我想绘制的是 temp 和 Judge(拦截)及其 CI 的随机效应。请参阅我使用下面的代码生成的下图

result2<-lmer(as.numeric(rating)~1+temp+contact+(1+temp|judge), data=d)
dotplot(ranef(result2, condVar=TRUE))

Plot from lmer

如果您可以就如何避免使用 clmm 阻止我使用上面的代码使用 dotplot 看似冲突的情况给出任何评论或建议,它将真的很感激。

最佳答案

我开始尝试破解 lme4:::dotplot.ranef.mer 的内部结构,但事实证明使用 reshape2::melt 可以更轻松地做到这一点> 和 ggplot2。抱歉,如果您非常喜欢lattice...

顺便注意,从技术上讲,这些不是“置信区间”(因为预测的条件模式不是技术、频率论意义上的“估计”)...

将条件模式的点估计和SE重新排列成有用的形状:

library(reshape2)
melt.ranef.clmm <- function(re,cv) {
  reList <- lapply(re,
        function(x) {
           x$id <- reorder(factor(rownames(x)),x[,1])
           return(melt(x,id.var="id"))
        })
  cvList <- lapply(cv,melt,id.var=NULL,value.name="se")
  mm <- Map(cbind,reList,cvList)
  return(mm)
}

将此应用于模型(m1 是拟合模型):

ss <- melt.ranef.clmm(ranef(m1),condVar(m1))

剧情:

library(ggplot2); theme_set(theme_bw())
ggplot(ss[[1]],aes(value,id))+
  geom_errorbarh(aes(xmin=value-1.96*se,xmax=value+1.96*se),
                 height=0)+
  ggtitle(names(ss)[1])+
  geom_point(colour="blue")+
  facet_wrap(~variable,scale="free_x")

enter image description here

关于r - clmm后如何使用dotplot,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38977094/

相关文章:

rpart公式参数用法: "NAs are not allowed in subscripted assignments"

r - 在 R 中使用循环的图的不同标题

c++ - 虚基类在多级继承中有什么用?

jQuery 多级子菜单

r - 在 R 中输出 FALSE 而不是错误

r - R 中的命名空间和泛型函数

r - bwplot 的 boxplot lwd 参数等效

r - 合并或覆盖晶格面板中的xyplots

r - 如何在 xyplot() 中控制面板顺序?

php - 需要对多级缓存场景有一定的了解