lme4中glmer线周围的置信区间

时间:2015-03-27 13:47:20

标签: r glm interaction confidence-interval

我花了很多时间试图弄清楚如何生成所需的情节,并且想知道是否有人可以提供帮助。该情节用于说明“时间”与“时间”之间的相互作用。和' group'在二元响应变量上,随着时间的推移,对于第2组'而不是'组1'。以下是使用模拟数据所需的简化版本。我已经正确地为每个小组绘制了一个斜坡(我想),但是现在想要在每个斜坡周围绘制一个置信度。

#simulate 41 individuals, each occurring over a random number of days:
days.each<-sapply(sample(2:40,41,T),function(a)1:a)
thedata<-data.frame(day=unlist(days.each))

#add the individual id in:
thedata$id<-rep(1:41,sapply(days.each,length))

#9 of these individuals are in group 1, and 10 and in group 2:
thedata$group<-ifelse(thedata$id<20,1,2)

#with increasing 'day', the y increases. This relationship is stronger in individuals from group 2:
thedata$y<-(thedata$day*thedata$group)

#Also, some individuals have generally higher 'y' than others:
thedata$y<-thedata$y+rnorm(41,10,3)[thedata$id]

#the y is binomial:
thedata$y<-rbinom(nrow(thedata),1,thedata$y/max(thedata$y))

#change the group and id to class "factor"
thedata$id<-as.factor(thedata$id);thedata$group<-as.factor(thedata$group)

#run the full model:
library(lme4)
model <- glmer(formula=y ~ day*group+(1|id),family=binomial,data=thedata)


#to illustrate the interaction, plot one line for each group:
vals<-predict(model,re.form=NA,type ="response")

plot(y~day,data=thedata,type="n")
lines(sort(vals[thedata$group==1])~sort(thedata$day[thedata$group==1]),col="black")
lines(sort(vals[thedata$group==2])~sort(thedata$day[thedata$group==2]),col="purple")

#now add confidence around these slopes?

任何帮助都会受到大力赞赏

编辑: 以前的问题是基于对具有单个预测变量的线性混合模型的拟合。这个问题涉及来自具有二项式误差结构的广义线性混合模型的x1的每个值的置信度,二项式误差结构包括两个独立变量以及它们之间的相互作用。如果有人能证明如何将类似于Extract prediction band from lme fit的蓝色乐队的东西添加到我的情节中,那就太棒了。

0 个答案:

没有答案