linearmodels.iv.absorbing.AbsorbingLSResults.wald_test

AbsorbingLSResults.wald_test(restriction: DataFrame | ndarray | None = None, value: Series | ndarray | None = None, *, formula: str | list[str] | dict[str, float] | None = None) → WaldTestStatistic

Test linear equality constraints using a Wald test.

Parameters:
restriction: DataFrame | ndarray | None = None

Array with q rows and nvar columns containing linear weights to apply to parameters when forming the restrictions. It is not possible to use both restriction and formula.

value: Series | ndarray | None = None

Array with q elements containing the restricted values. The default is zeros.

formula: str | list[str] | dict[str, float] | None = None

Linear constraints in the formulaic syntax. The simplest formats are one of:

  • A single comma-separated string such as “x1=0, x2+x3=1”

  • A list of strings where each element is a single constraint such as [“x1=0”, “x2+x3=1”]

  • A single string without commas to test simple constraints such as “x1=x2=x3=0”

  • A dictionary where each key is a parameter restriction and the corresponding value is the restriction value, e.g., {“x1”: 0, “x2+x3”: 1}.

It is not possible to use both restriction and formula. The names in the restrictions are the entries of the index of params. A name that is not valid Python, for example one that contains : or [ such as exper:black, must be enclosed in back-ticks, e.g., "`exper:black` = 0".

Returns:

Test statistic for null that restrictions are valid.

Return type:

linearmodels.shared.hypotheses.WaldTestStatistic

Raises:

ValueError – If both restriction and formula are provided.

Notes

Hypothesis test examines whether \(H_0:C\theta=v\) where the matrix C is restriction and v is value. The test statistic has a \(\chi^2_q\) distribution where q is the number of rows in C.

Examples

>>> import numpy as np
>>> from linearmodels.datasets import wage
>>> from linearmodels.iv import IV2SLS
>>> data = wage.load()
>>> formula = "np.log(wage) ~ 1 + exper + I(exper**2) + brthord + [educ ~ sibs]"
>>> res = IV2SLS.from_formula(formula, data).fit()

Testing the experience is not needed in the model

>>> restriction = np.array([[0, 1, 0, 0, 0],
...                         [0, 0, 1, 0, 0]])
>>> value = np.array([0, 0])
>>> wald_res = res.wald_test(restriction, value)

Using the formula interface to test the same restrictions. The names are those in the index of params, which has I(exper ** 2)

>>> formula = "exper = I(exper ** 2) = 0"
>>> wald_res = res.wald_test(formula=formula)

Using the formula interface with a list

>>> wald_res = res.wald_test(formula=["exper = 0", "I(exper ** 2) = 0"])

A name that is not valid Python, such as an interaction, is enclosed in back-ticks

>>> formula = "np.log(wage) ~ 1 + exper + black + exper:black + [educ ~ sibs]"
>>> res = IV2SLS.from_formula(formula, data).fit()
>>> wald_res = res.wald_test(formula="`exper:black` = 0")