Concept · Statistics Library

Random effect

A random effect models the levels of a grouping variable (like subject, site, or batch) as a sample drawn from a larger population of possible groups, rather than as the fixed, specific set of categories the analysis cares about individually.

Topic indexA reference reading outside the guided chapter sequence

Understand the idea

A FIXED effect treats a factor's levels as the exact categories you care about reporting: 'treatment vs. placebo' is fixed because those are the two specific groups the study is about. A RANDOM effect instead treats the levels as a sample from a bigger population: the 20 schools in a study are not the only schools anyone cares about, they stand in for 'schools in general'.

This distinction matters for how much you can generalize: with schools as a random effect, the model estimates how much schools TEND to vary, and that variance estimate is expected to hold for a new school not in the study. With schools as fixed, the model only describes those exact 20 schools and says nothing formal about a 21st.

Mixed models combine both kinds in one model: fixed effects for the things you want a specific estimate of (a treatment's effect), and random effects for the grouping structure that creates repeated or clustered measurements (patients within a study, students within schools), which is exactly the tool for the non-independence that a plain t-test or regression cannot handle.

A random intercept lets each group, such as each school, have its own starting level, so some schools sit higher and some lower than the overall average. A random slope goes further and lets the effect of a predictor differ from group to group, such as a teaching method that helps more in some schools than in others. A model that contains both fixed and random effects is called a mixed model or mixed-effects model. The intraclass correlation, or ICC, is the share of the total variation that comes from differences between groups; a high ICC means rows in the same group are very alike.

Practitioner explanation

A random intercept model specifies y_ij = beta_0 + beta_1*x_ij + u_j + e_ij, where u_j ~ N(0, tau^2) is the group-level deviation and e_ij ~ N(0, sigma^2) the residual; the intraclass correlation ICC = tau^2 / (tau^2 + sigma^2) quantifies what fraction of total variance sits at the group level and, equivalently, how correlated observations within the same group are.

The fixed-vs-random choice is a modeling decision, not purely a data-generating fact: with few groups (roughly under 5-8) random-effect variance components are poorly estimated and a fixed-effects (dummy-variable) approach is often more stable; with many groups and interest in the POPULATION of groups rather than the specific ones observed, random effects borrow strength across groups (shrinkage toward the grand mean) and generalize correctly to a new group.

KernelStats' Linear Mixed-Effects Model reports the group_variance, residual_variance and their ratio as ICC directly on the card, so the analyst can see how much of the outcome's variation is structural (between-group) versus residual (within-group) without computing the ratio by hand, and the card fits a random INTERCEPT per group only: random slopes, crossed random effects and non-normal (generalized) mixed models are out of scope for this function.

When to use it

Consider it when

Whenever observations are naturally clustered (patients within clinics, students within schools, repeated measures within subjects) and you want to generalize beyond the specific clusters observed.

Use caution when

Do not fit a random effect over a grouping factor with very few levels (under about 5); the variance component will be poorly estimated and a fixed-effect (dummy variable) approach is usually more stable there.

Formulas and symbols

Intraclass correlation from a random-intercept model

ICC=τ2τ2+σ2ICC = \frac{\tau^2}{\tau^2 + \sigma^2}

tau^2 is the between-group variance component, sigma^2 the residual (within-group) variance.

Common misconceptions

Misconception

Adding a random effect for subject is the same as just adding subject as a fixed-effect predictor.

Correction

A fixed effect estimates a separate parameter per level and generalizes only to those exact levels; a random effect estimates one variance component describing how levels TEND to vary, which is what lets the model generalize to a new, unobserved level of that grouping factor.

References

  1. NIST/SEMATECH e-Handbook of Statistical Methods, §3.3.4 Random effects models, NIST/SEMATECH (2012), §3.3.4.