pyGAM icon indicating copy to clipboard operation
pyGAM copied to clipboard

Fix empty Effective DoF in summary() for overparametrized models #535

Open hritikkumarpradhan opened this issue 8 months ago • 0 comments

Resolve Empty Effective DoF in summary() for overparametrized models

When a pyGAM model is overparameterized (number of samples < number of coefficients), the summary() method previously displayed an empty string for the term-by-term Effective Degrees of Freedom (EDoF). This was due to the statistics computation relying on a truncated SVD result (U1) whose size was limited by the number of samples.

Changes:

  1. Refined EDoF Calculation: Updated _estimate_model_statistics() to use the robust formula $diag(B \cdot WB)$ for computing edof_per_coef. This formula correctly handles cases where $n < m$ and ensures the EDoF array always matches the number of coefficients.
    1. Summary Method Update: Updated the summary() method to rely on the now-correctly-sized EDoF values.
    1. Transparent Warning: Added a warning to the summary() output to inform users when overparameterization is detected, clarifying that while EDoF values are now displayed, they should be interpreted with caution in these settings.
    1. Test Coverage: Updated test_more_splines_than_samples in pygam/tests/test_GAM_methods.py to assert the correct EDoF length. This fix ensures that users can always inspect how their subterms consume degrees of freedom, even when working with small datasets or complex spline settings.

hritikkumarpradhan avatar Mar 17 '26 18:03 hritikkumarpradhan