rmixed-modelsglmmtmb

How to structure random slope with interactions using glmmTMB in R


I am trying to:

However, no animal in my data set has observations in both seasons.

I am using R package glmmTMB to estimate a binomial GLMM with random intercept and random slope for animal ID, but I don't know how to represent the effects of landcover (the variable of interest) and season in the model formula.

I have tried these two variations:

1)

glmmTMB(presence ~ landcover:season + (1 | ID) +  (0 + landcover:season | ID),  
        family = binomial(), data = dat.rsf, doFit = FALSE, weights = weight)

This one is more intuitive to me, but does not converge. Is that just an indication that I cannot estimate this model with my data? Or is this model not the best way to get at the relationships that I am trying to test?

2)

glmmTMB(presence ~ landcover:season + (1 | ID) +  (0 + landcover | ID), 
        family = binomial(), data = dat.rsf, doFit = FALSE, weights = weight)

This converges, but is not as intuitive. Does it make sense to not include the interaction in the random slope when I include it as a fixed effect? Or does that violate the principle of a random slope?


Solution

  • tl;dr I would suggest

    glmmTMB(presence ~ landcover*season + (1 + landcover | ID), 
            family = binomial(), data = dat.rsf, 
             weights = weight,
             map = list(theta=factor(c(NA, 1, 2))),
             start = list(theta = c(log(1e3), rep(0, 2))
        )
    

    (noting that landcover is a continuous predictor).