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-3/

Spatial Housing Price Analysis with Endogenous Variables

Build a spatial econometric analysis tool that estimates the effect of property characteristics on housing prices while accounting for endogeneity and testing for spatial autocorrelation in an instrumental variables framework.

Background

In housing price analysis, certain variables like renovation expenditure may be endogenous (correlated with unobserved factors in the error term). When analyzing spatial data with endogenous variables, it's important to use instrumental variables estimation and test for spatial autocorrelation that might bias the results.

Requirements

Data Input

Your program should accept the following inputs:

  • prices: Housing prices (dependent variable)
  • characteristics: Exogenous property characteristics such as square footage, number of bedrooms, age, etc.
  • renovation_spending: Endogenous variable representing renovation expenditure
  • neighborhood_income: External instrument for renovation spending
  • spatial_weights: A spatial weights matrix representing neighborhood relationships

Model Estimation

Estimate a housing price model that:

  • Treats renovation spending as an endogenous variable
  • Uses neighborhood income as an instrumental variable for renovation spending
  • Includes the exogenous property characteristics as control variables
  • Accounts for the spatial structure using the provided spatial weights matrix

Diagnostic Testing

Perform diagnostic tests to assess:

  • Whether the instrumental variables approach is needed (test for endogeneity)
  • Whether spatial autocorrelation is present in the residuals of the IV model

Output Requirements

Your program should output:

  1. Coefficient estimates for all variables (exogenous characteristics and instrumented renovation spending)
  2. The endogeneity test statistic and p-value
  3. The spatial autocorrelation test statistic and p-value specifically designed for IV/2SLS models
  4. A boolean flag indicating whether spatial autocorrelation is detected (using 0.05 significance level)

Test Cases

Test Case 1: Basic IV estimation without spatial effects @test

Given:

  • 100 observations of housing prices
  • 2 exogenous characteristics (square footage, age)
  • 1 endogenous variable (renovation spending)
  • 1 instrument (neighborhood income)
  • A spatial weights matrix with no significant spatial structure

Expected:

  • Model successfully estimates coefficients
  • Endogeneity test is performed
  • Spatial autocorrelation test for IV models is performed
  • All test statistics are returned with p-values

Test Case 2: Detection of spatial autocorrelation @test

Given:

  • Simulated data with strong spatial autocorrelation in the error term
  • IV model setup with endogenous variable and valid instrument
  • Spatial weights matrix reflecting true spatial structure

Expected:

  • Spatial autocorrelation test p-value < 0.05
  • Boolean flag for spatial autocorrelation detection is True

Implementation

@generates

API

def analyze_housing_prices(prices, characteristics, renovation_spending,
                          neighborhood_income, spatial_weights):
    """
    Estimate a spatial IV model for housing prices and perform diagnostic tests.

    Parameters:
    -----------
    prices : array-like
        Dependent variable (housing prices)
    characteristics : array-like
        Exogenous independent variables (property characteristics)
    renovation_spending : array-like
        Endogenous variable (renovation expenditure)
    neighborhood_income : array-like
        Instrument for the endogenous variable
    spatial_weights : spatial weights object
        Spatial weights matrix representing neighborhood relationships

    Returns:
    --------
    dict with keys:
        'coefficients': Estimated coefficients for all variables
        'endogeneity_test_statistic': Test statistic for endogeneity
        'endogeneity_test_pvalue': P-value for endogeneity test
        'spatial_test_statistic': Test statistic for spatial autocorrelation in IV model
        'spatial_test_pvalue': P-value for spatial autocorrelation test
        'has_spatial_autocorrelation': Boolean indicating if spatial autocorrelation detected
    """
    pass

Dependencies { .dependencies }

spreg { .dependency }

Provides spatial regression and diagnostic testing capabilities for econometric analysis.

numpy { .dependency }

Provides numerical array operations.