Spatial econometric regression models for analyzing geographically-related data interactions.
Overall
score
87%
Spatial regression models allowing parameters to vary across regimes, with options for separate or joint estimation and extensive regime-specific diagnostics.
class GM_Error_Het_Regimes:
def __init__(self, y, x, regimes, w, constant_regi='many', cols2regi='all',
regime_err_sep=False, regime_lag_sep=False, cores=False,
max_iter=1, epsilon=0.0000001, step1c=False,
inv_method='power_exp', hard_bound=False, vm=False,
name_y=None, name_x=None, name_regimes=None, name_w=None,
name_ds=None, latex=False):
"""
GMM spatial error model with regimes and heteroskedasticity.
Parameters:
- y (array): nx1 dependent variable
- x (array): nxk independent variables
- regimes (list/Series): Regime identifier for each observation
- w (sparse matrix): Spatial weights matrix
- constant_regi (str): 'one' (same constant) or 'many' (different per regime)
- cols2regi (str/list): Variables that vary by regime ('all' or list)
- regime_err_sep (bool): Separate error variance by regime
- regime_lag_sep (bool): Separate spatial parameter by regime
- cores (bool): Use multiprocessing for regime estimation
Attributes:
- regimes_set (set): Unique regime values
- kr (int): Number of regimized variables
- nr (int): Number of regimes
- multi (dict): Individual regime results (if regime_err_sep=True)
- chow (dict): Chow test for regime differences
"""
class GM_Error_Hom_Regimes:
def __init__(self, y, x, regimes, w, constant_regi='many', cols2regi='all',
regime_err_sep=False, regime_lag_sep=False, cores=False,
hard_bound=False, vm=False, name_y=None, name_x=None,
name_regimes=None, name_w=None, name_ds=None, latex=False):
"""GMM spatial error model with regimes assuming homoskedasticity."""import numpy as np
import spreg
from libpysal import weights
# Data with regimes
n = 150
x = np.random.randn(n, 2)
y = np.random.randn(n, 1)
regimes = np.random.choice(['North', 'South', 'East'], n)
w = weights.KNN.from_array(np.random.randn(n, 2), k=5)
# Spatial error model with regimes
regime_model = spreg.GM_Error_Het_Regimes(y, x, regimes, w.sparse,
constant_regi='many', cols2regi='all',
name_y='y', name_x=['x1', 'x2'],
name_regimes='region')
print(regime_model.summary)
print(f"Number of regimes: {regime_model.nr}")
print("Chow test for regime differences:", regime_model.chow)Install with Tessl CLI
npx tessl i tessl/pypi-spregdocs
evals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10