Skip to content

fix: correct weighted log_pdf in NormalDist and InvGaussDist#458

Open
DEEP-600 wants to merge 3 commits into
dswah:mainfrom
DEEP-600:fix/normal-log-pdf-weights
Open

fix: correct weighted log_pdf in NormalDist and InvGaussDist#458
DEEP-600 wants to merge 3 commits into
dswah:mainfrom
DEEP-600:fix/normal-log-pdf-weights

Conversation

@DEEP-600

@DEEP-600 DEEP-600 commented Feb 24, 2026

Copy link
Copy Markdown

Two related weighted-likelihood fixes in pygam/distributions.py:

What changed

NormalDist

# before
scale = self.scale / weights
# after
scale = self.scale / np.sqrt(weights)

Aligns with GLM convention: Var = scale² / w, not scale² / w².

InvGaussDist

# before
invgauss.logpdf(y, mu=mu, scale=1.0/gamma)
# after
invgauss.logpdf(y, mu=mu/gamma, scale=gamma)

where gamma = weights / self.scale. Matches correct inverse-Gaussian parameterization under weights.

Tests

Added test_distributions.py with 6 tests covering both fixes — control cases and weighted/non-unit-scale parity against closed-form.

All 6 pass: pytest test_distributions.py -q → 6 passed

Impact

Fixes log-likelihood calculations under weighted settings → corrects AIC, AICc, GCV, pseudo R² for LinearGAM and InvGaussGAM with non-uniform weights. Fitted coefficients unaffected.

Align SciPy invgauss parameter mapping for weighted/non-unit-scale cases and add regression tests against closed-form inverse-Gaussian log-density.
@DEEP-600 DEEP-600 changed the title fix: NormalDist.log_pdf divide SD by sqrt(weights) instead of weights fix: correct weighted log_pdf in NormalDist and InvGaussDist Mar 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant