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