In the last blog post I showed my initial attempt at modeling football results in La Liga using a Bayesian Poission model, but there was one glaring problem with the model; it did not consider the advantage of being the home team. In this post I will show how to fix this! I will also show a way to deal with the fact that the dataset covers many La Liga seasons and that teams might differ in skill between seasons.
Modeling Match Results: Iteration 2
The only change to the model needed to account for the home advantage is to split the baseline into two components, a home baseline and an away baseline. The following JAGS model implements this change by splitting baseline
into home_baseline
and away_baseline
.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 

Another cup of coffee while we run the MCMC simulation…
1 2 3 4 5 6 

Looking at the trace plots and distributions of home_baseline
and away_baseline
shows that there is a considerable home advantage.
1


1


Looking at the difference between exp(home_baseline)
and exp(away_baseline)
shows that the home advantage is realized as roughly 0.5 more goals for the home team.
1 2 

Comparing the DIC of the of the two models also indicates that the new model is better.
1 2 3 

1 2 

Finally we’ll look at the simulated results for Valencia (home team) vs Sevilla (away team) using the estimates from the new model with the first row of the graph showing the predicted outcome and the second row showing the actual data.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 

And similarly Sevilla (home team) vs Valencia (away team).
1


Now the results are closer to the historical data as both Sevilla and Valencia are more likely to win when playing as the home team.
At this point in the modeling process I decided to try to split the skill parameter into two components, offence skill and defense skill, thinking that some teams might be good at scoring goals but at the same time be bad at keeping the opponent from scoring. This didn’t seem to result in any better fit however, perhaps because the offensive and defensive skill of a team tend to be highly related. There is however one more thing I would like to change with the model…
Modeling Match Results: Iteration 3
The data set laliga
contains data from five different seasons and an assumption of the current model is that a team has the same skill during all seasons. This is probably not a realistic assumption, teams probably differ in their yeartoyear performance. And what more, some teams do not even participate in all seasons in the laliga
data set, as a result of dropping out of the first division, as the following diagram shows:
1


The second iteration of the model was therefore modified to include the yeartoyear variability in team skill. This was done by allowing each team to have one skill parameter per season but to connect the skill parameters by using a team’s skill parameter for season $t$ in the prior distribution for that team’s skill parameter for season $t+1$ so that
for all different $t$, except the first season which is given an vague prior. Here $\sigma_{\text{season}}^2$ is a parameter estimated using the whole data set. The home and away baselines are given the same kind of priors and below is the resulting JAGS model.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 

These changes to the model unfortunately introduces quit a lot of autocorrelation when running the MCMC sampler and thus I increase the number of samples and the amount of thinning. On my setup the following run takes the better half of a lunch break (and it wouldn’t hurt to run it even a bit longer).
1 2 3 4 5 6 7 

The following graph shows the trace plot and distribution of the season_sigma
parameter.
1


Calculating and comparing the DIC of this model with the former model show no substantial difference.
1 2 

1 2 

However, I believe the assumptions of the current model (m3) are more reasonable so I’ll stick with this model. In part three of Modeling Match Results in La Liga Using a Hierarchical Bayesian Poisson Model I will use my model to complete the goals set out in the introduction. That is, ranking the teams in La Liga and predicting the outcome of future matches.