Skip to content

panel: complete Tier-1 diagnostics and shared inference framework #93

Description

@TheHiddenObserver

Context

statgpu already provides PanelOLS, RandomEffects, PooledOLS, BetweenOLS, FirstDifferenceOLS, and FamaMacBeth, together with several covariance paths. The remaining core gap is not another estimator count; it is the absence of a shared panel inference framework and standard econometric diagnostics expected in routine FE/RE workflows.

The current implementation also duplicates validation, summary construction, OLS/inference logic, and covariance dispatch across panel estimators.

Roadmap: PR #89. Design reference: dev/plans/panel_framework_proposal.md.

Goal

Complete the Panel Tier-1 workflow through three bounded implementation stages while preserving all current fitted values, coefficients, prediction semantics, and documented covariance behavior.

Stage A — shared framework refactor

Introduce or finalize:

  • a shared panel base abstraction for input/formula handling, fitted-state lifecycle, prediction validation, and summary construction;
  • a covariance-estimator registry or equivalent centralized dispatch;
  • shared structured result types for tests and fit statistics;
  • common rank-deficiency, degrees-of-freedom, entity/time index, balanced/unbalanced panel, and missing-data validation;
  • lazy effect handling where consistent with current public contracts.

This stage must be behavior-preserving. Golden regression tests should freeze current coefficients, fitted values, residuals, covariance matrices, and predictions before structural changes.

Stage B — specification tests and fit statistics

Add:

  • Hausman FE-vs-RE test;
  • pooling F-test / fixed-effect significance test;
  • Breusch-Pagan LM test for random effects versus pooled OLS;
  • within, between, and overall R-squared;
  • adjusted R-squared with an explicitly documented degrees-of-freedom definition;
  • model F-statistic;
  • structured test output containing statistic, distribution, degrees of freedom, p-value, null, alternative, and applicability diagnostics.

Singular covariance differences, non-positive test statistics caused by numerical error, incompatible model pairs, and non-nested designs must have explicit behavior rather than silent clipping or generic exceptions.

Stage C — covariance completion

Add or complete:

  • robust covariance for RandomEffects;
  • HC0, HC2, and HC3 where statistically defined;
  • Driscoll-Kraay covariance;
  • explicit one-way and two-way cluster contracts;
  • bandwidth and kernel selection semantics;
  • small-sample and degrees-of-freedom corrections;
  • backend-native accumulation without copying full GPU arrays to CPU.

Backend contract

  • NumPy CPU;
  • CuPy CUDA;
  • Torch CUDA;
  • explicit device requests must not silently fall back;
  • final scalar/result conversion may synchronize, but core transformed design, residual, score, and covariance accumulation must remain on the selected backend.

Formula and data contract

Cover:

  • entity and time effects;
  • two-way effects;
  • explicit and formula-generated intercept behavior;
  • categorical terms and interactions where currently supported;
  • balanced and unbalanced panels;
  • index/order preservation;
  • prediction with required entity/time identifiers;
  • missing-data row alignment.

External alignment

Use aligned comparisons against:

  • Python linearmodels;
  • R plm;
  • R/Python sandwich implementations where applicable;
  • Stata definitions as documentation references when no open implementation is directly callable.

Every comparison must state effect specification, covariance type, small-sample correction, degrees-of-freedom convention, and any parameterization differences.

Non-goals

  • no Panel IV/2SLS/GMM;
  • no high-dimensional fixed-effect absorption;
  • no DID/event study;
  • no Arellano-Bond/dynamic-panel GMM;
  • no Panel VAR;
  • no repository-wide inference rewrite outside panel code.

Required validation

  • focused unit tests for each statistic and covariance formula;
  • golden behavior-preservation tests before/after Stage A;
  • formula and array API parity;
  • balanced/unbalanced and one-way/two-way effect cases;
  • rank-deficient and invalid model-pair failure tests;
  • NumPy/CuPy/Torch parity tests;
  • external comparisons for coefficients, covariance, standard errors, test statistics, p-values, and R-squared variants;
  • maintained physical-GPU validation on CuPy and Torch;
  • synchronized EN/CN panel documentation and examples;
  • benchmark evidence for any performance claim.

Acceptance criteria

  • Stage A removes the targeted duplication without changing existing public numerical behavior.
  • Hausman, pooling F, and Breusch-Pagan LM tests have structured, documented APIs.
  • Within/between/overall/adjusted R-squared and model F-statistics are available where defined.
  • RandomEffects robust covariance, HC0/HC2/HC3, and Driscoll-Kraay contracts are implemented or explicitly split with a documented blocker.
  • All supported statistics work on NumPy, CuPy, and Torch without silent fallback.
  • External alignment records definitions and degrees-of-freedom corrections explicitly.
  • Complete CPU, compatibility, and physical-GPU gates pass.
  • User documentation states applicability restrictions and failure behavior.

PR decomposition

This issue should normally close through at least three PRs:

  1. shared base and covariance registry;
  2. diagnostics and fit statistics;
  3. covariance extensions.

A single PR combining all stages requires an explicit review justification and must not weaken the staged acceptance gates.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions