Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accounting for temporal correlation in GLMM

I am trying to account for autocorrelation in a GLMM. My response variable is boolean, it represents the presence and absence of a en event in the life cycle of a set of bee nests. I am trying to predict the probability of such an event with a set of numerical variables describing the state of each nest. Thefore, I used a binomial distribution in a generalized model with nest as a random effect (using glmer()). However, the events are autocorrelated, so I get a pretty horrible pattern in my residuals. If I were using a gaussian distribution in the errors without random effects, I would estimate some correlation parameters using correlation structure with gls(), but that is not gonna work in this case. I have been looking for ways to include this autocorrelation in GLMM, but I don't seem to get it right. I found that the data set can be transformed using the function ts() and diff() to allow the model to include as a predictor, previous values of the response. This works for a linear model lm(), making the residuals much nicer.

basket.1<-subset(basket,select=c(Nest,day,number_cells,provitioning_cells,closed_cells,
                             reopened_cells,eclosed_cells,pollen))
basket.ts<-ts(as.matrix.data.frame(basket.1),start=1,frequency=9)
m.basket.ts1<-lm(pollen~provitioning_cells+reopened_cells+closed_cells
            +eclosed_cells+day,data=diff(basket.ts,differences=2))`

However, neither lmer() nor glm() accept the output of those functions. The problem seems to be the the trasformation makes some values negative, and glm()does not accept negative values for a binomial model (which makes sense). I have read that it is possible to account for autocorrelations glm(), which would already be an improvement,but I cannot make it work. I also read that glmmPQL() can include correlation structures.That model runs, but it does not improve the patterns in my residuals. They still seem to be autocorrelated.

m.basket.glmm1<-glmmPQL(pollen~provitioning_cells+reopened_cells+closed_cells
            +eclosed_cells+day,random=~1|Nest,family=binomial,correlation=corAR1(form=~day),
            data=basket)

I tried different correlation structures and none of them seems to work.

Finally, I tried the dyn package, which is supposed to allow regression functions to handles time series. But once again, the function does not run with the values produced by the transformation.

m.bas.glm.dyn1<-dyn$glm(pollen~provitioning_cells+reopened_cells+closed_cells
                    +eclosed_cells+day,family=poisson,data = diff(basket.ts,differences=3))

To summarize, I need to run GLMM with temporal correlations, but I cannot find a way to do this. I would highly appreciate some help.

Cheers!!!

like image 660
AtiQP Avatar asked Nov 11 '22 05:11

AtiQP


1 Answers

Can you give us a reproducible example? In principle it shouldn't be too hard to lag values 'by hand', e.g.

basket.1 <- subset(basket,select=c(Nest,day,number_cells,
                             provitioning_cells,closed_cells,
                             reopened_cells,eclosed_cells,pollen))
n <- nrow(basket.1)
basket.2 <- transform(basket.1,pollen.lag1=c(pollen[2:n],NA),
                      pollen.lag2=c(pollen[3:n],rep(NA,2)))

library("lme4")
m.basket.glmm1 <- glmer(pollen~provitioning_cells+
                   reopened_cells+ closed_cells+
                    eclosed_cells+day+pollen.lag1+pollen.lag2+
                    (1|Nest),
                   family=binomial,data=basket.2)

Depending on the size of your data set, if day is numeric rather than a factor you might want (day|Nest) instead of (1|Nest) ...

like image 162
Ben Bolker Avatar answered Dec 03 '22 07:12

Ben Bolker