Random-effects in regressions

Hierarchical and Mixed Effects Models in R

Richard Erickson

Data Scientist

Figure of multi-levels schools

Hierarchical and Mixed Effects Models in R

Figure of multi-level models

Hierarchical and Mixed Effects Models in R

Algebraic representation

$ y \sim \beta_i x + \epsilon$

$ \beta_i \sim ~ \text{Normal}( \mu, \sigma)$

Hierarchical and Mixed Effects Models in R

R syntax

library(lme4)

lmer(y ~ x + (1 | random_group), data = my_data)
lmer(y ~ x + (random_slope | random_goup), data = my_data)
Hierarchical and Mixed Effects Models in R

Random-effect models with school data

  1. Does the sex of a student impact their knowledge gain?
  2. Does the teacher's training impact the gain and does the teacher's math knowledge impact the gain?
Hierarchical and Mixed Effects Models in R

Let's practice!

Hierarchical and Mixed Effects Models in R

Preparing Video For Download...