BCompare groups · Guide test 280
Knapp–Hartung meta regression tests
Use adjusted uncertainty and t or F reference distributions for meta analytic mean effects or moderators.
Do it in CodeSplash
In the app, set it up in Analyze with one of these methods:
- Meta-analysis (pool studies, heterogeneity) — What is the average effect across studies, and how much do the studies' true effects differ?
- Meta-regression (moderators of study effects) — Do study characteristics explain why the studies' effects differ?
In Influence and sensitivity of a meta-analysis, choose Inference = Knapp–Hartung t. In Meta-analysis (pool studies, heterogeneity), choose Inference = Knapp–Hartung t. In Meta-regression (moderators of study effects), choose Inference = Knapp–Hartung t.
Do it in CodeSplash Run this test on your own data, in Python or R.
Bench
Change the design, drag the data, move α. The statistic, its reference distribution and the verdict follow.
Bench · Knapp–Hartung test
Adds bias × SE: small studies report bigger effects.
Your data
Simulated with a known ρIf H₀ were true
- The reference: how t varies across samples when H₀ is true.
- Your statistic, from the data above.
- The p-value: the area at least as extreme as yours (p = .050).
- The hatched rejection region at α = .050: statistics landing here reject H₀.
How the studies combine
Boxes scale with the random-effects weight. The Knapp–Hartung interval rescales the SE by the observed spread q and uses t(k − 1), so it is usually wider than the Wald interval with few studies.
The formula
With your numbers
- random-effects weights with REML τ²
- the observed spread relative to the weights; it rescales the SE
- the reference, wider than the normal with few studies
The verdict
t(9) = 2.26, p = .050, μ̂ = 0.32
p > α = .050: compatible with H₀
Effect size: pooled effect (REML) μ̂ = 0.316
Holds its level far better than the Wald z with few or heterogeneous studies. With very few studies q can fall below 1 and shrink the interval; the modified version caps it at 1.
- Statistic
- 2.259
- p-value
- 0.0502
Knapp–Hartung test on 10 (x, y) pairs: t(9) = 2.26, p = .050, μ̂ = 0.32. The p-value is above α = .050, so the data are compatible with H₀.
Question and hypotheses
H0: a meta-analytic mean effect or moderator coefficient equals its specified value.
Assumptions
Independent studies; correctly specified meta-regression, suitable within-study variances and heterogeneity estimate; enough studies relative to parameters.
Formula
Parameters and notation
wi=1/(vi+τ̂²) in random effects; k studies,p coefficients. Modified variants replace q by max(1,q).
Structure of the method
Fit a weighted random-effects meta-regression, estimate residual dispersion relative to k−p degrees of freedom, and multiply the coefficient covariance by that factor. Individual coefficients use a t reference; a specified coefficient set uses a corresponding joint F test. This modifies inference around a fitted model.
Estimated and nuisance parameters
Estimated quantities include regression coefficients, between-study heterogeneity τ², residual scaling q and their model-based covariance. The user chooses the moderator design and heterogeneity estimator. q is a data-derived uncertainty adjustment, not a neural learning rate or freely optimized regularizer.
Settings and design choices
State original Knapp–Hartung versus a modified form that prevents q below one. Select moderators, tau estimator, contrast and alpha in advance. The baseline test="knha" invokes the package’s stated adjustment; it should not be relabeled as a publication-bias diagnostic or an automatic small-sample guarantee.
Fitting and adaptation
Refit the meta-regression when studies or moderators change, retaining adequate residual degrees of freedom. Assess different scientifically justified tau estimators and influential studies as sensitivity analyses. Selecting moderators to minimize the adjusted p value still requires accounting for selection.
Sensitivity and robustness
Very small k, many moderators, leverage, uncertain within-study variances and heterogeneity near its boundary can make inference unstable. Original q<1 can produce narrower intervals than unadjusted Wald inference; modified procedures behave differently. Report coefficient estimates, confidence intervals, residual degrees of freedom and the exact adjustment variant.
How to use and calibrate
Use tk−p for individual coefficients or the corresponding joint F test; state original versus modified adjustment.
Example application
Test a random-effects meta-analysis mean while accounting better for estimated uncertainty.
Interpretation and pitfalls
Watch out
Very few studies still give fragile inference. Knapp–Hartung is an inference adjustment, not a test for publication bias.
What changed in edition 2
- New sections: structure of the method, estimated and nuisance parameters, settings and design choices, fitting and adaptation, sensitivity and robustness.
Python and R
yi are study effect estimates on one common scale and vi their sampling variances. Egger/Begg assess small-study asymmetry, not proof of publication bias; power is limited with few studies.
Not run — Executed end to end through Rscript · needs Python standard library + Rscript; R packages: metafor
# Python launcher for the complete R implementation below.
# Requires Rscript on PATH and the listed R packages.
import shutil
import subprocess
rscript = shutil.which("Rscript")
if rscript is None:
raise RuntimeError("Install R and make Rscript available on PATH.")
r_code = r"""
set.seed(2026)
d<-data.frame(yi=rnorm(12,.2,.2),vi=runif(12,.02,.08),moderator=seq_len(12));fit<-metafor::rma(yi,vi,data=d,method="REML")
print(metafor::rma(yi,vi,mods=~moderator,data=d,method="REML",test="knha"))
"""
# No shell interpolation. A failed R execution raises an error in Python.
result = subprocess.run([rscript, "--vanilla", "-"], input=r_code,
text=True, capture_output=True)
print(result.stdout)
if result.stderr:
print(result.stderr)
result.check_returncode()
Validated — Executed successfully in the validation environment · needs metafor
set.seed(2026)
d<-data.frame(yi=rnorm(12,.2,.2),vi=runif(12,.02,.08),moderator=seq_len(12));fit<-metafor::rma(yi,vi,data=d,method="REML")
print(metafor::rma(yi,vi,mods=~moderator,data=d,method="REML",test="knha"))
Output
Mixed-Effects Model (k = 12; tau^2 estimator: REML)
tau^2 (estimated amount of residual heterogeneity): 0 (SE = 0.0156)
tau (square root of estimated tau^2 value): 0
I^2 (residual heterogeneity / unaccounted variability): 0.00%
H^2 (unaccounted variability / sampling variability): 1.00
R^2 (amount of heterogeneity accounted for): 0.00%
Test for Residual Heterogeneity:
QE(df = 10) = 5.3726, p-val = 0.8649
Test of Moderators (coefficient 2):
F(df1 = 1, df2 = 10) = 0.2928, p-val = 0.6003
Model Results:
estimate se tval df pval ci.lb ci.ub
intrcpt 0.1268 0.0863 1.4697 10 0.1724 -0.0654 0.3190
moderator -0.0065 0.0120 -0.5411 10 0.6003 -0.0333 0.0203
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1Sources
- metafor meta analysis methodswviechtb.github.io
- rma.uniwviechtb.github.io
- rmasearch.r-project.org
- Statistics guide v4 (historical):
- Python: Executed end to end through Rscript · R: Executed successfully in the validation environment
- Reference's record:
- Edition 2 review: Python: skip · R: not executed (Rscript unavailable); why not run: Python: Python-to-R bridge; Rscript is unavailable. R code was not executed. Python: Not run in the reference's review: Python-to-R bridge; Rscript is unavailable. R code was not executed. R: Reviewed but not run: R wasn't available to the reference's authors.
From the CodeSplash statistics guide (v4), entry 280, updated from the reference's edition 2 (reviewed 14 November 2026) as STAT280.