lagrange_multiplier

class weak_instruments.lagrange_multiplier.LMTestResult(lm_stat: float, p_val: float)

Bases: object

Stores results for the Jackknife Lagrange Multiplier (LM) test.

lm_stat

The LM test statistic.

Type:

float

p_val

The p-value for the test statistic.

Type:

float

summary()

Prints a summary of the LM test results in a tabular format.

__getitem__(key)

Allows dictionary-like access to LMTestResult attributes.

__repr__()

Returns a string representation of the LMTestResult object.

summary()

Prints a summary of the LM test results in a tabular format.

weak_instruments.lagrange_multiplier.lm_test(Y: ndarray, X: ndarray, Z: ndarray, b: ndarray, talk: bool = False) LMTestResult

Calculates the Jackknife Lagrange Multiplier (LM) test for weak instrument robust inference.

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:
  • lm_stat (float): The LM test statistic.

  • p_val (float): The p-value for the test statistic.

Return type:

LMTestResult

Raises:

ValueError – If the dimensions of Y, X, Z, or b are inconsistent or invalid.

Notes

  • The LM 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 for variance estimation.

  • The function computes the LM 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.lagrange_multiplier import lm_test
>>> Y = np.random.randn(100)
>>> X = np.random.randn(100, 1)
>>> Z = np.random.randn(100, 2)
>>> b = np.array([0.5])
>>> result = lm_test(Y, X, Z, b)
>>> result.summary()