Rewriting the mixed effect model formula from R (lme4) to Julia

I would like to get the same results in Julia as the lmer function from the lme4 library in R. Below is an example and an example of the mtcars built-in dataset using R

library(lme4) data<-mtcars data$vs<-as.factor(data$vs) data$am<-as.factor(data$am) data$gear<-as.factor(data$gear) str(data) model <- lmer(mpg ~ cyl:gear + hp:am + (1|gear:am), data = data) 

I found the lmm() function from the MixedModels package for Julia, which should be able to perform the same results, however I don’t know how to rewrite the formula from the first argument of the lmer() function using lmm() . Especially the interaction operator (:).

I would appreciate a short answer.

+5
source share
1 answer

The correspondence between the R and Julia models here does not seem accurate. There are also problems with various numerical algorithms. But my attempt to recreate the same model using MixedModels as follows:

 using RDatasets using MixedModels mtcars = dataset("datasets","mtcars") mtcars[:AM] = PooledDataArray(mtcars[:AM]) mtcars[:Gear] = PooledDataArray(mtcars[:Gear]) mtcars[:GearAM] = PooledDataArray(collect(zip(mtcars[:Gear],mtcars[:AM]))) m = fit!(lmm(MPG ~ 1 + Gear + AM + Cyl + HP + (1|GearAM),mtcars)) 

Manually creating a mixed effect column - klunky - there may be a better way. Note the differences in naming coefficients between R and Julia. In both cases, there are 6 fixed effect coefficients.

The solution in Julia seems different (on my machine), but achieves a better logarithmic probability. The random effect is expected to be weak, as its variables are already present in fixed effects (it only takes into account the relationship between Gear and AM), and there are only 32 data points.

Hope this helps, and if you come up with a better understanding, it would be nice to add it to another answer or comment.

+2
source

Source: https://habr.com/ru/post/1236001/


All Articles