linearmodels.panel.results.PanelResults.wald_test¶
-
PanelResults.wald_test(restriction: ndarray[tuple[int, ...], dtype[float64]] | DataFrame | None =
None, value: ndarray[tuple[int, ...], dtype[float64]] | Series | None =None, *, formula: str | list[str] | None =None) WaldTestStatistic[source]¶ Test linear equality constraints using a Wald test.
- Parameters:¶
- restriction: ndarray[tuple[int, ...], dtype[float64]] | DataFrame | 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: ndarray[tuple[int, ...], dtype[float64]] | Series | None =
None¶ Array with q elements containing the restricted values. If not provided, the restricted values are all 0.
- formula: str | list[str] | None =
None¶ Formulaic linear constraints. 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
restrictionandformula. The names in the restrictions are the entries of the index ofparams. A name that is not valid Python, for example one that contains:or[such asC(year)[T.1987]:educ, must be enclosed in back-ticks, e.g.,"`C(year)[T.1987]:educ` = 0".
- restriction: ndarray[tuple[int, ...], dtype[float64]] | DataFrame | None =
- Returns:¶
Test statistic for null that restrictions are valid.
- Return type:¶
- Raises:¶
ValueError – If the model has no parameters, e.g., a PanelOLS model that only has effects, or if both restriction and formula are provided.
Notes
Hypothesis test examines whether \(H_0:C\theta=v\) where the matrix C is
restrictionand v isvalue. The test statistic has a \(\chi^2_q\) distribution where q is the number of rows in C.Examples
>>> from linearmodels.datasets import wage_panel >>> import statsmodels.api as sm >>> import numpy as np >>> import pandas as pd >>> data = wage_panel.load() >>> year = pd.Categorical(data.year) >>> data = data.set_index(["nr", "year"]) >>> data["year"] = year >>> from linearmodels.panel import PanelOLS >>> exog_vars = ["expersq", "union", "married", "year"] >>> exog = sm.add_constant(data[exog_vars])>>> mod = PanelOLS(data.lwage, exog, entity_effects=True) >>> fe_res = mod.fit()Test the restriction that union and married have 0 coefficients
>>> restriction = np.zeros((2, 11)) >>> restriction[0, 2] = 1 >>> restriction[1, 3] = 1 >>> value = np.array([0, 0]) >>> wald_res = fe_res.wald_test(restriction, value)The same test using formulas
>>> formula = "union = married = 0" >>> wald_res = fe_res.wald_test(formula=formula)A name that is not valid Python, such as the interaction of a categorical variable with a regressor, is enclosed in back-ticks
>>> from linearmodels import PooledOLS >>> mod = PooledOLS.from_formula("lwage ~ 1 + union + C(year) * educ", data) >>> res = mod.fit(cov_type="clustered", cluster_entity=True) >>> null = "`C(year)[T.1987]:educ` = 0, `C(year)[T.1986]:educ` = 0" >>> wald_res = res.wald_test(formula=null)