linearmodels.system.model.SUR.from_formula

classmethod SUR.from_formula(formula: str | dict[str, str], data: DataFrame, *, sigma: ndarray | DataArray | DataFrame | Series | None = None, weights: Mapping[str, ndarray | DataArray | DataFrame | Series] | None = None) linearmodels.system.model.SUR[source]

Specify a SUR using the formula interface

Parameters:
formula: str | dict[str, str]

Either a string or a dictionary of strings where each value in the dictionary represents a single equation. See Notes for a description of the accepted syntax

data: DataFrame

Frame containing named variables

sigma: ndarray | DataArray | DataFrame | Series | None = None

Prespecified residual covariance to use in GLS estimation. If not provided, FGLS is implemented based on an estimate of sigma.

weights: Mapping[str, ndarray | DataArray | DataFrame | Series] | None = None

Dictionary like object (e.g. a DataFrame) containing variable weights. Each entry must have the same number of observations as data. If an equation label is not a key weights, the weights will be set to unity

Returns:

model – Model instance

Return type:

linearmodels.system.model.SUR

Notes

Models can be specified in one of two ways. The first uses curly braces to encapsulate equations. The second uses a dictionary where each key is an equation name.

Examples

The simplest format uses standard formulas for each equation in a dictionary. Best practice is to use an Ordered Dictionary

>>> import pandas as pd
>>> import numpy as np
>>> data = pd.DataFrame(np.random.randn(500, 4),
...                     columns=["y1", "x1_1", "y2", "x2_1"])
>>> from linearmodels.system import SUR
>>> formula = {"eq1": "y1 ~ 1 + x1_1", "eq2": "y2 ~ 1 + x2_1"}
>>> mod = SUR.from_formula(formula, data)

The second format uses curly braces {} to surround distinct equations

>>> formula = "{y1 ~ 1 + x1_1} {y2 ~ 1 + x2_1}"
>>> mod = SUR.from_formula(formula, data)

It is also possible to include equation labels when using curly braces

>>> formula = "{eq1: y1 ~ 1 + x1_1} {eq2: y2 ~ 1 + x2_1}"
>>> mod = SUR.from_formula(formula, data)