Skip to content

Adding new panels module - #192

Merged
pedrovma merged 6 commits into
pysal:mainfrom
pedrovma:main
Mar 24, 2026
Merged

Adding new panels module#192
pedrovma merged 6 commits into
pysal:mainfrom
pedrovma:main

Conversation

@pedrovma

Copy link
Copy Markdown
Member

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 function GM_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 (ϕ)

Copilot AI review requested due to automatic review settings March 16, 2026 10:58

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.py with the new panel estimators and integrates them into the public package API (spreg/__init__.py).
  • Extends panel plumbing/utilities (e.g., prepare_panel, panel-aware get_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.

Comment thread spreg/panel.py Outdated
if spat_diag:
self.bsk = BSK_tests(self, w, which=BSK_list)
other_end += "\nSPATIAL DIAGNOSTIC TESTS\n"
other_end += f"{"-" * 84 }\n"
@codecov

codecov Bot commented Mar 16, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 72.20447% with 87 lines in your changes missing coverage. Please review.
✅ Project coverage is 71.0%. Comparing base (715b6de) to head (3a1fb8c).
⚠️ Report is 7 commits behind head on main.

Files with missing lines Patch % Lines
spreg/user_output.py 39.0% 25 Missing ⚠️
spreg/diagnostics_panel.py 89.0% 16 Missing ⚠️
spreg/output.py 59.0% 16 Missing ⚠️
spreg/ols.py 33.3% 10 Missing ⚠️
spreg/panel_re.py 33.3% 6 Missing ⚠️
spreg/ml_error.py 72.2% 5 Missing ⚠️
spreg/utils.py 78.6% 3 Missing ⚠️
spreg/panel_fe.py 60.0% 2 Missing ⚠️
spreg/panel_utils.py 90.5% 2 Missing ⚠️
spreg/sp_panels.py 0.0% 1 Missing ⚠️
... and 1 more

❌ 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

Impacted file tree graph

@@           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     
Files with missing lines Coverage Δ
spreg/__init__.py 100.0% <100.0%> (ø)
spreg/error_sp_het.py 88.0% <ø> (ø)
spreg/panel.py 96.6% <ø> (ø)
spreg/sp_panels.py 11.2% <0.0%> (-73.7%) ⬇️
spreg/sputils.py 80.5% <66.7%> (-0.3%) ⬇️
spreg/panel_fe.py 56.3% <60.0%> (-40.2%) ⬇️
spreg/panel_utils.py 82.1% <90.5%> (+17.6%) ⬆️
spreg/utils.py 78.0% <78.6%> (+1.5%) ⬆️
spreg/ml_error.py 83.8% <72.2%> (-1.2%) ⬇️
spreg/panel_re.py 55.0% <33.3%> (-44.2%) ⬇️
... and 4 more

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@pedrovma
pedrovma requested a review from knaaptime March 16, 2026 12:43
@pedrovma
pedrovma merged commit 6abf15b into pysal:main Mar 24, 2026
14 of 15 checks passed
@knaaptime

Copy link
Copy Markdown
Member

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?

@pedrovma

Copy link
Copy Markdown
Member Author

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants