Grid algorithm for the gamma-Poisson hierarchical model
Copyright 2021 Allen B. Downey
License: Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0)
Poisson model
Let's look at one more example of a hierarchical model, based on the hockey example we started with.
Remember that we used a gamma distribution to represent the distribution of the rate parameters, mu. I chose the parameters of that distribution, alpha and beta, based on results from previous NHL playoff games.
An alternative is to use a hierarchical model, where alpha and beta are hyperparameters. Then we can use data to update estimate the distribution of mu for each team, and to estimate the distribution of mu across teams.
Of course, now we need a prior distribution for alpha and beta. A common choice is the half Cauchy distribution (see Gelman), but on advice of counsel, I'm going with exponential.
Here's a model that generates the prior distribution of mu.
One teams
Here's the hierarchical version of the model for two teams.
We can use traceplot to review the results and do some visual diagnostics.
Here are the posterior distributions for the two teams.
More background
But let's take advantage of more information. Here are the results from the most recent Stanley Cup finals. For games that went into overtime, I included only goals scored during regulation play.
Here's how we can get the data into the model.
Here's the graph representation of the model:
And here are the results.
Here are the posterior means for the hyperparameters.
So in case you were wondering how I chose the parameters of the gamma distribution in the first notebook. That's right -- time travel.
Here's the updated chance that Tampa Bay is the better team.