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

Spatial Multiplier Effects Analyzer

Build a tool that estimates spatial multiplier effects to decompose how changes in independent variables propagate through spatially connected observations. The tool should fit a spatial model and compute direct, indirect, and total effects.

Requirements

Input Data

Your implementation must accept:

  • A dependent variable (y) as a numeric array
  • Independent variables (X) as a 2D numeric array
  • A spatial weights matrix (W) representing spatial connections between observations

Model Estimation

Estimate a spatial lag model that includes a spatially lagged dependent variable. The model should:

  • Include an intercept term automatically
  • Estimate coefficients for the independent variables
  • Estimate the spatial autoregressive parameter

Multiplier Decomposition

Compute spatial multipliers that decompose the total effect into:

  • Direct effects: The impact of a unit change in an independent variable on the same observation
  • Indirect effects: The spillover impact on other spatially connected observations
  • Total effects: The sum of direct and indirect effects

Calculate these multipliers using at least two different computational methods and verify they produce consistent results.

Output

Return a data structure containing:

  • Direct, indirect, and total effects for each independent variable
  • Results from multiple computation methods for comparison
  • The estimated spatial autoregressive parameter

Test Cases

Test Case 1: Basic Multiplier Computation @test

Given a 5-observation dataset with y=[1,2,3,4,5], X=[[1,2],[2,3],[3,4],[4,5],[5,6]], and a row-standardized spatial weights matrix with nearest-neighbor connections:

  • Verify that direct, indirect, and total effects are all computed and returned
  • Verify that total effects equal direct effects plus indirect effects (within numerical precision)

Test Case 2: Method Comparison @test

Using the same dataset from Test Case 1:

  • Verify that at least two different computation methods are used
  • Verify that results from different methods are numerically similar (within 0.01 tolerance for each effect type)

Test Case 3: Spatial Parameter Validation @test

Using the fitted model from Test Case 1:

  • Verify that the estimated spatial autoregressive parameter (rho) is returned
  • Verify that rho is between -1.0 and 1.0

@generates

API

def analyze_spatial_multipliers(y, X, W):
    """
    Estimate spatial multipliers from a spatial lag model.

    Parameters:
    -----------
    y : array-like
        Dependent variable (n x 1)
    X : array-like
        Independent variables (n x k)
    W : array-like or sparse matrix
        Spatial weights matrix (n x n)

    Returns:
    --------
    dict
        Dictionary containing:
        - 'direct': array of direct effects for each variable
        - 'indirect': array of indirect effects for each variable
        - 'total': array of total effects for each variable
        - 'methods': dict with results from different computation methods
        - 'rho': estimated spatial autoregressive parameter
    """
    pass

Dependencies { .dependencies }

spreg { .dependency }

Provides spatial econometric regression models and multiplier computation.