I have been meaning to write about my take on using Poisson regression to predict football results for a while, so here we go. Poisson regression is one of the earliest statistical methods used for predicting football results. The goal here is to use available data to to say something about how many goals a team is expected to score and from that calculate the probabilities for different match outcomes.

**The Poisson distribution**

The Poisson distribution is a probability distribution that can be used to model data that can be counted (i.e something that can happen 0, 1, 2, 3, … times). If we know the number of times something is expected to happen, we can find the probabilities that it happens any number of times. For example if we know something is expected to happen 4 times, we can calculate the probabilities that it happens 0, 1, 2, … times.

It turns out that the number of goals a team scores in a football match are approximately Poisson distributed. This means we have a method of assigning probabilities to the number of goals in a match and from this we can find probabilities for different match results. Note that I write that goals are approximately Poisson. The Poisson distribution does not always perfectly describe the number of goals in a match. It sometimes over or under estimates the number of goals, and some football leagues seems fit the Poisson distribution better than others. Anyway, the Poisson distribution seems to be an OK approximation.

**The regression model**

To be able to find the probabilities for different number of goals we need to find the expected number of goals L (It is customary to denote the expectation in a Poisson distribution by the Greek letter lambda, but WordPress seem to have problems with greek letters so i call i L instead). This is where the regression method comes in. With regression we can estimate lambda conditioned on certain variables. The most obvious variable to look at is which team is playing. Manchester United obviously makes more goals than Wigan. The second thing we want to take into account is who the opponent is. Some teams are expected to concede fewer goals, while others are expected to let in more goals. The third thing we want to take into account is home field advantage.

Written in the language of regression models this becomes

log(L) = mu + home + team_{i} + opponent_{j}

The *mu* is the overall mean number of goals. The *home* is the effect on number of goals a team has by playing at home. Team_{i} is the effect of team number *i*, opponent_{j} is the effect of team *j*.

(Note: Some descriptions of the Poisson regression model on football data uses the terms *offensive* and *defensive* strength to describe what I have called *team* and *opponent*. The reason I prefer the terms I use here is because it makes it a bit easier to understand later when we look at the data set.)

The logarithm on the left hand side is called the link function. I will not dwell much on what a link function is, but the short story is that they ensure that the parameter we try to estimate don’t fall outside its domain. In this case it ensures us that we never get negative expected number of goals.

**Data
**In my example I will use data from football-data.co.uk. What data you would want to use is up to yourself. Typically you could choose to use data from the last year or the least season, but that is totally up to you to decide.

Each of the terms on the right hand side of the equation (except for *mu*) corresponds to a columns in a table, so we need to fix our data a bit before we proceed with fitting the model. Each match is essentially two observations, one for how many goals the home team scores, the second how many the away team scores. Basically, each match need two rows in our data set, not just one.

Doing the fix is an easy thing to do in excel or Libre Office Calc. We take the data rows (i.e. the matches) we want to use and duplicate them. Then we need to switch the away team and away goals columns so they become the same as the home team column. We also need a column to indicate the home team. Here is an example on how it will look like:

In the next part I will fit the actual model, calculate probabilities and describe how we can make predictions using R.

Hi man,

My name’s Marco and I’m spanish. I’ve been seeking for poisson formulas for a long time, and I’ve some spreadsheets made by me, but the search still continues. A few days ago I found your page, and it throws a bit of light over my studies, but, since I don’t understand R, I work on Excel. May be is so rudimentary but it works for me!

Now, I hope you can help me with some points of the log(L) formula here:

MU: Is the overall mean of goals. Okay, Goals for? Goals against? Goals of the team I am studying? Goals of the league / championship?

HOME: The home is the effect on number of goals a team has by playing at home. Does it mean: goals for at home / goals for away?

TEAM & OPONNENT: This I think is clear. As you said, is attacking strength and deffense strength.

So, as I understand, for example:

City – Tottenham (Next Saturday 18 October 2014)

70 matches, 196 goals in Premier League. Goals per match: 2.80

*** MU = 2.80

HOME LEAGUE GOALS: 1.54

AWAY LEAGUE GOALS: 1.26

*** Home advantage (effect): 1.54/1.26 = 1.22

*** TEAM (attacking strength of M.City): 0.864

*** OPPONENT (Deffense strength of Tottenham): 0.649

Then:

Log(L) = 2.80 + 1.22 + 0.864 + 0.649 = 0.7429

So, 0,7429 is the logarythm. Must I then do the exponent? e^0.7429?

And, is 0,7429 (or the e^07429) the number of goals expected for Manchester City?

Thanks a lot, I hope you understand it at all even though my english…

If you want to answer via e-mail: *******

Or if you want here, I’ll be so grateful wherever you answer!

While it is convenient to think about the MU as the overall mean of goals scored, it is not entirely right. Remember that these parameters are estimated in terms of the logarithm of the number of goals. It is perhaps more accurately to describe it at the geometric mean. Therefore you cant just estimate MU and home parameter like you did. Also, ignoring logarithms, I am not sure about the way you estimate the home field advantage (HFA). In the context of linear models (models where add things together) it is more intuitive to think of HFA as the difference instead of the ratio.

And yes, you have to exponentiate the end result to get the correct estimate.

Hi. Thanks for you site. Very nice article can you give any example wuth real market odds?

Thanks for the answer, what type of Log do you use? log10? LN?

R uses the natural log by default, so that is the one used here.

how did you calculate the overall goals scored in R

I explain how you can do predictions in part 2:

http://opisthokonta.net/?p=296

for the expected goals score form the two teams how will i go about it

also i want to know how to predict the probabity given the fixed odds of the teams and also market odds

I am not an expert on betting and odds markets etc. but you could try to just add the odds into the model, instead of using the teams. I did use the odds as predictors in my post on using decision trees with adaptive boosting:

http://opisthokonta.net/?p=809

I love that ! But it’s possible to do don’t write each match in excel ( for exemple ) just write the number of Goal for a team ( home and away ) here in your data , you write all matches , and if we want to do a lot a league it’s so long !

Can you explain in more détails how you have download R package for have boxplot ( part 2 ) , thank you for you answer ! =)

This method will not work with just having the total number of goals scored for each team. What makes this regression model interesting is that it takes into account both the team and opposition in each game. Fortunately, you don’t have to punch in the data yourself, you can take a look at this page for some links to downloadable data sets.

There are no boxplots in part 2, but all plots are made using the built-in plotting commands in R.

How big the data should be? Do you use only 2 past matches or collect data over several years?

You should use as much data as possible. You could use the Dixon-Coles weighting method which I have described here. See also this post where I show that you can improve prediction by also including data outside of the league you are going to predict.

How do you find the Home effect column?

You have to create it yourself.

If you are using R, you can take a look at the first block of code in this post:

http://opisthokonta.net/?p=927