I am modelling the activity of animals (subjects). Each subject is measured for activity repeatedly (which requires a random intercept associated with subject). Subjects have also been measured in two environments (a and b). I specifically want to see if the activity level of a given subject in environment a correlates with its activity level in environment b.
In line with this really useful answer (How to specify uncorrelated random slopes in lmer() syntax?), I tried doing a log-likelyhood ratio test on these models:
full.model <- lmer(activity ~ (1+environment|subject), family='binomial') no.correlation.model <- lmer(activity ~ (1|subject) + (environment-1|subject), family='binomial')
It appears that this code works nicely for gaussian data, but that it does not for binomial data. In this case, no.correlation.model has two random intercepts, a 'slope' associated with environment and a correlation.
Is there a way to test whether the correlation estimated in full.model is significant?
Here is a reproducible dataset.
activity <-rbinom(n=1000, size=1, prob=0.5) subject <- rep(1:100,each=10) environment <- rep(c('a', 'b'), 500)
Many thanks in advance!