pyGAM icon indicating copy to clipboard operation
pyGAM copied to clipboard

fix(distributions): correct NormalDist weight handling and UBRE calculation

Open Karman580 opened this issue 8 months ago • 0 comments

This PR fixes statistical correctness issues in the weighted log-likelihood computation for NormalDist and related UBRE calculations. Previously, weights were applied as scale = self.scale / weights, which implied a variance of σ²/w². Following the GLM convention used in PyGAM (Var = σ²/w), the correct standard deviation for weighted observations is σ/√w; therefore, the implementation has been updated to self.scale / np.sqrt(weights). Additionally, this PR corrects a boolean inversion bug in the UBRE computation (~add_scale → float(not add_scale)) and fixes a formatting issue in the gamma scaling ValueError message. Regression tests were added to validate weighted log-likelihood behavior against scipy.stats.norm.logpdf. All tests pass successfully. Fixes #457.

Karman580 avatar Mar 14 '26 16:03 Karman580