mixed effects modeling
Welcome! I am glad you are here to dive into mixed effects modeling. Before we map out our journey and look at how these models handle complex, messy data, I would love to learn a bit more about you so I can make this session as useful as possible.
I have some basic stats (like t-tests and regression) and want to use this for research.
It is great to have you here! Since you already understand basic regression, you are in a perfect position to tackle mixed effects models.
What is a Mixed Effects Model
Continue to the difference between fixed and random effects
Let's unpack the difference between fixed and random effects. It is simplest to think of this as a choice about how we want to treat the variables we are investigating.
Fixed vs. Random Effects
| Feature | Fixed Effects | Random Effects |
|---|---|---|
| Goal | Estimate specific, systematic impact | Control for grouped/nested variation |
| Levels | Selected, repeatable (e.g., treatment vs. placebo) | Random sample of a population (e.g., classroom, patient ID) |
| Inference | Generalizes only to those specific levels | Generalizes to the broader population |
Does this distinction make sense? We can look at a concrete research example next to see how you would classify your own variables.
Continue to a concrete example
To bring this to life, let us walk through a concrete research scenario. Imagine you are running an educational study across 15 different schools to see how a new personalized digital tutoring tool affects student math scores.
The Math Tutoring Study
You collect data from 500 students in total. For each student, you record their final math score, how many hours they spent using the digital tool, their grade level, and the specific school they attend.
Now, let us put your variable classification skills to the test. Which of the variables in this study should be treated as fixed effects, and which should be treated as random effects?
A visual representation of hierarchical data nesting, displaying 15 student nodes clustered inside a parent school container, with arrows pointing from nested components to their corresponding level variables.
Think about our rule of thumb: are you interested in comparing the specific, repeatable impact of the variable (fixed), or do you want to control for the nested variation of a representative sample (random)?
Hours spent and grade are fixed; school is random
Spot on. You nailed it. Hours spent and grade level are fixed effects because you want to estimate their specific, repeatable impact on math scores, while school is a random effect because your 15 schools are a representative sample of a larger population you want to control for.
The Magic of Random Intercepts
A scatter plot of math scores against tutoring hours, showing three parallel regression lines with distinct vertical intercepts representing different schools.
I have set up a placeholder showing how those random intercepts visually shift the regression line up or down for different schools. Notice that while the lines start at different heights, they run parallel to each other. This is because we are only varying the intercept, not the slope.
Are you ready to continue to our next subtopic, where we will dive into how we actually write out and interpret these varying intercepts and slopes in our model structure?