Fixed Effects vs Random Effects: How to Choose

Fixed effects and random effects differ in how they treat the differences between units (people, hospitals, firms, countries). A fixed-effects model lets those differences correlate with your predictors and estimates only within-unit relationships. A random-effects model assumes the differences are uncorrelated with your predictors and uses both within-unit and between-unit variation. Which one fits depends on that assumption, on your research question, and on whether you need to estimate effects of variables that never change within a unit.
The terms also mean slightly different things in different fields. Economists, epidemiologists and psychologists all use them, and a reviewer from another discipline may read your choice differently. This guide covers the panel-regression meaning first, then the mixed-model meaning, then how to read a Hausman test without over-trusting it.
TL;DR
- Fixed effects (FE) estimate within-unit effects and tolerate correlation between unit effects and regressors. They cannot estimate time-invariant predictors.
- Random effects (RE) are more efficient and can estimate time-invariant and higher-level variables, but they assume unit effects are uncorrelated with regressors.
- The Hausman test compares the FE and RE coefficients. A significant result favors FE. A nonsignificant one does not prove RE is right.
- A within-between RE model often answers the question better than choosing one side, because it separates within and between effects.
- Choose from the research question first, then use the test as a diagnostic.
Table of Contents
- What each model assumes
- When to use which
- Fixed and random effects in mixed models
- The Hausman test, step by step
- Practical workflow in R, Python or Stata
- Our perspective
- Run the comparison with PlotStudio AI
- FAQ
- Sources
What each model assumes
In panel regression, FE permits correlation between unit-specific effects and regressors and estimates within-unit effects, while RE assumes those effects are uncorrelated with regressors and uses within- and between-unit variation. That one sentence carries most of the decision.

Fixed effects: within-unit variation only
The FE estimator is based on within-unit variation after removing unit-specific means. Each unit is compared with itself over time (or across repeated measurements). Anything stable about the unit, observed or not, drops out. That is why FE is attractive when you worry about unmeasured confounders such as baseline health, ability, or institutional culture.
The price is that FE models absorb all time-invariant unit characteristics, so you cannot separately estimate the coefficient of something like sex, country of birth or treatment site if it never changes within a unit. For a deeper walk-through with code, see our fixed effects regression guide for R and Python users.

Random effects: partial pooling with an assumption
RE models treat unit effects as draws from a distribution. The key assumption is that lower-level covariates are uncorrelated with higher-level residuals, and violating it produces omitted-variable bias in the RE estimator.
In return, RE models can estimate time-invariant predictors and higher-level variables because unit heterogeneity is represented by a distribution rather than one unrestricted parameter per unit. A random intercept summarizes between-group variability with a single variance parameter, which is more parsimonious than group fixed effects.
Side by side
| Question | Fixed effects | Random effects |
|---|---|---|
| Unit effects vs regressors | May be correlated | Assumed uncorrelated |
| Variation used | Within unit | Within and between unit |
| Time-invariant predictors | Not estimable separately | Estimable |
| Efficiency | Lower | Higher if assumption holds |
| Main risk | Discards between-unit information | Omitted-variable bias if assumption fails |
| Typical use | Policy or treatment effects within units | Generalizing to a population of units, higher-level predictors |
When to use which
Start with what you want to say in the results section.
Use FE when within effects are your target. The guidance from Bell, Fairbrother and Jones is to use FE when within effects are of greatest interest, especially when evaluating policy interventions. Example: you want to know how a patient’s blood pressure changes when their own medication dose changes, not how patients on high doses differ from patients on low doses.
Use RE when you need between-unit or higher-level effects. If your question involves a hospital-level policy, a country-level variable or a participant characteristic that is constant, FE cannot answer it. Bell and Jones argue that FE sacrifices the ability to estimate higher-level processes, while correctly specified RE is more flexible and generalizable.
Do not treat FE as the automatic safe default. FE protects against bias from correlated heterogeneity, but it can throw away theoretically important contextual information. A reviewer who asks “why FE?” is entitled to an answer based on your question, not on habit.
Consider the within-between model. Bell, Fairbrother and Jones recommend a within-between RE specification because it separately represents within-unit and between-unit relationships and is more encompassing than conventional FE or RE. You enter each time-varying predictor twice: its unit mean (between) and its deviation from that mean (within). If the two coefficients differ, that difference is substantively a contextual effect rather than merely a nuisance for model selection.
A quick decision path:
- Write the effect you want to report in one sentence. Is it within a unit, between units, or both?
- List the predictors that never change within a unit. If one of them is central, FE alone is out.
- Ask whether unmeasured stable traits plausibly correlate with your predictors. If yes, you need FE or a within-between model.
- Fit FE and RE (or the within-between model) and compare. Report both when they disagree.
- Use the Hausman test as a diagnostic, not a verdict.
Fixed and random effects in mixed models
The same words mean something a little different in mixed-effects modeling, which is what many clinical and psychology researchers meet first. There, fixed effects represent population parameters, while random effects are sample-dependent random variables whose distributions and covariances must be specified.
Mixed models are built for clustered, longitudinal and repeated-measures data: random intercepts and slopes represent group-specific departures and induce dependence among observations sharing a group. A common rule of thumb from teaching materials is that a factor is random when your data include only a sample of its many possible levels (subjects, schools, sites), and fixed when you have all the levels you care about (treatment arm, sex). Treat that as a starting heuristic, since the panel-data literature above shows the real issue is correlation with regressors and the question you ask.
Two further points help:
- Random effects as shrinkage. Hazlett and Wainstein describe multilevel random effects as regularized or shrunken versions of group-specific fixed effects, with partial pooling toward a common mean. Their efficiency comes from pooling, and bias can arise when group confounding is not modeled.
- Interpretation. For continuous outcomes with an identity link, subject-specific and population-averaged interpretations coincide, but for generalized linear mixed models they can differ. That matters for logistic and count outcomes, such as readmission or infection.
Our practical guide to mixed effects models covers random intercepts, slopes and covariance structures in more detail.
The Hausman test, step by step
The Hausman test compares FE and RE coefficient estimates for the regressors they share. Its null hypothesis is that unit effects are uncorrelated with regressors, so RE is consistent and efficient; the alternative is correlation, under which RE is inconsistent while FE remains consistent. The conventional statistic is a quadratic form in the difference between the FE and RE coefficient vectors and the estimated variance of that difference, compared with a chi-square distribution.
Reading the result
| Result | What it means | What to do |
|---|---|---|
| Significant (small p-value) | Evidence that FE and RE estimates differ; a heuristic to favor the consistency of the fixed-effects model | Prefer FE or a within-between model; report why |
| Nonsignificant | Fails to reject the RE orthogonality assumption; it does not prove the assumption is true | RE remains attractive for efficiency and time-invariant effects; check robustness |
| Test fails to compute (negative or non-positive-definite variance difference) | The classical statistic is unreliable here | Use a robust or regression-based version |
Worked example. Suppose you model weekly symptom score on hours of physical activity for 200 patients over 12 weeks. The FE coefficient is -0.40 and the RE coefficient is -0.75, with a significant Hausman test. Patients who are generally more active also differ in stable ways (fitness, baseline severity), and that correlation contaminates RE. A within-between model would show the within coefficient near the FE value and a different between coefficient, which is a substantive finding in its own right.
Limits you should state in the paper
- It is not a mechanical rule. Bell, Fairbrother and Jones caution that Hausman testing should not mechanically decide FE versus RE: it can diagnose whether within and between relationships differ, while model choice must follow the research question.
- Classical assumptions. The statistic relies on RE efficiency under the null and can be problematic with heteroskedasticity, serial correlation, small samples, or a non-positive-definite variance-difference matrix. If you suspect heteroskedasticity, see our guide to heteroscedasticity tests and fixes and our robust standard errors articles.
- Rejection is not proof that FE is correct. FE removes only time-invariant confounding, so time-varying omitted variables or other endogeneity can bias both FE and RE.
- A hybrid exists. When RE fails the test, a hybrid approach can recover the fixed-effects estimate in a random-effects model, which is the within-between idea again.
Practical workflow in R, Python or Stata
The mechanics are the same in any package: fit the FE model, fit the RE model on the same sample, compare, then test. In R, the panel-data route and the mixed-model route are separate tools, so be explicit about which one you are using. In Python and Stata the pattern is similar. For panel data in general, see our panel data analysis overview and the econometrics articles.
A checklist that survives peer review:
- Report the sample for both models (same observations, same units).
- Use cluster-robust standard errors when serial correlation or heteroskedasticity is plausible.
- Say which question each estimate answers: within, between, or population average.
- Show the FE, RE and within-between coefficients in one table.
- Document the Hausman statistic, degrees of freedom and whether a robust version was used.
- Keep the code and output so a supervisor can reproduce every number.
Our perspective
We see the same pattern across research groups: the model choice is made once, quickly, and defended later under pressure from a reviewer or a supervisor who cannot reproduce the numbers.
The traditional tools, R, Python, Stata, SPSS, SAS and Jupyter, give you the statistical computing. What is often missing is the layer that plans the whole comparison, runs it, inspects the intermediate output and documents the reasoning. That is what we call agentic analytics for researchers, and it is why we think it is becoming a must-have layer in the modern research toolkit, next to those tools rather than instead of them.
In PlotStudio AI, Plan Mode lets you review and modify the proposed approach, including the methods and assumptions, before anything runs. Domain Skills can encode your group’s conventions, such as always reporting FE, RE and within-between estimates side by side. The code, statistics and charts stay available as Analysis Pages, notebooks and PDF reports, so the Hausman test result sits next to the reasoning that justified it.
The test result is one number. The defensible part of your analysis is the method justification around it.
Aymen
Run the comparison with PlotStudio AI
PlotStudio AI is agentic analytics software for researchers: you connect tabular data, define the objective, and specialized agents plan the investigation, write and run real code in Python or R, and synthesize the results into a reproducible analysis. Analyses can run locally on your machine, which suits work with patient or other GDPR special category data that should not be uploaded to cloud tools.

There is a free trial with no published price. Paid plans listed on our pricing page are Managed Credits at $69.99 per month and Bring Your Own Key at $39.99 per month. The academic page lists Bring Your Own Key at $399.90 per year. Labs that want a managed rollout can see the enterprise page, which lists a $500 one-off pilot fee.
FAQ
Is a fixed effect the same as a covariate?
Not exactly. In mixed-model language, any predictor with a population-level coefficient is a fixed effect, so covariates are fixed effects there. In panel regression, “fixed effects” usually means unit-specific intercepts that absorb everything constant about each unit.
Can I use random effects if the Hausman test is significant?
Only with care. A significant test suggests RE estimates may be biased by correlation between unit effects and regressors. A within-between random-effects specification lets you keep random intercepts while recovering the within-unit estimate.
What if the Hausman test is not significant?
It means you could not reject the RE assumption, not that the assumption holds. RE is then reasonable for efficiency and for time-invariant predictors, but confirm with robust standard errors and by comparing it with FE.
Which should I use for longitudinal clinical data?
It depends on the question. For how a patient’s outcome changes with their own exposure, FE or the within part of a within-between model fits. For differences between patients or sites, or to generalize to a wider population, a mixed model with random intercepts is the usual route.
Sources
- Fixed and random effects models: making an informed choice (Bell, Fairbrother and Jones, 2018)
- Explaining Fixed Effects: Random Effects Modeling of Time-Series Cross-Sectional and Panel Data
- Bridging Methodological Divides Between Macro- and Microresearch
- Understanding, Choosing, and Unifying Multilevel and Fixed Effect Approaches
- Mixed-Effects Models, MathWorks documentation
- Mixed Models, chapter 15
- Correlation structures in longitudinal data analysis, Duke core guide
- One-way error component models. Hausman test.
- Fixed-effects and Random-effects, Panel Data Using R
- The Hausman Test: Fixed vs. Random Effects