Lme4 :: glmer vs Stata melogit

Recently, I have been trying to fit many random effect models to relatively large data sets. Suppose that about 50,000 people (or more) observed up to 25 time points. With such a large sample size, we include many predictors that have been adjusted โ€” perhaps 50 or so fixed effects. Im fitting the model to a binary result using lme4::glmer in R, with random hooks for each object. I cannot go into the details of the data, but the main format of the glmer command that I used was:

 fit <- glmer(outcome ~ treatment + study_quarter + dd_quarter + (1|id), family = "binomial", data = dat) 

where both study_quarter and dd_quarter are factors with approximately 20 levels each.

When I try to fit this model into R, it works for about 12-15 hours and returns an error with which it did not converge. I did a bunch of troubleshooting (e.g. following these guidelines), without any improvement. And the convergence does not even end at the end (the maximum gradient is about 5-10, while the convergence criterion is 0.001).

Then I tried to fit the model in Stata using the melogit command. The model fits in less than 2 minutes, with no convergence issues. Corresponding Stata command p>

 melogit outcome treatment i.study_quarter i.dd_quarter || id: 

What gives? Does Stata have a better fitting algorithm or is it better optimized for large models and large data sets? Its really amazing how different the lead times are.

+7
r lme4 mixed-models stata
source share
2 answers

The glmer fit is likely to be much faster with the optional argument nAGQ=0L . You have many parameters of fixed effects (20 levels for each of study_quarter and dd_quarter generate a total of 28 contrasts), and the default optimization method (corresponding to nAGQ=1L ) puts all these coefficients in a general nonlinear optimization call. Using nAGQ=0L these coefficients are optimized in the much faster curved iteratively reversed least squares (PIRLS) method. The default value usually provides a better estimate in the sense that the deviation from the estimate is lower, but the difference is usually very small and the time difference is huge.

I have a record of the differences in these algorithms as a Jupyter notepad nAGQ.ipynb . This entry uses the MixedModels package for Julia instead of lme4 , but the methods are similar. (I am one of the authors of lme4 and the author of MixedModels .)

If you are going to do a lot of GLMM tricks, I would think of it in Julia using MixedModels . It is often much faster than R , even with all the complex code in lme4 .

+6
source share

Are you sure Stata is reading the entire file?

http://www.stata.com/manuals13/rlimits.pdf

I ask because it sounds to me as if you have observed 50,000 people 25 times (1,250,000 lines); depending on the version of Stata you are using, you may get truncated results.

EDIT Since this is not a file length problem, have you tried other packages for mixed effects like nlme? I suspect that the model of non-linear mixed effects will require your data a little faster.

EDIT This resource may be more useful than anything in different models: https://stats.stackexchange.com/questions/173813/r-mixed-models-lme-lmer-or-both-which-one-is- relevant-for-my-data-and-why

0
source share

All Articles