or run

tessl search
Log in

Version

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/spreg@1.8.x
tile.json

tessl/pypi-spreg

tessl install tessl/pypi-spreg@1.8.0

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

Agent Success

Agent success rate when using this tile

87%

Improvement

Agent success rate improvement when using this tile compared to baseline

0.95x

Baseline

Agent success rate without this tile

92%

task.mdevals/scenario-6/

Regional Housing Price Analysis with Spatial Error Correction

Build a housing price analysis module that accounts for spatial autocorrelation in model errors. When analyzing housing prices across neighboring regions, standard regression assumptions often break down because residuals from nearby areas tend to be correlated. Your task is to implement a spatial error model that properly handles this spatial dependence in the error term.

Problem Context

You are given housing price data from multiple census tracts, along with characteristics like median income, crime rates, and housing age. Standard OLS regression yields biased standard errors when spatial autocorrelation exists in the residuals. Your module should estimate a spatial error model to account for this spatial dependence structure.

Requirements

Core Functionality

Your module must provide a function to estimate spatial error models that:

  1. Accepts a dependent variable (housing prices), independent variables (characteristics), and a spatial weights matrix
  2. Estimates the model accounting for spatially autocorrelated errors
  3. Returns the spatial error autocorrelation parameter (lambda)
  4. Returns coefficient estimates and their standard errors
  5. Provides model fit statistics

Test Cases

  • Given synthetic data with no spatial error autocorrelation (lambda = 0), the estimated lambda parameter should be close to zero (within 0.1) @test
  • Given synthetic data with moderate positive spatial error autocorrelation (lambda = 0.5), the estimated lambda should be between 0.4 and 0.6 @test
  • The function returns coefficient estimates as a dictionary or object with variable names as keys @test
  • The model provides a pseudo R-squared statistic for goodness of fit @test

Implementation

@generates

API

def estimate_spatial_error_model(y, X, W, variable_names=None):
    """
    Estimate a spatial error model with spatially autocorrelated errors.

    Parameters
    ----------
    y : array-like
        Dependent variable (n x 1), e.g., housing prices
    X : array-like
        Independent variables (n x k), e.g., income, crime rate, housing age
    W : array-like or sparse matrix
        Spatial weights matrix (n x n) representing spatial relationships
    variable_names : list of str, optional
        Names for the independent variables

    Returns
    -------
    dict
        Dictionary containing:
        - 'coefficients': dict mapping variable names to coefficient estimates
        - 'lambda': float, spatial error autocorrelation parameter
        - 'std_errors': dict mapping variable names to standard errors
        - 'pseudo_r_squared': float, pseudo R-squared statistic
    """
    pass

Dependencies { .dependencies }

spreg { .dependency }

Provides spatial econometric regression models for estimating spatial error models.

@satisfied-by