Skip to content

Specification of binomial mixed model with custom intercept

1 message · Tom Wenseleers

#
Hi Dale,
Many thanks for the pointer - yes, it turned out that this was indeed the right syntax, e.g. for a binomial GLM (analogous syntax for a binomial mixed model) :

data=data.frame(treatment=c("INF","CONTR","INF","CONTR","INF","CONTR","INF","CONTR"),day=c(4,4,8,8,12,12,16,16),infected=c(20,11,18,15,19,16,19,19),not_infected=c(0,9,2,5,1,4,1,1))
data$propinfected=data$infected/(data$infected+data$not_infected)
data$baseline=qlogis(c(0.01,0.99))[data$treatment] # to have starting vals near 0 or 1 for the two groups (CONTROL and experimentally INFected)
fit=glm(cbind(infected,not_infected)~ -1+treatment:log(day),offset=baseline,family=binomial,data=data)

(used log(day) here because that gave a better fit)

Basically, it's a binomial GLM to describe the evolution of the proportion of infected individuals as a function of time (day) in two groups, a CONTROL group, where the initial prop of infecteds is known to be near 0 at day=0, and an experimentally infected group INF, where the initial prop of infecteds is known to be near 1 at day=0.

Turned out the problem had more to do with getting the effects package to plot the model correctly.
Apparently the effects package only supports specifying one fixed intercept/offset - in my case I got around this by plotting the predictions for the two groups separately and each time suppressing the other group's output, and specifying the correct offset for each group : 

library(effects)

a=plot(effect(fit,term="treatment:log(day)",xlevels=list(day=seq(0.01, 17, 1)),offset=qlogis(0.01) ),ylim=c(-0.05,1.05),xlim=c(-1,17),multiline=T,xlab="Day",ylab="Proportion infected",ci.style="bands",rescale.axis=F,rug=F,lines=c(1,1),lwd=c(2,2),colors=c("black",rgb(1,1,1,0)))

b=plot(effect(fit,term="treatment:log(day)",xlevels=list(day=seq(0.01, 17, 1)),offset=qlogis(0.99) ),ylim=c(-0.05,1.05),xlim=c(-1,17),multiline=T,xlab="Day",ylab="Proportion infected",ci.style="bands",rescale.axis=F,rug=F,lines=c(1,1),lwd=c(2,2),colors=c(rgb(1,1,1,0),"red"))

library(latticeExtra)
c=xyplot(propinfected~day,data=data,pch=15,cex=2,col=data$treatment,ylim=c(0,1),xlim=c(-1,17))
a+as.layer(b)+as.layer(c)

Of course I could also use predict() directly, or work with the Effect() dataframes to plot the model, rather than apply this hack...

cheers,
Tom