Skip to content

DPredict · Guide test 186

Anderson–Rubin test

Tests instrumental variable coefficient restrictions with validity that can survive weak instrument identification.

Runs in CodeSplashPython (calls R) example not runR example validated

Do it in CodeSplash

In the app, set it up in Analyze with this method:

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 · Anderson–Rubin test

200
0.30
0.50

0 makes x exogenous: OLS and 2SLS estimate the same thing.

0.70
0.00

Not 0: z₂ violates the exclusion restriction (an invalid instrument).

0.00

H₀: β = β₀. The test stays valid however weak the instruments are.

0.050

Your data

Simulated with known truth
—— first stage, slope 0.18—— OLS 1.21– – IV 0.86

Left: how strongly the instruments move x (a flat line means weak instruments). Right: OLS and the instrumented slope; they part when x is endogenous.

If H₀ were true

F = 2.93
  1. The reference: how F varies across samples when H₀ is true.
  2. Your statistic, from the data above.
  3. The p-value: the area at least as extreme as yours (p = .056).
  4. The hatched rejection region at α = .050: statistics landing here reject H₀.

The formula

F(β0)=(y−β0x)⊤PZ(y−β0x)/L(y−β0x)⊤MZ(y−β0x)/(n−L−1)F(\beta_0) = \dfrac{(y-\beta_0x)^{\top}\mathbf P_Z(y-\beta_0x)/L}{(y-\beta_0x)^{\top}\mathbf M_Z(y-\beta_0x)/(n-L-1)}

With your numbers

β0=0,F=2.93 on (2,197) df\beta_0 = 0,\qquad F = 2.93\ \text{on}\ (2, 197)\ df
PZ\mathbf P_Z
projection on the (centered) instruments
y−β0xy - \beta_0 x
the outcome with the hypothesized effect removed

The verdict

F(2, 197) = 2.93, p = .056

p > α = .050: compatible with H₀

Under H0 the instruments cannot predict y − β0x. Inverting the test over β0 gives a confidence set that stays valid with weak instruments (it may be unbounded).

Statistic
2.926
p-value
0.0559
Anderson–Rubin test on 200 observations: outcome y, regressor x, instruments z1 and z2: F(2, 197) = 2.93, p = .056. The p-value is above α = .050, so the data are compatible with H0.

Anderson–Rubin test on 200 observations: outcome y, regressor x, instruments z₁ and z₂: F(2, 197) = 2.93, p = .056. The p-value is above α = .050, so the data are compatible with H₀.

Question and hypotheses

H0: the structural coefficient β on endogenous regressors equals β0.

Assumptions

Valid excluded instruments; the classical exact version uses normal homoskedastic errors and conditions on instruments. It remains valid under weak identification.

Formula

y−Xendβ0=Xexoγ+Zexclπ+uH0:π=0\begin{gathered}y-X_{end}\beta_0=X_{exo}\gamma+Z_{excl}\pi+u\\[5pt] H_0:\pi=0\end{gathered}

Parameters and notation

Test all L excluded instrument coefficients in the transformed regression; the ordinary partial F uses L numerator df and regression residual df.

Structure of the method

For each hypothesized endogenous coefficient, subtract its contribution from the outcome and regress the transformed outcome on exogenous controls and excluded instruments. Test the excluded-instrument coefficients jointly. Under the null, this regression avoids relying on a well-identified first-stage coefficient estimate, giving the method its weak-instrument robustness.

Estimated and nuisance parameters

Nuisance control coefficients and residual covariance/variance are fitted for the transformed regression. The tested structural coefficient is fixed at the null value during each test; inverting tests across null values produces a confidence set rather than a single fitted coefficient.

Settings and design choices

Prespecify valid instruments, controls, null value or inversion grid, significance level, and exact homoskedastic versus robust Wald formulation. Instrument validity remains essential. A grid must be broad and fine enough to represent disconnected or unbounded confidence regions faithfully.

Fitting and adaptation

Refit the transformed regression at every candidate null value and use its matching covariance/reference. If instrument selection or nuisance modeling is data-adaptive, include that in a justified procedure. Weak-instrument robustness does not authorize arbitrary machine-learning residualization with unchanged finite-sample F critical values.

Sensitivity and robustness

Strong rejection can coexist with poor point identification when the null is incompatible with instrument moments. Wide, disjoint, or unbounded inverted sets are meaningful uncertainty, not numerical defects to hide. Heteroskedasticity, dependence, many instruments, and invalid exclusions require the appropriate variant and interpretation; a valid weak-instrument test is not an instrument-validity test.

How to use and calibrate

Compute the F/Wald statistic for each β0; inversion yields a weak-instrument-robust confidence set.

Example application

Test a causal coefficient when instruments may be weak but their validity is defensible.

Interpretation and pitfalls

Watch out

Robust variants need appropriate covariance. Confidence sets can be wide, disjoint or unbounded; that is meaningful information.

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

Tests structural slope zero using excluded instruments, robust to weak identification under the test’s error assumptions.

Python · invokes R

Not run — Executed end to end through Rscript · needs Python standard library + Rscript; R packages: ivmodel

# 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)
n<-200;z1<-rnorm(n);z2<-rnorm(n);u<-rnorm(n);v<-rnorm(n);x<-.8*z1+.5*z2+.6*u+v;y<-1+.7*x+u;d<-data.frame(y,x,z1,z2)
fit<-ivmodel::ivmodel(Y=y,D=x,Z=cbind(z1,z2));print(ivmodel::AR.test(fit,beta0=0))
"""
# 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()
R

Validated — Executed successfully in the validation environment · needs ivmodel

set.seed(2026)
n<-200;z1<-rnorm(n);z2<-rnorm(n);u<-rnorm(n);v<-rnorm(n);x<-.8*z1+.5*z2+.6*u+v;y<-1+.7*x+u;d<-data.frame(y,x,z1,z2)
fit<-ivmodel::ivmodel(Y=y,D=x,Z=cbind(z1,z2));print(ivmodel::AR.test(fit,beta0=0))
Output
$Fstat
[1] 11.04844

$df
[1]   2 197

$p.value
[1] 2.833072e-05

$ci.info
[1] "[0.367706001758276, 0.832763922392601]"

$ci
        lower     upper
[1,] 0.367706 0.8327639

Sources

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 186, updated from the reference's edition 2 (reviewed 14 November 2026) as STAT186.