Testing Poisson Overdispersion in Football Goal Counts with Python

A tutorial on checking whether goal counts vary more than a Poisson model allows, with an input contract, a hand-checkable example and failure tests.

Algo Bet Editorial · · Models · 4 min read

A Poisson model for goals makes a strong bet: the spread of goal counts is tied to their average. If that bet is wrong, intervals come out too narrow and every downstream probability inherits false confidence. This tutorial treats the check as a small engineering task. It declares an input contract, explains why the variance is locked to the mean, shows how a negative binomial loosens that lock, works through a hand-checkable calculation on a synthetic table, and lists the bad inputs a pipeline should refuse. Everything here is a demonstration, not evidence about any real league.

The input contract before any statistics

Start with the table, not the test. A goal-count check needs one row per team per match, with a non-negative integer goals column, a team identifier, and a kickoff timestamp in a declared timezone. The timestamp matters because every feature must be available before the match it describes. A row that mixes in information from after kickoff leaks the future, and any later validation built on it is meaningless.

The question itself is easy to state. Overdispersion means the observed variance in a data set is higher than the variance expected from a given statistical model. For goals, that model is Poisson, so the contract must also name what is compared: the sample variance of the goals column against its sample mean. Declare that pairing in the schema, so a reader can reproduce the check without guessing.

Why Poisson pins the variance and how a negative binomial frees it

The Poisson distribution has one free parameter, so it cannot adjust the variance independently of the mean. Fit the mean and the variance is already decided. Picture a single dial that sets the centre and the spread together: you can turn it, but you cannot widen the spread while holding the centre still. When real goal counts are more scattered than that dial permits, the model has no way to say so.

The usual remedy adds a second dial. A Poisson mixture such as the negative binomial treats the Poisson mean as a random variable drawn from a gamma distribution, which adds one free parameter. That parameter is what lets variance rise above the mean. The model stops claiming that every team-match shares one scoring rate and admits that the rate itself varies.

A hand-checkable variance-to-mean calculation

Take a hypothetical fixture of six synthetic team-match rows with goals 0, 0, 1, 1, 2, 6. These numbers are illustrative only. The mean is 10 divided by 6, about 1.67. The squared deviations from that mean sum to roughly 25.33, and dividing by 5 gives a sample variance near 5.07. The variance-to-mean ratio is therefore about 3.04. A Poisson model expects a ratio near 1, so this fixture sits well above it.

Now the contrast. Replace the final 6 with a 2 and the goals become 0, 0, 1, 1, 2, 2. The mean falls to 1.0, the sample variance to 0.8, and the ratio to 0.8, which is not overdispersed at all. One extreme row moved the ratio from below 1 to above 3. With six rows a single outlier decides the verdict, so a ratio alone is a prompt to look closer, not a conclusion.

Synthetic goal counts: fixture A has sample variance 5.07 and variance-to-mean ratio 3.04; fixture B has variance and ratio 0.80.

Reading the negative binomial correctly

Before switching to the alternative, know how it relates to the baseline. The negative binomial has variance mu/p, and it becomes identical to the Poisson distribution in the limit p to 1 for a given mean mu. That limit makes a handy sanity check in code: as the extra parameter pushes toward the Poisson end, the two models should return matching answers. If they do not, suspect a parametrisation slip before suspecting the data.

It also tells you how to use the alternative. The negative binomial can serve as an overdispersed alternative to the Poisson, for example as a robust modification of Poisson regression. Treat it as a fallback when the Poisson spread assumption fails, not an automatic upgrade. Keep the Poisson as the declared baseline and make the wider model earn its place against it on held-out matches.

Failure cases and why the spread appears

A defensible pipeline refuses bad input loudly. Three cases belong in the test suite. An empty table must raise an error rather than return a ratio of not-a-number. A row with a negative or fractional goal count must be rejected with a message naming the offending row. Two rows sharing the same team and kickoff timestamp must be flagged as duplicates, since silently keeping both double-counts one match and distorts the variance.

Once those checks pass, you still need a reason to expect extra spread. Overdispersion is common in applied data because populations are frequently heterogeneous, contrary to the assumptions of simple parametric models. Teams differ in strength and matches differ in context. The negative binomial may also fit when events have positively correlated occurrences, which produce a larger variance than independent occurrences would, through a positive covariance term. If one goal changes how a match unfolds, goals are not independent draws.

An overdispersion check belongs before any model comparison, but on its own it settles little. Fit on earlier matches, evaluate on later ones, and never shuffle across time. Small samples make the variance-to-mean ratio unstable, as the six-row fixture showed, so a flagged ratio should trigger a closer test rather than a verdict. Nothing here claims that goals in any real competition are overdispersed. That needs a licensed dataset and a recorded run. Treat the code as a falsifiable gate in the pipeline, and report the result with its sample size attached.

18+ only. Models do not guarantee results. See our Responsible Gambling page.