Skip to contents

Source: the reference implementation AR.test in the CRAN package ivmodel (file R/AR.r), implementing Anderson, T. W. and Rubin, H. (1949), Annals of Mathematical Statistics 20, 46-63. With temp = Y - beta0 D after the exogenous covariates have been partialled out of Y, D and Z, Fstat = ||P_Z temp||^2 / ||M_Z temp||^2 * (n - k - L)/L and p = 1 - pf(Fstat, L, n - k - L).

Usage

Ivartest(y, X, Z, beta0 = 0, X_exog = NULL, add_intercept = TRUE)

Arguments

y

Numeric outcome of length n.

X

Numeric endogenous regressor of length n.

Z

Numeric n x L matrix of instruments.

beta0

Null value of the structural coefficient. Default 0.

X_exog

Optional n x q matrix of included exogenous covariates.

add_intercept

Include an intercept. Default TRUE.

Value

list: statistic, p_value, df1, df2, beta0, n, n_instruments, method.

Examples

set.seed(1)
Z <- matrix(rnorm(120), 60, 2)
D <- Z %*% c(1, 0.5) + rnorm(60)
Ivartest(1.5 * D + rnorm(60), D, Z, 1.5)$p_value
#> [1] 0.7331542