Adding new panels module - #192
Conversation
There was a problem hiding this comment.
Pull request overview
Adds a new spreg.panel module (targeting spreg 1.9.0) that consolidates panel estimators (pooled OLS, FE/RE, and spatial SEM/SAR variants) and updates supporting utilities/output to enable panel-aware lagging and reporting.
Changes:
- Introduces
spreg/panel.pywith the new panel estimators and integrates them into the public package API (spreg/__init__.py). - Extends panel plumbing/utilities (e.g.,
prepare_panel, panel-awareget_lags, updates to diagnostics + output formatting). - Updates/adjusts tests and notebooks to reflect the new panel entry points and deprecations.
Reviewed changes
Copilot reviewed 19 out of 20 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
spreg/panel.py |
New consolidated panel estimators (PooledOLS/FE/RE + spatial GM/ML variants) and reporting glue. |
spreg/panel_utils.py |
Adds prepare_panel and updates check_panel to return T alongside stacked arrays. |
spreg/utils.py |
Updates caching behavior and adds panel-aware spatial lag computation via Kronecker-expanded weights. |
spreg/user_output.py |
Extends naming helpers and flex_wx to support panel lagging / additional lag naming paths. |
spreg/diagnostics_panel.py |
Updates panel diagnostics for new check_panel signature and adds BSK_tests helper. |
spreg/output.py |
Tweaks summary formatting and Probit summary output API. |
spreg/ml_error.py |
Refactors LU path to use splu directly and improves numerical robustness in concentrated LL. |
spreg/ols.py |
Updates BaseOLS docstring, adds pinv option, and introduces BaseWLS. |
spreg/sputils.py |
Adjusts spatial effects indexing logic for cases with/without constant. |
spreg/__init__.py |
Exposes the new panel module at package import time. |
spreg/sp_panels.py, spreg/panel_fe.py, spreg/panel_re.py |
Marks legacy panel modules as deprecated and adds deprecation warnings. |
spreg/tests/test_panel.py |
Adds new tests covering the new panel estimators. |
spreg/tests/test_sp_panels.py, spreg/tests/test_panel_fe.py, spreg/tests/test_panel_re.py |
Disables legacy tests and marks deprecation. |
notebooks/panels_examples.ipynb |
Adds new notebook showcasing the new panel API. |
notebooks/Panel_FE_example.ipynb |
Removes old fixed-effects notebook example. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if spat_diag: | ||
| self.bsk = BSK_tests(self, w, which=BSK_list) | ||
| other_end += "\nSPATIAL DIAGNOSTIC TESTS\n" | ||
| other_end += f"{"-" * 84 }\n" |
Codecov Report❌ Patch coverage is
❌ Your patch status has failed because the patch coverage (72.2%) is below the target coverage (80.0%). You can increase the patch coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## main #192 +/- ##
=======================================
- Coverage 72.6% 71.0% -1.6%
=======================================
Files 45 46 +1
Lines 10929 11948 +1019
=======================================
+ Hits 7937 8483 +546
- Misses 2992 3465 +473
🚀 New features to boost your workflow:
|
|
this is sweet! I'm guessing there's a paper in the works... :P any chance you have a notebook exploring some of these functions somewhere? |
Sure thing! Here it is: https://github.com/pysal/spreg/blob/6abf15bfed2c0f9a02573ddb29d6492a305736ef/notebooks/panels_examples.ipynb Let me know if you feel there is anything missing. Many thanks! |
This new panels module (spreg version 1.9.0) offers the following panel functions (in addition to the SUR estimators):
1. OLS and Basic Panel Classes
PooledOLS
Description: Baseline pooled regression for panel data. Initializes and runs the pooled OLS estimation with optional BSK spatial diagnostics.
PanelFE
Description: Fixed Effects (Within) estimator for panel data. Performs the "Within Transformation" (demeaning) and executes the regression.
PanelRE
Description: Random Effects (GLS) estimator. Estimates variance components using Swamy-Arora, computes quasi-demeaning, and performs the Hausman test.
2. GMM-Based Spatial Error Classes
GM_ErrorPooled
Description: Pooled Spatial Error Model (SEM) via GMM. Based on the heteroskedasticity-robust estimator proposed by
Arraiz2010, available in the spreg functionGM_Error_Het.GM_ErrorRE
Description: KKP spatial random effects model.
3. Maximum Likelihood (ML) Spatial Classes
ML_ErrorPooled
Description: Pooled ML SEM with diagnostic output.
ML_ErrorFE
Description: ML estimation for Fixed Effects Spatial Error models.
ML_ErrorRE
Description: ML estimation for Random Effects Spatial Error models using Ord's eigenvalue approach.
ML_LagFE
Description: ML estimation for Fixed Effects Spatial Lag models with spatial impacts.
ML_LagRE
Description: ML Spatial Lag Random Effects to estimate both the spatial lag (ρ) and the random effects component (ϕ)