# Multilevel/Mixed Models

• Papers on the relationship between the multilevel/mixed modeling and structural equation modeling (SEM) with latent variables:
• Bauer, D.J. (2003). Estimating multilevel linear models as structural equation models. Journal of Educational and Behavioral Statistics, 28, 135-167. [1]
• Curran, P.J. (2003). Have multilevel models been structural equation models all along? Multivariate Behavioral Research, 38, 529-569. [2]

## Software for Multilevel Models

Name Software Summary Reference
npmlreg
Non-parametric maximum likelihood
R Rnews (2007)

## Notes on Snijders & Bosker (2012)

### Hausman test (p. 57)

Is equivalent to a test that the between group effect of a variable is equal to the within group effect, i.e. that there is no 'contextual' effect of the variable beyond its within group effect. S&B state that the test has been wrongly used to decided between using a random effects versus a fixed effects model. It should be used to decide on the inclusion of a 'contextual' variable in addition to the original 'raw' variable or, equivalently in the fixed portion of the model, the inclusion of the contextual variable together with the 'centered-with-group' variable.

### Within- and between-group regression coefficients (p. 58)

They can have opposite signs providing an example of Robinson's Paradox.

### Centering variables with random slopes (p. 87ff)

This issue concerns centering the variable that appears in the 'random' portion of the model. The variable can appear uncentered or centered in fixed part of the model independently of the way it appears in the random part of the model. If the contextual variable is included in the fixed part of the model, then choosing either the centered-within-group (CWG) or the raw variable in the fixed part yields the same model with different parametrizations. Note that the contextual variable would not normally appear in the random part of the model because it is a level-2 variable. Using the raw variable versus the CWG variable in the random part yields different models as S&B discuss in the bottom half of p. 88.

It's a small point but the second to last paragraph on p. 88 might give the impression that the same variable (CWG or raw) needs to be used in the fixed part and in the random part. This is not the case. One can use raw in the fixed part so that the regression output provides a direct estimate of the contextual effect and the CWG in the random part.

The last paragraph seems to reify the relationship between Y and X versus Y and X-Xbar. In the presence of Xbar they are not distinguishable. What matters to distinguish the two models is the shape of the random scatter of within-group regression lines relative to group means for X and for Y.

There's a relevant connected point at the top of p. 89: Interactions among level-1 variables will produce different fixed models depending on the centering of the variables.

## Issues in mixed models

### Missing data in longitudinal studies

#### Using Julia from R to fit mixed models

from Doug Bates (2018):

Many users experience long execution times and convergence warnings when trying to fit complex linear mixed-effects models with lmer. I have, in the past, shown that such models can be fit using the MixedModels ( https://github.com/dmbates/MixedModels.jl) package for Julia ( https://julialang.org) and that the data can be pulled from an R representation using either the RCall ( https://github.com/JuliaInterop/RCall.jl) or RData ( https://github.com/JuliaData/RData.jl).

Recently the JuliaCall package for R (https://github.com/Non-Contradiction/JuliaCall) has become available on CRAN. I have a short note at http://rpubs.com/dmbates/377897 on how to use that package to fit models using MixedModels from R.