Spatial econometric regression models for analyzing geographically-related data interactions.
Overall
score
87%
Full information maximum likelihood estimation for spatial lag and error models with analytical derivatives and concentrated log-likelihood functions.
class ML_Error:
def __init__(self, y, x, w, epsilon=0.0000001, hard_bound=False, vm=False,
name_y=None, name_x=None, name_w=None, name_ds=None, latex=False):
"""
Maximum likelihood spatial error model.
Parameters:
- y (array): nx1 dependent variable
- x (array): nxk independent variables
- w (sparse matrix): Spatial weights matrix
- epsilon (float): Convergence criterion
- hard_bound (bool): Constrain lambda to [-1,1]
- vm (bool): Include variance-covariance matrix
"""
class ML_Error_Regimes:
def __init__(self, y, x, regimes, w, constant_regi='many', cols2regi='all',
regime_err_sep=False, cores=False, epsilon=0.0000001,
hard_bound=False, vm=False, name_y=None, name_x=None,
name_regimes=None, name_w=None, name_ds=None, latex=False):
"""ML spatial error model with regimes."""class ML_Lag:
def __init__(self, y, x, w, epsilon=0.0000001, hard_bound=False, vm=False,
name_y=None, name_x=None, name_w=None, name_ds=None, latex=False):
"""
Maximum likelihood spatial lag model.
Parameters:
- y (array): nx1 dependent variable
- x (array): nxk independent variables
- w (sparse matrix): Spatial weights matrix
- epsilon (float): Convergence criterion
- hard_bound (bool): Constrain rho to [-1,1]
- vm (bool): Include variance-covariance matrix
"""
class ML_Lag_Regimes:
def __init__(self, y, x, regimes, w, constant_regi='many', cols2regi='all',
regime_lag_sep=False, cores=False, epsilon=0.0000001,
hard_bound=False, vm=False, name_y=None, name_x=None,
name_regimes=None, name_w=None, name_ds=None, latex=False):
"""ML spatial lag model with regimes."""import numpy as np
import spreg
from libpysal import weights
# Data setup
n = 49
x = np.random.randn(n, 2)
y = np.random.randn(n, 1)
w = weights.lat2W(7, 7)
# ML spatial error estimation
ml_error = spreg.ML_Error(y, x, w.sparse, name_y='y', name_x=['x1', 'x2'])
print(ml_error.summary)# ML spatial lag estimation
ml_lag = spreg.ML_Lag(y, x, w.sparse, name_y='y', name_x=['x1', 'x2'])
print(ml_lag.summary)
print(f"Spatial lag parameter (rho): {ml_lag.rho}")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