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%
A tool for evaluating and comparing regression model fit quality using R-squared and pseudo R-squared metrics.
Fits an OLS regression model and returns the R-squared value indicating the proportion of variance explained.
Fits an OLS regression model and returns the adjusted R-squared which penalizes model complexity.
Fits a two-stage least squares model with an endogenous variable and returns the pseudo R-squared metric.
Evaluates both OLS and TSLS models on the same data and compares their fit metrics.
@generates
def compute_ols_fit(y, x):
"""
Compute R-squared and adjusted R-squared for an OLS regression model.
Parameters:
- y (array): nx1 dependent variable
- x (array): nxk independent variables
Returns:
- dict: {'r_squared': float, 'adjusted_r_squared': float}
"""
def compute_tsls_fit(y, x, yend, q):
"""
Compute pseudo R-squared for a two-stage least squares model.
Parameters:
- y (array): nx1 dependent variable
- x (array): nxk exogenous independent variables
- yend (array): nxp endogenous variables
- q (array): nxq external instruments
Returns:
- float: Pseudo R-squared value
"""
def compare_models(y, x, yend=None, q=None):
"""
Compare OLS and TSLS model fit on the same dataset.
Parameters:
- y (array): nx1 dependent variable
- x (array): nxk independent variables
- yend (array, optional): nxp endogenous variables for TSLS
- q (array, optional): nxq instruments for TSLS
Returns:
- dict: {'ols': {'r_squared': float, 'adjusted_r_squared': float},
'tsls': {'pseudo_r_squared': float}} if yend and q provided,
otherwise only returns 'ols' results
"""Provides spatial econometric regression models including OLS and TSLS estimation with fit statistics.
@satisfied-by