CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-spreg

Spatial econometric regression models for analyzing geographically-related data interactions.

Overall
score

87%

Overview
Eval results
Files

ml-models.mddocs/

Maximum Likelihood Models

Full information maximum likelihood estimation for spatial lag and error models with analytical derivatives and concentrated log-likelihood functions.

Capabilities

Spatial Error ML Models

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."""

Spatial Lag ML Models

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."""

Usage Examples

Basic ML Spatial Error

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 Model

# 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-spreg

docs

diagnostics.md

index.md

ml-models.md

ols-models.md

panel-models.md

probit-models.md

regime-models.md

spatial-error-models.md

sur-models.md

tsls-models.md

utilities.md

tile.json