- ger.: Mehrebenenanalye – Hierarchisch Lineare Modellierung
- engl.: multilevel modelling – random effects modelling – hierachical linear modelling – mixed modelling – random coefficient modelling

### What does random intercept mean? Is there a difference between random effect and random intercept model?

A random intercept model estimates separate

interceptsfor each unit of each level at which the intercept is permitted to vary. This is one kind of random effect model. Another kind of random effect model also includesrandom slopes, and estimates separate slopes (i.e. coefficients, betas, effects, etc. depending on your discipline) for eachvariablefor each unit of each level at which that slope is permitted to vary.

# Why Random Intercepts?

Why not simply include L2 variable in the model as a fixed factor/ control variable?

- fine if L2 has few categories
- not really interested in difference between counties
- if a lot of dummy categories -> eat up a lot of degrees of freedom

# Random Intercept + Fixed Slope/ Effects

#### what?

- the slopes for groups are assumed to be of the same value
- the structural part of the model is also called fixed effects

#### why?

- The researcher is interested in the characteristics of the sample, not the population
- weak effects??

# Random Intercept + Random Slope/ Effects

#### what?

- Effects are modelled allowing the slopes to vary between groups.

#### why?

- Enhance computation of fixed effects
- Not interested in L2 effects within sample, but in the effects in general population
- (might) fit the data better

#### report?

- variance in intercepts
- variance of slopes
- covariance of slopes and intercepts

# Missing Data

- partially missing data not a big problem
- at least two points needed for calculating slope
- if only one data point only intercept is computed

# Formulas and Code in R

grand mean centering predictors (makes interactions easier to interpret)

1 |
cgrade <- df$grade - mean(df$grade) |

### relevant packages and formula variations:

{nlme}

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# lme ## Simple multi level linear null model lme(fixed = grade ~ 1, random = ~1|school, data = df) ## Simple multi level linear null model with one predictor lme(fixed = grade ~ intervention, random = ~1|school, data = df) ## Simple multi level linear null model with several predictors lme(fixed = grade ~ intervention + other_grade, random = ~1|school, data = df) ## Random coefficient model lme(fixed = grade ~ intervention, random = ~intervention|school, data = df) ## Random coefficient model with several random slopes lme(fixed = grade ~ intervention + other_grade, random = ~intervention + other_grade|school, data = df) ## Interactions on Level 1 lme(fixed = grade ~ intervention + other_grade + intervention*other_grade, random = ~1|school, data = df) ## Crosslevel Interactions lme(fixed = grade ~ intervention + context_L2 + intervention*context_L2 , random = ~1|school, data = df) ## Use Maximum Likelihood (ML) instead of Restricted Maximum Likelihood (REML) lme(fix = grade ~ intervention, random = ~1|school, data = df, method = "ML") ## Three-Level Model lme(fix = grade ~ 1, random = ~1|school/class, data = df) ## Three-Level Model with random effects for specific coefficient (here: other_grade) lme(fix = grade ~ intervention + other_grade, random = list(school = ~1, class = ~other_grade, data = df) |

1 2 3 |
# glmmPQL ## Random Intercept Logistic Regression glmmPQL(grade ~ intervention, random = ~1|school, family = "binomial") |

{lme4}

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# lmer ## Random Intercept Models lmer(grade ~ intervention + (1|school), data = df) lmer(grade ~ intervention + other_grade + (1|school), data = df) ## P Values with MCMC, requires packages coda, languageR pvals.fnc(lmer_fit, nsim = 10000, withMCMC = T) ## Random Coefficient Models lmer(grade ~ intervention + (intervention|school), data = df) ## Correlated Random Coefficients lmer(grade ~ intervention + other_grade + (intervention + other_grade|school), data = df) ## Uncorrelated Random Coefficients lmer(grade ~ intervention + other_grade + (intervention|school) + (other_grade|school), data = df) ## Use Maximum Likelihood (ML) instead of Restricted Maximum Likelihood (REML) lmer(grade ~ intervention + (1|school), data = df, REML = F) ## Three-Level (null) model - post: pvals.func() lmer(grade ~ 1 + (1|school/class), data = df) |

1 2 3 |
# glmer ## Multi Level Logistic Model glmer(grade ~ intervention) + (1|school), family = binomial, nAGQ = 25, data = df) |

{ordinal}

1 2 3 4 |
# clmm ## Multi Level ordinal regression clmm(grade ~ intervention + (1|school), data = df) # uses lme4 style formulas |

{MCMCglmm}

1 2 |
# Bayesian Multilevel Modeling MCMCglmm(grade ~ intervention, random = ~school, data = df) |

Comparing model fits with ANOVA

1 |
anova(model1, model2) |