Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 随机效应点图_R_Plot_Lme4 - Fatal编程技术网

R 随机效应点图

R 随机效应点图,r,plot,lme4,R,Plot,Lme4,我有一个广义混合效应模型,如下所示: d <- data.frame( g = sample(c("A","B","C","D","E"), 250, replace=TRUE), x = runif(250, max=100), y = sample(c(0,1), 250, replace=TRUE) ) require(lme4) fm <- lmer(y ~ x + (1 + x | g), data=d, family=binomial) 使

我有一个广义混合效应模型,如下所示:

d <- data.frame(
    g = sample(c("A","B","C","D","E"), 250, replace=TRUE),
    x = runif(250, max=100),
    y = sample(c(0,1), 250, replace=TRUE)
)

require(lme4)

fm <- lmer(y ~ x + (1 + x | g), data=d, family=binomial)

使用
dotplot(ranef(fm,postVar=TRUE)$g[,2])
不会给我想要的东西,即使我认为应该!我已经看了
str(fm)
,但没有看到任何帮助我更接近的东西


任何帮助和提示都将不胜感激

你只需要稍微聪明一点就可以移除另一列随机效果:

re <- ranef(fm,postVar = TRUE)
re$g$x <- NULL
dotplot(re)

re您没有看到正确的str()

re <- ranef(fm, postVar = TRUE)
str(re)

re这会让你非常接近。我一直想在
coefplot
中添加对
lme4
对象的支持,所以这可能是我的催化剂

theRan <- ranef(fm, postVar=TRUE)
pv <- attr(theRan$g, "postVar")
se <- pv[1, 1, ]
theIntercepts <- theRan$g[, 1, drop=F]
theFrame <- cbind(theIntercepts, se)
names(theFrame)[1] <- "Intercept"
theFrame$Low <- with(theFrame, Intercept - 2 * se)
theFrame$High <- with(theFrame, Intercept + 2 * se)
theFrame$Variable <- rownames(theFrame)
ggplot(theFrame, aes(y=Intercept, x=reorder(Variable, Intercept))) + geom_linerange(aes(ymin=Low, ymax=High), colour="black") + geom_point(, colour="blue") + coord_flip() + labs(y="Intercept", x=NULL)

theRan您的原始代码几乎达到了目的:

dotplot(ranef(fm, postVar=TRUE))$g[1]
为每个绘图释放刻度的附加提示:

dotplot(ranef(fm, postVar=TRUE),
        scales = list(x =list(relation = 'free')))

谢谢,这是一个很好的答案!
dotplot(ranef(fm, postVar=TRUE))$g[1]
dotplot(ranef(fm, postVar=TRUE),
        scales = list(x =list(relation = 'free')))