1.
Letβs finish the exercise we started:
In the 2014 FIFA World Cup, Germany played Brazil in a semifinal match. Germany scored after 11 minutes and again at the 23 minute mark. At that point in the match, how many goals would you expect Germany to score after 90 minutes? What was the probability that they would score 5 more goals (as, in fact, they did)?
Here are the steps I recommend:
-
Starting with the same gamma prior we used in the previous problem, compute the likelihood of scoring a goal after 11 minutes for each possible value of
lam. Donβt forget to convert all times into games rather than minutes. -
Compute the posterior distribution of
lamfor Germany after the first goal. -
Compute the likelihood of scoring another goal after 12 more minutes and do another update. Plot the prior, posterior after one goal, and posterior after two goals.
-
Compute the posterior predictive distribution of goals Germany might score during the remaining time in the game,
90-23minutes. Note: You will have to think about how to generate predicted goals for a fraction of a game. -
Compute the probability of scoring 5 or more goals during the remaining time.
Solution.
# Here's a function that updates the distribution of lam
# with the given time between goals
def update_expo(pmf, data):
"""Update based on an observed interval
pmf: prior PMF
data: time between goals in minutes
"""
t = data / 90
lams = pmf.qs
likelihood = expo_pdf(t, lams)
pmf *= likelihood
pmf.normalize()
# Here are the updates for the first and second goals
germany = prior.copy()
update_expo(germany, 11)
germany2 = germany.copy()
update_expo(germany2, 12)
# Here are the mean values of `lam` after each update
germany.mean(), germany2.mean()
(2.1358882653086892, 2.703059034926364)
# Here's what the posterior distributions look like
prior.plot(ls='--', label='prior', color='C5')
germany.plot(color='C3', label='Posterior after 1 goal')
germany2.plot(color='C16', label='Posterior after 2 goals')
decorate_rate('Prior and posterior distributions')

# Here's the predictive distribution for each possible value of `lam`
t = (90-23) / 90
pmf_seq = [make_poisson_pmf(lam*t, goals)
for lam in germany2.qs]
# And here's the mixture of predictive distributions,
# weighted by the probabilities in the posterior distribution.
pred_germany2 = make_mixture(germany2, pmf_seq)
# Here's what the predictive distribution looks like
pred_germany2.bar(color='C1', label='germany')
decorate_goals('Posterior predictive distribution')

# Here's the probability of scoring exactly 5 more goals
pred_germany2[5]
0.047109658706113416
# And the probability of 5 or more
pred_germany2.prob_ge(5)
0.09286200122834538













