anderson_rubin¶
- class weak_instruments.anderson_rubin.ARTestResult(ar_stat: float, p_val: float)¶
Bases:
object
Stores results for the Anderson-Rubin (AR) test.
- ar_stat¶
The Anderson-Rubin test statistic.
- Type:
float
- p_val¶
The p-value for the test statistic.
- Type:
float
- summary()¶
Prints a summary of the Anderson-Rubin test results in a tabular format.
- __getitem__(key)¶
Allows dictionary-like access to ARTestResult attributes.
- __repr__()¶
Returns a string representation of the ARTestResult object.
- summary()¶
Prints a summary of the Anderson-Rubin test results in a tabular format.
- weak_instruments.anderson_rubin.ar_test(Y: ndarray, X: ndarray, Z: ndarray, b: ndarray, talk: bool = False) ARTestResult ¶
Calculates the Jackknife Anderson-Rubin (AR) test with cross-fit variance as described in Mikusheva and Sun (2022).
- Parameters:
Y (np.ndarray) – A 1-D numpy array of the dependent variable (N,).
X (np.ndarray) – A 2-D numpy array of the endogenous regressors (N, L).
Z (np.ndarray) – A 2-D numpy array of the instruments (N, K), where K > L.
b (np.ndarray) – A 1-D numpy array of the parameter values to test (L,).
talk (bool, optional) – If True, provides detailed output for debugging purposes. Default is False.
- Returns:
- An object containing the following attributes:
ar_stat (float): The Anderson-Rubin test statistic.
p_val (float): The p-value for the test statistic.
- Return type:
- Raises:
ValueError – If the dimensions of Y, X, Z, or b are inconsistent or invalid.
Notes
The Anderson-Rubin test is a robust inference method for instrumental variables models, particularly in the presence of many or weak instruments.
This implementation uses a jackknife approach with cross-fit variance estimation as recommended by Mikusheva and Sun (2022).
The function computes the AR test statistic and its p-value under the null hypothesis that the parameter vector b is the true value.
The test is robust to weak identification and is valid even when the number of instruments is large relative to the sample size.
Example
>>> import numpy as np >>> from weak_instruments.anderson_rubin import ar_test >>> Y = np.array([1, 2, 3]) >>> X = np.array([[1], [2], [3]]) >>> Z = np.array([[1, 0], [0, 1], [1, 1]]) >>> b = np.array([0.5]) >>> result = ar_test(Y, X, Z, b) >>> print(result)