Skip to content

Model WIS with a Tweedie family (#159) - #166

Open
kathsherratt wants to merge 3 commits into
reinstate-baseline-modelfrom
model-error-family
Open

Model WIS with a Tweedie family (#159)#166
kathsherratt wants to merge 3 commits into
reinstate-baseline-modelfrom
model-error-family

Conversation

@kathsherratt

Copy link
Copy Markdown
Contributor

Compared Gaussian, Gamma and Tweedie families on the same joint specification (fixed formula and data).

Diagnostics

Using a Tweedie family created a large improvement. The Tweedie power parameter is estimated at 1.99 (the upper limit of mgcv), so the fitted family is effectively Gamma.

Comparison:

Family AIC Deviance explained Residual skew Residual kurtosis Converged
gaussian(log) 262,977 0.286 5.84 77.5 yes
Gamma(log) −104,260 0.378 0.52 9.4 no
tw(log), p=1.99 −103,072 0.380 0.58 9.2 yes

Also investigated whether the skew was a data artefact.

  • Checked the impact of the 1e-7 offset that process-data.R adds to every score
  • 553 forecasts (0.27%) score exactly zero, and adding the offset the constant parks them 11 log-units below the next smallest value
  • No impact: refitting without the offset changed residual skew by 0.01.

Impact

Both scales now use tw(link = "log"), replacing gaussian(log) on the log scale and Gamma(log) on the natural scale.

Several adjusted estimates moved, particularly the deaths-versus-cases contrast (ratio from 0.17 to 0.38).
All substantive conclusions hold (no model structure differs from the grand mean).

kathsherratt and others added 3 commits July 28, 2026 12:42
The primary model used gaussian(link = "log"), which left deviance
residuals with skew 5.8 and kurtosis 77. Modelling log(WIS) directly
would fix the residuals but loses propriety of the score, so the fix had
to come from the error family instead.

Compare Gaussian, Gamma and Tweedie families on the joint specification,
holding formula and data fixed (R/sensitivity/check-family.R). Both
scales now use tw(link = "log"), replacing gaussian(log) on the log scale
and Gamma(log) on the natural scale.

On the log scale this is a large improvement: residual skew falls from
5.84 to 0.58, kurtosis from 77.5 to 9.2, deviance explained rises from
0.286 to 0.380. Gamma fits the same data almost identically (skew 0.52,
deviance explained 0.378) but does not converge on either scale, which is
the reason for preferring Tweedie. The power parameter is estimated at
1.99, the upper limit mgcv permits, so the fitted family is a Gamma in
all but numerical behaviour -- stated as such rather than implying p was
freely estimated.

This also resolves the natural-scale non-convergence recorded in the
previous commit: that was a Gamma problem, not a scale problem. On the
natural scale the change fixes convergence but not the fit -- residual
skew is unchanged at 4.59, because natural-scale WIS is skewed beyond
what any Tweedie can absorb. Nothing rendered reads output/natural/, so
no reported result is affected.

Several adjusted estimates moved materially, most notably the
deaths-versus-cases contrast (ratio 0.17 to 0.38). All substantive
conclusions hold: no model structure differs from the grand mean, stable
trends remain most predictable, increasing trends least, Omicron BA.1 the
hardest variant phase. Delta's interval now excludes 1.

Investigated whether the 1e-7 constant that process-data.R adds to every
score was driving the skew, since 553 forecasts (0.27%) score exactly
zero and the constant parks them 11 log-units below the next smallest
value. It was not: refitting with the constant removed and the exact
zeros retained changes residual skew by 0.01. process-data.R is therefore
unchanged and the result is recorded in the supplement as a negative
finding.

Also fixes:
- archive_diagnostics() reassigned its accumulator, so it returned the
  whole fit-summary.csv rather than the row just written.
- tw() deparses its `link` argument, so passing a variable sent the
  literal string "family_link"; use do.call to force the value through.
- Pre-existing typo in the results ("After adjustment forfeatures of the
  forecast target ,").

The supplement comparison table carries a caption note that the Gamma fit
did not converge: it has the lowest residual skew of the three, and
without that note the table reads as though Gamma were the best choice.

Marks reviewer row #110 (QQ-plot dispersion) complete in the revision
tracker, which this work answers directly.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
The baseline-included-gaussian-log rows recorded the gaussian(log) and
Gamma(log) fits from the previous commit. Both families are now covered
by the family-* comparison arms, so the rows were redundant.

Remove both rows, their archived appraise() panels, and update the
CLAUDE.md pipeline example, which still named the retired label.

The supplement comparison table filters on the family-* prefix, so it is
unchanged and no re-render is needed.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@sbfnk

sbfnk commented Jul 29, 2026

Copy link
Copy Markdown
Member

Checked the impact of the 1e-7 offset that process-data.R adds to every score

Having done the comparison is there a case for removing the 1e-7 offset for the "production" version?

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.

2 participants