Skip to content

Panels as mixed models: Breusch–Pagan LM, Hausman and Mundlak

A panel is clustered data with a clock. Random effects are a random-intercept model, fixed effects remove the units, and three tests tell you whether unit effects exist and whether they're tangled with your predictor.

Advanced ~13 min11 steps

What runs in CodeSplash

You will be able to

  • Connect panel random effects to a random-intercept model
  • Test for unit effects with Breusch–Pagan LM, Honda and the F test
  • Read theta as the amount of partial demeaning
  • Use Hausman and Mundlak tests to judge random against fixed effects

Read first

01

Clustered data with a clock

Read

A panel follows the same units over time: firms by year, regions by quarter. It's the data you've met in this track, but the question usually changes. You want to know what happens when a unit's own predictor moves.

You now have two tools you already know, under new names:

  • Random effectsRandom effectsA panel model that treats unit differences as noise unrelated to the regressors, which gives more precise estimates when that holds. give each unit an intercept drawn from a distribution. That's a random-intercept model.
  • Fixed effectsFixed effectsA panel model that compares each unit with itself, removing everything constant within a unit, measured or not. give each unit its own free intercept. That's no pooling.

The Causal track's panel lesson asks what these designs can claim. This one is about the tests.

02

Where is the variation?

Predict

Predict first

Grunfeld's data follow 10 large firms over 20 years. How much of the variation in a firm's market value do you expect to be within firms, over time?

Under 10%About halfOver 90%
Reveal

6.7%. Big firms stay big, so nearly all the variation is between firms. Fixed effects use only the within part, so here they throw away most of the variation in the predictor. The within-between chart on the card shows this split.

03

Do unit effects exist?

Read

First ask whether units differ at all. If they don't, pooled least squares is fine.

The Breusch–Pagan LM testBreusch–Pagan LM test for panel effectsAsks whether pooled OLS residuals of one unit move together, which would mean unit effects exist. Honda and King–Wu are its one-sided forms. uses pooled residuals, and asks whether residuals within a unit are correlated: H0H_0: σu2=0\sigma^2_u = 0. A variance can't be negative, so Honda's version tests the same thing one-sided.

TestGrunfeld
Breusch–Pagan LMχ2\chi^2 = 798.2, p < .001
Hondazz = 28.3, p < .001
F test of unit effectsFF = 49.2, p < .001

Firms differ, so pooled least squares is out.

Don't confuse this test with the Breusch–Pagan LM test for cross-sectional dependence, which squares the correlations between units' residuals: LM=T∑i<jρ^ij2LM = T\sum_{i<j}\hat\rho_{ij}^2, with N(N−1)/2N(N-1)/2 degrees of freedom. On Grunfeld it gives p < .001 on 45 df: errors move together across firms, which is a question for the standard errors, not for pooling.

04

Random effects are partial pooling

Read

Random effects subtract only part of each unit's mean:

yit−θ yˉi=β (xit−θ xˉi)+…y_{it} - \theta\,\bar y_i = \beta\,(x_{it} - \theta\,\bar x_i) + \dots

At θ=0\theta = 0 you get pooled least squares, and at θ=1\theta = 1 you get fixed effects. So θ\theta is a pooling dial. The data set it from the variance between units and the variance within them.

For Grunfeld, θ\theta = 0.861, closer to fixed effects. The estimates agree to three decimals: 0.110 for random effects, and 0.110 for fixed.

05

Feel the dial

Explore

DExplorable · Partial pooling

How can small groups borrow strength from the rest of the data?

Which estimate gets closest to the truth?

How sure?
15
0.50
1.50
each group alonepartial poolingone mean

Thicker lines are larger groups: they move little. Small groups shrink the most toward the overall mean.

Commit your prediction above to see the result

Make your prediction first; the figure appears when you commit.

Make your prediction to see the result.

This is the same blend as θ\theta. Raise True spread between groups, or reduce Noise within groups, and each group keeps more of its own information. That's θ\theta moving toward 1.

06

When random effects go wrong

Predict

The price of random effects is one assumption: unit effects are unrelated to the predictors. The Hausman testHausman testCompares fixed and random effects estimates; a large gap suggests unit differences track the regressors, so random effects are biased. checks it by comparing the two sets of estimates.

Predict first

In a simulated panel, regions with higher doses have higher unit effects by design. In Grunfeld, the two estimates nearly match. On which do you expect Hausman to reject?

GrunfeldThe simulated panelBothNeither
Reveal

On the simulated panel: χ2\chi^2(1) = 96.4, p < .001. For Grunfeld: χ2\chi^2(2) = 2.33, p = .312.

07

The same question with a mixed model

Read

The Mundlak testMundlak testAdds each regressor's unit mean to a pooled regression and tests them; nonzero means unit differences are related to the regressors. adds each unit's mean predictor to a random-effects model:

yit=βxit+γxˉi+ui+εity_{it} = \beta x_{it} + \gamma \bar x_i + u_i + \varepsilon_{it}

If γ=0\gamma = 0, unit effects aren't tied to the predictor. If it isn't, β\beta is the within-unit effect, and γ\gamma is how far the between-unit slope differs from it. In mixed-model papers, this is often called the within-between model.

It also works with clustered errors, where classic Hausman doesn't. Grunfeld: FF = 1.72, p = .233, a less comfortable answer than Hausman's. Simulated: p < .001.

08

What would you lose?

Reflect

Fixed effects can't estimate anything that never changes within a unit, such as a firm's founding country. Mundlak's model can keep those predictors, while still using within-unit change for the rest.

What's your main predictor: does it change within units, or differ between them? Would a mean-of-predictor term answer your question better than either model alone?

09

Check your understanding

Checkpoint

Check yourself

Breusch–Pagan LM gives p < .001. What does it tell you?

Show the answer

Answer: a

It tests whether the variance of unit effects is zero. It says nothing about which of fixed or random effects to prefer, and it isn't the Breusch–Pagan heteroskedasticity test, despite the name.

Check yourself

A random-effects fit reports θ\theta close to 0. What's going on?

Show the answer

Answer: b

θ\theta near 0 subtracts almost none of each unit's mean. θ\theta near 1 subtracts nearly all of it, which is fixed effects.

Check yourself

Hausman rejects. Which model does that speak against?

Show the answer

Answer: b

Fixed effects don't need that assumption. Rejecting says the random-effects estimates are probably biased, under this test's assumptions.

Check yourself

Why might you prefer Mundlak's form to Hausman's test?

Show the answer

Answer: a

It estimates the same contrast as a regression term. It handles only unit-level effects tied to the predictors, not confounders that change over time.

10

Fit a panel

In the app

Set Outcome, Treatment, Unit and Time, then choose Model. Every run reports all of these tests, whichever model you choose. The Causal studio's panel design uses the same method.

Python
import pandas as pd
from linearmodels.panel import PanelOLS, RandomEffects, compare

df = pd.read_csv("panel_grunfeld.csv").set_index(["firm", "year"])

fe = PanelOLS.from_formula("inv ~ value + capital + EntityEffects", df).fit()
re = RandomEffects.from_formula("inv ~ 1 + value + capital", df).fit()
print(compare({"FE": fe, "RE": re}))
print("theta:", re.theta.mean().iloc[0])
print(fe.f_pooled)  # F test of unit effects
R
library(plm)

df <- read.csv("panel_grunfeld.csv")
pdf <- pdata.frame(df, index = c("firm", "year"))

fe <- plm(inv ~ value + capital, data = pdf, model = "within")
re <- plm(inv ~ value + capital, data = pdf, model = "random")
pooled <- plm(inv ~ value + capital, data = pdf, model = "pooling")

plmtest(pooled, type = "bp")     # Breusch-Pagan LM
plmtest(pooled, type = "honda")  # Honda
pFtest(fe, pooled)               # F test of unit effects
phtest(fe, re)                   # Hausman
11

Recap

Recap
  • Random effects are a random-intercept model, and fixed effects are no pooling.
  • Breusch–Pagan LM and Honda ask whether unit effects exist at all.
  • θ\theta is a pooling dial between pooled least squares and fixed effects.
  • Hausman and Mundlak ask whether unit effects are tied to the predictors. A large p-value doesn't settle it.

Concepts in this lesson