Hausman Test
Calculate the Hausman specification test comparing a Fixed Effects and a Random Effects fit of dependent_tickers (the panel of entities) on a regressor x.
Also known as: Hausman specification test, Hausman-Wu test.
Random Effects is more efficient than Fixed Effects but relies on entity effects being uncorrelated with the regressor(s) – if that assumption is violated, Random Effects is inconsistent while Fixed Effects remains consistent regardless. See panel_data_model.get_hausman_test for the full formula and references, and get_fixed_effects/get_random_effects for how the two models being compared are estimated (including how independent_tickers/independent_column shape the panel, and why independent_column is generally the more reliable choice here).
No programming experience? With the Finance Toolkit MCP server, AI assistants such as Claude and ChatGPT can calculate the Hausman Test for you. Just ask in plain English.
Calculate the Hausman Test in Python
The Hausman Test is available in the Econometrics module of the open-source Finance Toolkit. Install it with:
pip install financetoolkit -U
Then call get_hausman_test as shown below.
from financetoolkit import Toolkit
toolkit = Toolkit(
["AAPL", "MSFT", "AMZN"], api_key="FINANCIAL_MODELING_PREP_KEY"
)
toolkit.econometrics.get_hausman_test(
independent_column="Volume", period="weekly"
)
Which returns:
| Metric | Value |
|---|---|
| Hausman Statistic | 8.1289 |
| Degrees of Freedom | 1 |
| P-Value | 0.0044 |
| Prefer Fixed Effects (5%) | 1 |
Parameters
get_hausman_test accepts the following parameters:
- independent_tickers (str | list[str] | None, optional): The factor
ticker(s), whose
columnvalues are broadcast identically to every entity at each date. Mutually exclusive withindependent_column. - independent_column (str | None, optional): A different historical data
column, taken per-entity from each of
dependent_tickers’ own data, to use as the regressor. Mutually exclusive withindependent_tickers. - dependent_tickers (str | list[str] | None, optional): The panel of
entity tickers to explain. Defaults to None, meaning every ticker in
the
Toolkitinstance (other thanindependent_tickers, if given). - period (str, optional): The data frequency (daily, weekly, monthly, quarterly, or yearly). Defaults to “daily”.
- column (str, optional): The dependent variable’s historical data column. Defaults to “Return”.
- rounding (int | None, optional): The number of decimals to round the results to. Defaults to None.
Related Panel Data
The Econometrics module page introduces the module, and the sidebar lists all of its functions.