预测SE的行不适用于混合效果模型lmer或lme

时间:2018-09-05 11:27:29

标签: r

第二天,看不到解决方案。

我正在使用基本绘图功能来创建植物高度与温度的关系图。有两种预测线-一种用于森林栖息地,一种用于草地栖息地。我希望这两行显示标准错误。

当我使用模型:mod1<-lm(plant.height ~ temp*habitat, data = data1)时,一切都很好。但是,我的实际模型是混合模型,因此需要添加随机效果。

当我使用模型mod1<-lmer(plant.height ~ temp:habitat + (1|plot), data = data1)

我得到:Error in eval(predvars, data, env) : object 'plot' not found In addition: Warning message: In predict.merMod(mod1, newdata = data.frame(temp = seq(21, : unused arguments ignored

如果我使用模型:mod1<-lme(plant.height ~ temp*habitat, random = ~1|plot, data=data1)

我得到:Error in predict(mod1, newdata = data.frame(temp = seq(21, 30, length.out = 1000), : $ operator is invalid for atomic vectors

我的代码如下:

data1<-plant.height.data
mod1<-lmer(plant.height ~ temp:habitat + (1|plot), data = data1)
t1<-aggregate(plant.height ~ plot + habitat + temp, data1, mean)
points(plant.height ~ jitter(temp+1, factor=.8), 
data=t1[t1$habitat=="forest",], bg=ucol, pch=24, cex=2)
points(plant.height ~ jitter(temp, factor=.8), 
data=t1[t1$habitat=="meadow",], bg=rcol, pch=21, cex=2)
lines(predict(mod1, 
newdata=data.frame(temp=seq(21,30,length.out=1000),habitat="meadow"), 
level=0) ~ seq(21,30,length.out=1000), col=rcol, lwd=3)
lines(predict(mod1, 
newdata=data.frame(temp=seq(21,30,length.out=1000),habitat="meadow"), 
level=0, se=T)$fit-
predict(mod1, 
newdata=data.frame(temp=seq(21,30,length.out=1000),habitat="meadow"), 
level=0, se=T)$se.fit ~ seq(21,30,length.out=1000), col=rcol, lwd=1, lty=2)
lines(predict(mod1, 
newdata=data.frame(temp=seq(21,30,length.out=1000),habitat="meadow"), 
level=0, se=T)$fit+
predict(mod1, 
newdata=data.frame(temp=seq(21,30,length.out=1000),habitat="meadow"), 
level=0, se=T)$se.fit ~ seq(21,30,length.out=1000), col=rcol, lwd=1, lty=2)

谢谢。

0 个答案:

没有答案
相关问题