tessl install tessl/pypi-spreg@1.8.0Spatial 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%
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.
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.
Your module must provide a function to estimate spatial error models that:
@generates
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
"""
passProvides spatial econometric regression models for estimating spatial error models.
@satisfied-by