linearmodels.panel.model.RandomEffects.from_formula

classmethod RandomEffects.from_formula(formula: str, data: PanelData | ndarray | DataArray | DataFrame | Series, *, weights: PanelData | ndarray | DataArray | DataFrame | Series | list[Any] | tuple[Any, ...] | None = None, check_rank: bool = True) → RandomEffects[source]

Create a model from a formula.

Parameters:
formula: str

Formula to transform into model. Conforms to formulaic formula rules.

data: PanelData | ndarray | DataArray | DataFrame | Series

Data structure that can be coerced into a PanelData. In most cases, this should be a multi-index DataFrame where the level 0 index contains the entities and the level 1 contains the time. A list or a tuple raises a TypeError that names data.

weights: PanelData | ndarray | DataArray | DataFrame | Series | list[Any] | tuple[Any, ...] | None = None

Weights to use in estimation. Assumes the variance of the residual is proportional to the inverse of the weight, so that the residual times the square root of the weight is homoskedastic. The weights must be strictly positive and finite. They are rescaled to have a mean of 1. A NaN weight is missing, and its observation is dropped.

check_rank: bool = True

Flag indicating whether to perform a rank check on the exogenous variables to ensure that the model is identified. Skipping this check can reduce the time required to validate a model specification. Results may be numerically unstable if this check is skipped and the matrix is not full rank. The default is True.

Returns:

Model specified using the formula.

Return type:

linearmodels.panel.model.RandomEffects

Notes

Unlike standard formula syntax, it is necessary to explicitly include a constant using the constant indicator (1)

Examples

>>> from linearmodels import RandomEffects
>>> from linearmodels.panel import generate_panel_data
>>> panel_data = generate_panel_data()
>>> mod = RandomEffects.from_formula("y ~ 1 + x1", panel_data.data)
>>> res = mod.fit()