No history yet

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.

Your path
Model Structure and Interpretation
Implementation and Practical Examples

What is a Mixed Effects Model

In standard linear regression, we assume all our observations are independent. But in real-world research, data is often clustered. For example, if you measure the same patient's heart rate multiple times, or look at exam scores of students grouped inside different schools, those measurements are naturally correlated. A (also known as a multilevel or hierarchical model) is a statistical model designed specifically for this kind of structured data. It gets the name "mixed" because it contains two types of mathematical terms: fixed effects and random effects.

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

are the variables we typically care about making direct predictions or conclusions about. These represent specific, repeatable levels that we choose and expect to have a systematic impact on our outcome—such as comparing a treatment group to a control group, or looking at the effect of age on cognitive scores. If you ran the experiment again, you would use the exact same levels. , on the other hand, are variables where we want to control for variation, but we don't necessarily care about the specific levels themselves. Instead, we treat the levels as a random sample from a larger population. The classic example is "Subject" or "Participant." You don't specifically care about how Patient 14 differs from Patient 15; you just want to control for the fact that individuals vary, so you can see the overall pattern of your fixed effects more clearly.
FeatureFixed EffectsRandom Effects
GoalEstimate specific, systematic impactControl for grouped/nested variation
LevelsSelected, repeatable (e.g., treatment vs. placebo)Random sample of a population (e.g., classroom, patient ID)
InferenceGeneralizes only to those specific levelsGeneralizes 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

To understand how the mathematical machinery actually works here, we need to look at . In standard regression, we fit a single intercept (a shared starting point) for everyone. But in our math study, schools might start at very different baseline levels due to funding, location, or resources. A random intercept model allows each school to have its own unique baseline starting point. Instead of estimating 15 separate, unconnected regression lines, the model treats these individual baselines as deviations from one overall average baseline. This allows us to calculate how much variation exists between schools while still figuring out the true, overall relationship between study hours and math scores.

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?