I want to compare lme4 and nlme packages for my data. But I'm confused by how to use syntax in nlme. I'm working with Mixed-Effects Models in S and S-Plus (Pinheiro, Bates 2000) and the current Version of the documentation Package 'nlme' (04/07/2018)
I tried to use groupedData()
as well as nlsList()
and SSlogis()
, to fit my model.
For lme4 I can fit my models wihtout any trouble. Can you tell me, how to fit these models from lme4 in nlme?
My data has easy structure:
$y$ is a binary outcome in $\{0,1\}$, $x$ is continuous, $group$ is categorical grouping factor ($N$ different groups)
model1 <- glmer(y ~ (1 | group), data = data , family = binomial(link="logit"))
model2 <- glmer(y ~ 1 + (x | group), data = data , family = binomial(link="logit"))
model3 <- glmer(y ~ (x | group) group, data = data , family = binomial(link="logit"))
model4 <- glmer(y ~ x + (1 | group), data = data , family = binomial(link="logit"))
Best Answer
I was looking for a way to do what you're trying to accomplish and came across a couple of things. First was this question that was asked elsewhere on the website with this answer. The second was this paper, which did exactly what you were asking about. What they did was perform a logit transformation on the response variable, which could then be fitted into the
lme
function.Full disclosure:
1. According to the answer I linked above, the method I'm about to share is apparently not recommended (though the comment by Aaron on the answer indicates that this is a very common way of doing it?)
2. There are very different results with the outputs I'm about to provide
Okay, onwards and outwards...
1. Create some simulated data
2. Logit-transform the response variable and prepare our data frame
3. Run some models
4. Look at the summaries
The results from
test.glmer
andtest.glmmTMB
are quite similar, but thetest.lme
results (i.e. the one where we logit-transformed the response variable) is just a little bit different.Also note that the
nlme
output uses a t-test, whileglmer
andglmmTMB
use a z-test. More on the z-test used to test individual parameters can be found here.5. Compare back-transformed estimates
6. Let's look at some visualizations.
So the result we get from the logit-transformed response variable with the linear
nlme
is slightly different from outputs provided using theglmer
andglmmTMB
when specifying thebinomial
family. It also doesn't take too much to see that there is a difference between the methods when looking at the visuals.Now the question is why is it different. I'm sure there is an answer, I just don't know what it is.
Some other things:
lme
method is to fit an autoregressive correlation structure of some kind to account for temporal/spatial autocorrelation, much like was done in the paper I mentioned earlier. Ben Bolker does provide a succinct brain dump (unlike this answer) on which packages can be used for fitting mixed models with temporally autocorrelative data, though I haven't tried any of them myself (I'm afraid I'm too intimidated to even try, lets I break R again).