Fixed-effect and random-effects models
The difference between the two models is not how conservative they are but what they assume: one asks what common effect this set of studies points to, the other asks where the average of a distribution of effects lies. How the weights get rewritten, which estimators of τ² exist, where DerSimonian-Laird goes wrong when there are few studies, and what the Knapp-Hartung adjustment actually repairs.
The two models are not asking the same question
The usual formulation is that “random effects is more conservative”. That happens to describe the outcome in most cases, but it reverses cause and effect, and it leads to the wrong operation (“heterogeneity is high, so switch models to widen the interval”). The real difference is that the two make different assumptions about the world, and therefore estimate different things.
The fixed-effect model assumes every included study is estimating the same true value :
Any apparent difference between studies is sampling error and nothing else. The question it answers is: “what is the common effect these studies point to?”
The random-effects model assumes each study has its own true value , and that those true values are themselves drawn from a distribution:
The question it answers is: “where does the average of those true effects lie?” The extra is the between-study variance.
How far apart the two are on one dataset
Both models run on metadat::dat.bcg, the same 13 BCG vaccine trials used on the previous page and on B7-04:
| Model | Pooled RR | 95% CI | Interval width (log scale) |
|---|---|---|---|
| Fixed-effect | 0.650 | 0.601–0.704 | 0.159 |
| Random-effects (REML) | 0.489 | 0.344–0.696 | 0.705 |
Two things are worth stopping on:
- The confidence interval becomes 4.4 times as wide (measured on the log scale). That is τ² = 0.313 being added to every study’s variance.
- The point estimate also moves a long way, from RR 0.650 to 0.489. This gets overlooked constantly — many people believe switching models only changes the width of the interval. It changes the point estimate too, and by how much depends on whether the large and the small studies agree with each other.
What happens to the weights
Under a fixed-effect model the weight is ; under random effects it is . Adding a constant that is the same for every study flattens the weights towards equality — the advantage a very precise study had is diluted away by τ².
figures/scripts/B7-02-fixed-random.R| Trial | Total n | Trial RR | Fixed-effect weight | Random-effects weight | Change |
|---|---|---|---|---|---|
| TPT Madras, 1980 | 176782 | 1.012 | 41.4% | 10.2% | -31.2 |
| Stein & Aronson, 1953 | 2992 | 0.456 | 23.8% | 10.1% | -13.7 |
| Comstock et al, 1974 | 77972 | 0.712 | 13.2% | 9.9% | -3.3 |
| Hart & Sutherland, 1977 | 26465 | 0.237 | 8.2% | 9.7% | +1.5 |
| Frimodt-Moller et al, 1973 | 10877 | 0.804 | 3.2% | 8.9% | +5.7 |
| Coetzee & Berjak, 1968 | 14776 | 0.625 | 2.9% | 8.7% | +5.8 |
| Comstock et al, 1976 | 34767 | 0.983 | 2.3% | 8.4% | +6.1 |
| Rosenthal et al, 1961 | 3381 | 0.254 | 2.2% | 8.4% | +6.1 |
| Ferguson & Simes, 1949 | 609 | 0.205 | 0.8% | 6.4% | +5.5 |
| Vandiviere et al, 1973 | 3174 | 0.198 | 0.7% | 6.0% | +5.3 |
| Aronson, 1948 | 262 | 0.411 | 0.5% | 5.1% | +4.6 |
| Rosenthal et al, 1960 | 451 | 0.260 | 0.4% | 4.4% | +4.0 |
| Comstock & Webster, 1969 | 4839 | 1.562 | 0.3% | 3.8% | +3.5 |
Now the previous section’s question — why did the point estimate move — has an answer. The largest trial (TPT Madras, 1980, 176782 participants) has an RR of 1.012 on its own, which is to say it detected no protective effect. Under fixed effects that single trial holds 41.4% of the weight and drags the pooled value towards 1; random effects cut it to 10.2%, and the pooled value falls back towards what the remaining trials indicate.
τ² has many estimators, and they disagree
The τ² that the random-effects model adds has to be estimated; it is not something the data hand over directly. The common estimators:
| Estimator | τ² | I² | Pooled RR | 95% CI | Note |
|---|---|---|---|---|---|
| DL | 0.3088 | 92.1% | 0.490 | 0.345–0.695 | DerSimonian-Laird, the historical default; closed form, no iteration |
| REML | 0.3132 | 92.2% | 0.489 | 0.344–0.696 | restricted maximum likelihood, the current default in metafor |
| PM | 0.3181 | 92.3% | 0.489 | 0.343–0.697 | Paule-Mandel, iterative moment estimator |
| SJ | 0.3455 | 92.9% | 0.488 | 0.338–0.704 | Sidik-Jonkman |
| ML | 0.2800 | 91.4% | 0.491 | 0.351–0.688 | maximum likelihood, known to be downward biased |
| HE | 0.3286 | 92.6% | 0.489 | 0.341–0.700 | Hedges (variance component) estimator |
On this dataset (13 studies, a lot of heterogeneity) the differences are modest, because there are enough studies. When there are few studies the differences start to matter.
Where DL goes wrong when there are few studies
A simulation makes it visible: the true τ² is fixed at the value estimated from the BCG data (0.313), each study’s within-study variance is resampled from the 13 variances actually observed there, only the number of studies changes, and each scenario is run 1500 times.
figures/scripts/B7-02-fixed-random.R| Number of studies k | Mean τ² | Median τ² | Proportion estimated as τ² = 0 | ||||||
|---|---|---|---|---|---|---|---|---|---|
| DL | REML | PM | DL | REML | PM | DL | REML | PM | |
| 5 | 0.315 | 0.317 | 0.325 | 0.206 | 0.241 | 0.244 | 6.8% | 4.6% | 6.8% |
| 10 | 0.291 | 0.299 | 0.307 | 0.235 | 0.269 | 0.273 | 0.5% | 0.3% | 0.5% |
| 30 | 0.314 | 0.314 | 0.316 | 0.285 | 0.299 | 0.304 | 0.0% | 0.0% | 0.0% |
Means are pulled around by a handful of extreme estimates, so the paragraph below describes the median, which is closer to what a single meta-analysis typically obtains; the zero-estimate column shows that all three methods can conclude there is no heterogeneity at all.
The true value is 0.313. At = 5, DL’s typical estimate is only 0.206 — an underestimate of about 34% — against 0.241 for REML and 0.244 for PM. And DL returns τ² = 0 outright 6.8% of the time, announcing that there is no heterogeneity between these studies — in a world where the true τ² is plainly not small.
The direct consequence of underestimating τ² is a confidence interval that is too narrow, since is added to every study’s variance. That is what the next section repairs.
What the Knapp-Hartung adjustment repairs
The standard random-effects confidence interval uses a normal quantile (1.96) and treats the estimated as if it were the true value. When is small and is itself unstable, both of those make the interval too narrow.
The Knapp-Hartung adjustment (also called Hartung-Knapp-Sidik-Jonkman, HKSJ) does two things: it replaces the normal quantile with a quantile on degrees of freedom, and it uses a variance estimator that absorbs some of the uncertainty in .
On the same BCG data, each estimator with and without KH:
| Estimator | Standard 95% CI | With Knapp-Hartung | Widening |
|---|---|---|---|
| DL | 0.345–0.695 | 0.330–0.726 | +12.4% |
| REML | 0.344–0.696 | 0.330–0.726 | +11.8% |
| PM | 0.343–0.697 | 0.330–0.726 | +11.2% |
| SJ | 0.338–0.704 | 0.329–0.725 | +7.8% |
| ML | 0.351–0.688 | 0.332–0.727 | +16.4% |
| HE | 0.341–0.700 | 0.329–0.725 | +9.8% |
With 13 studies the widening is around a tenth, which does not look like much. What KH rescues becomes obvious with fewer studies — the same simulation, now looking at how often the interval actually covers the true value:
| Number of studies k | Coverage, DL standard interval | DL + Knapp-Hartung |
|---|---|---|
| 5 | 85.7% | 93.4% |
| 10 | 89.5% | 94.3% |
| 30 | 93.1% | 95.0% |
At = 5, a nominally 95% interval covers the truth only 85.7% of the time; adding Knapp-Hartung brings it back to 93.4%. Put another way, a meta-analysis of five studies reporting a standard DL interval is reporting something closer to a 86% interval than a 95% one.
So which one should you choose
| Situation | Recommendation | Reason |
|---|---|---|
| Studies are clinically very similar (same drug, same population, same outcome definition) | Fixed-effect is defensible | The “common effect” assumption has some basis in reality |
| Most clinical meta-analyses | Random effects + Knapp-Hartung, τ² by REML or PM | Populations, doses and follow-up lengths are never identical |
| Very few studies (fewer than five) | Random effects, but τ² is essentially unestimable — say so among the limitations | τ² is wildly unstable here, and no model can support a strong conclusion |
| Only two or three studies | Consider not pooling at all and writing a narrative synthesis instead | An unestimable τ² plus a distribution whose shape cannot be seen leaves the pooled value with little meaning |
| You want to know where the next study will land | Neither model is enough; you need a prediction interval | See the heterogeneity page |
Run it yourself
library(metafor)
library(metadat)
data(dat.bcg, package = "metadat")
d <- escalc(measure = "RR", ai = tpos, bi = tneg, ci = cpos, di = cneg,
data = dat.bcg, slab = paste(author, year, sep = ", "))
fe <- rma(yi, vi, data = d, method = "FE") # fixed-effect
re <- rma(yi, vi, data = d, method = "REML") # random-effects (today's default)
fe; re
# What happens to the weights -- this is where the third section's table comes from
# slab does not become a column of d (d$slab is NULL); it travels as the
# names of weights().
data.frame(study = names(weights(fe)),
fixed = round(weights(fe), 1),
random = round(weights(re), 1))
# Swap the tau^2 estimator and watch the pooled value and interval move
for (m in c("DL", "REML", "PM", "SJ", "ML", "HE")) {
r <- rma(yi, vi, data = d, method = m)
cat(sprintf("%-5s tau2=%.4f RR=%.3f (%.3f-%.3f)\n",
m, r$tau2, exp(r$beta), exp(r$ci.lb), exp(r$ci.ub)))
}
# Knapp-Hartung: a t distribution, plus the uncertainty in tau^2
rma(yi, vi, data = d, method = "REML", test = "knha")
# The meta package does the same thing (its output is closer to a journal table)
# library(meta)
# metabin(tpos, tpos + tneg, cpos, cpos + cneg, data = dat.bcg,
# sm = "RR", method.tau = "REML", hakn = TRUE)Verified with R 4.6.0, metafor 5.0.1 and metadat 1.6.0
import numpy as np
from statsmodels.stats.meta_analysis import combine_effects
# The 2x2 counts of metadat::dat.bcg, 13 trials, carried here so this
# block runs on its own.
tpos = np.array([4, 6, 3, 62, 33, 180, 8, 505, 29, 17, 186, 5, 27])
tneg = np.array([119, 300, 228, 13536, 5036, 1361, 2537, 87886, 7470, 1699,
50448, 2493, 16886])
cpos = np.array([11, 29, 11, 248, 47, 372, 10, 499, 45, 65, 141, 3, 29])
cneg = np.array([128, 274, 209, 12619, 5761, 1079, 619, 87892, 7232, 1600,
27197, 2338, 17825])
log_rr = np.log((tpos / (tpos + tneg)) / (cpos / (cpos + cneg)))
var = 1 / tpos - 1 / (tpos + tneg) + 1 / cpos - 1 / (cpos + cneg)
# Input is the log RR and variance computed just above
res = combine_effects(log_rr, var, method_re="dl")
print(res.summary_frame()) # gives both the fixed-effect and random-effects rows
# The weights are easy to compute yourself -- and they are the point of this page
w_fe = 1 / var
w_re = 1 / (var + res.tau2)
print(np.round(100 * w_fe / w_fe.sum(), 1))
print(np.round(100 * w_re / w_re.sum(), 1))
# Knapp-Hartung has to be written by hand: a t quantile plus a weighted residual sum of squares
k = len(log_rr)
mu = np.sum(w_re * log_rr) / np.sum(w_re)
q = np.sum(w_re * (log_rr - mu) ** 2) / (k - 1)
se = np.sqrt(q / np.sum(w_re))
from scipy.stats import t
lo, hi = mu - t.ppf(0.975, k - 1) * se, mu + t.ppf(0.975, k - 1) * se
print("KH CI:", np.exp(lo), np.exp(hi))statsmodels' combine_effects() offers only DL and chi2 as τ² estimators — no REML, no PM, and no Knapp-Hartung. Doing what this page does means using R.
Reading the report
In a paper, this page usually corresponds to a sentence or two in the Methods plus the line underneath the forest plot. Five things to find:
- Which model was used, and why. “Random-effects model” with no reason is normal but not ideal; no statement of the model at all is a substantive omission.
- Which estimator produced τ². If it is not stated, it is usually DL — especially in older reviews.
- Whether Knapp-Hartung was applied. It appears as “Hartung-Knapp adjustment” or “HKSJ”. Fewer than ten studies and no mention of it means you should widen that confidence interval in your head.
- Whether the model was chosen after the fact. A sentence like “because I² exceeded some value, a random-effects model was adopted” is data-driven model selection.
- Where the weight is concentrated. If one box on the forest plot is conspicuously large, remove that study and look at the conclusion again — any reader can do this, as long as the paper reports the per-study data.
Common misuses
| Misuse | Why it is wrong |
|---|---|
| Treating the difference between the models as a matter of conservatism | They estimate different quantities; the random-effects inference is in fact the broader claim |
| Looking at I² and then choosing the model | Data-driven model selection, equivalent to an uncorrected two-stage procedure |
| Believing that switching models only changes the interval width | The point estimate moves too, by an amount that depends on whether large and small studies agree |
| Answering high heterogeneity by switching to random effects and stopping there | The job is to find where the heterogeneity comes from; switching models only absorbs it |
| Ignoring that random effects amplify the influence of small studies | When small studies are poor quality or publication-biased, random effects are more easily led astray |
| Claiming τ² was estimated when there are very few studies | With small k the estimate is wildly unstable, and DL frequently returns 0 |
| Using DL without Knapp-Hartung when there are few studies | A nominal 95% interval may cover the truth only about eighty-something per cent of the time |
| Reading the random-effects pooled value as “what the next patient or the next study will get” | That is the prediction interval’s job; the pooled value is only the mean of the distribution |
| Reporting the pooled value without τ² | Without τ², the reader cannot judge how representative that average is |
| Pooling studies that are not clinically comparable | The fact that the arithmetic runs does not make that μ meaningful |
Reproducing every number on this page
/opt/homebrew/bin/Rscript figures/scripts/B7-02-fixed-random.RRead the figure
The answer comes from the same statistical output that produced this page's figures, not from a number typed in beside them.
For the same 13 BCG trials the fixed-effect pooled RR is 0.650 and the random-effects one is 0.489. Why does the point estimate move at all?
Show the answer and why
Correct answer: Because the weights are rewritten: the largest trial drops from over forty per cent to 10.19%, and since its own RR is close to 1 its pull on the pooled value towards 1 is weakened
Under fixed effects the largest trial alone carries over forty per cent of the weight, and its own RR sits close to 1. Random effects cuts it to 10.19%, the direction the remaining trials point in surfaces, and the pooled value moves from 0.650 to 0.489. It moves away from 1, not towards it, so calling the model conservative gets even the direction wrong — the interval does become 4.44 times as wide, but that is a separate fact. The 92.22% I² is the share of total variation that lies between studies: it says how large the heterogeneity is, not which way the pooled value goes. Flip the effect directions of the same trials and I² is unchanged while the pooled value moves the other way. What decides the direction is whether the large and the small trials agree.
A simulation holds the true τ² at 0.313 and varies only the number of studies. What does DerSimonian-Laird do at k = 5?
Show the answer and why
Correct answer: Its typical estimate is only 0.206, understating the between-study variance by more than a third, and an understated τ² makes the confidence interval too narrow
0.206 is the median DL estimate at k = 5 against a truth of 0.313 — more than a third too low. The mean of 0.315 looks like a bullseye, but it is a handful of extreme overestimates pulling the average back; a single meta-analysis draws once from that distribution, and the median is what it typically gets. 0.285 is the median in the row with the most studies, which runs the other way: DL creeps back towards the truth as studies accumulate, so saying trouble arrives later has the two ends reversed. Understating τ² is not an academic blemish — τ² is added to every study's variance, so too small a τ² gives too narrow an interval, and the interval is what a reader uses to judge how firm the conclusion is.
In the same simulation, nominal 95% DerSimonian-Laird random-effects intervals at k = 5 actually cover the truth 85.7% of the time. What does the Knapp-Hartung correction do here?
Show the answer and why
Correct answer: It restores coverage to 93.4% by using t quantiles and folding the uncertainty in the τ² estimate into the variance — it repairs the interval, not the point estimate
Knapp-Hartung changes how the interval is computed: t quantiles instead of normal ones, plus a variance estimator that folds in how unstable the τ² estimate itself is. Coverage at k = 5 goes from 85.7% back to 93.4%. It leaves the τ² estimator alone and never touches the point estimate. The 93.1% belongs to the uncorrected interval in the row with far more studies; crediting the correction for it merges two different facts, more studies and a different interval formula. As for the price, on this BCG data the interval widens by about 12.4% and buys agreement between nominal and actual coverage — worth it when studies are few, near-invisible when they are many, which is why the current advice is to apply it by default rather than only in small meta-analyses.
Random effects flattens the weights: the most lightly weighted trial here goes from 0.31% to 3.8%, and the heaviest comes down from 41.4%. What does that rewriting cost?
Show the answer and why
Correct answer: The studies promoted are exactly the least precise ones: this trial's RR is 1.56, pointing the opposite way from the pooled value, and its weight has been raised more than tenfold
A random-effects weight is one over the study variance plus τ², and adding the same constant to everyone compresses the differences, so the least precise studies all rise together. The most lightly weighted trial has an RR of 1.56, the opposite direction from the pooled value, and its weight is raised more than tenfold. If those low-precision studies systematically exaggerate — poor blinding, inadequate allocation concealment, selective reporting, or simply the survivors of publication bias — random effects amplifies that bias while fixed effects suffers less. The 10.19% is the largest trial's rewritten weight, nowhere near one-study-one-vote, and one-study-one-vote is not what pooling should do: it throws away the precision information. The direction matters too. 1.01 is the largest trial's own RR; flattening weakens its influence, so the pooled value moves away from 1 rather than towards it.
The fixed-effect 95% CI runs 0.601 to 0.704 and the random-effects one 0.344 to 0.696. People call random effects the more conservative model. What is imprecise about that?
Show the answer and why
Correct answer: Conservatism is a consequence, not a reason: the two models estimate different quantities, and the interval is 4.44 times as wide because one of them also estimates the spread of the effect distribution
The fixed-effect interval answers where the effect common to these trials lies; the random-effects interval answers where the mean of a distribution of effects lies. The second carries an extra τ² = 0.31, the spread of the true effects across studies, which is why it comes out 4.44 times as wide. Width follows from the assumption; it is not a dial for caution. Treating it as one leads straight to switching models because the heterogeneity is high and the interval should look wider, which is choosing the model after seeing the result. The 0.16 is the fixed-effect width on the log scale, and it is narrow not because it is more accurate but because it assumes τ² is zero — an assumption the Q test rejects emphatically here. Note also that the point estimate moved, and conservative says nothing about which way.
Six τ² estimators on the same 13 studies put the pooled RR between 0.488 and 0.491 and I² between 91% and 93%. Does that show the choice of estimator does not matter?
Show the answer and why
Correct answer: No. They agree here because there are enough studies: the highest, 0.346, is more than twenty per cent above the lowest, and with few studies that gap rewrites the interval width directly
The six estimators do sit close together on this data, but the number of studies is what holds them there. SJ gives 0.346 and ML gives 0.280, more than twenty per cent apart. τ² is added to every study variance, so a gap of that size visibly changes interval width when studies are few and their individual variances large, and interval width is what carries the conclusion. ML is known to be downward biased, which is exactly why it sits lowest; reading furthest out as therefore irrelevant treats a bias as noise. DL's 0.309 is the historical default rather than an unbiased benchmark — it is the one that falls furthest short when studies are few, and both metafor and meta have moved their defaults away from it. What belongs in a report is which estimator was used, not an assumption that they are interchangeable.
Chapters that use this method
Watch next
醫學統計 EP18 統合分析:加權整合多項研究、看懂森林圖
Systematic reviews and meta analysis
How to do your first meta-analysis from start to finishSources and licences
This page is original writing