Conversation
Add a geometric channel alongside the seasonal and percentile strategies: expm1(mean(log1p(x)) + k*std(log1p(x))) over historical same-month (or same-week) values, i.e. the geometric mean times the geometric standard deviation to the power k. Computing on a log1p scale keeps zero counts, which a plain geometric mean cannot represent. The channel is centred on the geometric mean, which AM-GM keeps at or below the arithmetic mean, so a past epidemic year moves it far less than it moves mean + k*std. The band is multiplicative rather than additive, so on a short baseline a single extreme year can make it wider than mean + k*std; the strategy description and module docstring say so, since the default percentile baseline is five years. std_multiplier takes a scalar or a list, so one request can return several lines.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds a
geometricendemic channel strategy alongside the existingseasonalandpercentileones:over historical same-month (or same-week) values — the geometric mean times the geometric standard deviation raised to the power
k.std_multipliertakes a scalar or a list, so one request can return several lines.Why
Case counts are strongly right-skewed, and
seasonal's arithmetic mean is pulled up by single epidemic years. Working on a log scale centres the channel on the geometric mean instead, which AM-GM keeps at or below the arithmetic mean for any non-constant history.Computing on
log1p/expm1rather than a plain geometric mean is deliberate: it keeps zero counts, which a plain geometric mean cannot represent, and an all-zero season yields a finite threshold of 0 rather than dropping the rows.Caveat, stated in the strategy description
Only the centre is guaranteed lower than the arithmetic channel. The band is multiplicative, so the log-scale standard deviation is a relative spread, and on a short baseline a single extreme year can make the back-transformed band wider than
mean + k*std:seasonalgeometricThat matters because
percentiledefaults to a 5-year baseline, which is exactly where the effect reverses. The registry description, module docstring and contributor guide all say this, and the test asserts the guaranteed property (k=0, AM-GM) rather than the data-dependent inequality.Notes
@thresholdplus membership in theThresholdParamsunion is enough.median_iqr(Tukey fence) strategy; it was dropped as redundant next topercentile.Testing
make lintclean (ruff, mypy, pyright)