top of page

Calculating the probability of the number of tries scored in an NRL game using the Poisson Distribution

Apr 25

13 min read

1

10

0



In the NRL one of the many markets that are capable of being framed is how many tries each team will score in a game. Utilising the Poisson Distribution and some Python coding it is possible to determine the probability that a team will score for example, more than 3.5 tries or less than 3.5 tries.


So, what is the Poisson Distribution?


The Poisson Distribution can determine the probability of k events occurring if the average number of times that event occurs is known.


For instance, if an NRL team scores an average of 4 tries a game, is it possible to determine the probability that the team will score 2 tries, or 7 tries.


It is given by the formula:




Where:

P(X = k) is the probability of an event occurring k times.

e is the base natural logarithim

lambda is the average rate of occurrence of events

and

k is the number of events that occur



Python is useful in the sense that is has the scipy library that has an inbuilt function for calculating the poisson probability of an event occurring if the mean is known.


The first thing that needs to be undertaken however is to determine the average number of tries each team scores.


Last year's data is shown here:




The following Python code reads in the data from csv and stores each team's average number of tries in a dictionary called average_tries_dict.


average_tries_dict = {}

 

 

df = pd.read_csv("path_to_csv_goes_here")

 

 

for index, row in df.iterrows():

    average_tries = row["Tries"]/row["Games"]

    team = row["Team"]

    average_tries_dict[team] = average_tries

print(average_tries_dict)



The average tries dictionary can be seen here:


{'Roosters': 5.222222222222222,

'Storm': 5.0,

'Sharks': 4.481481481481482,

'Cowboys': 4.615384615384615,

'Sea Eagles': 4.538461538461538,

'Panthers': 4.148148148148148,

'Eels': 4.208333333333333,

'Dolphins': 4.125,

'Bulldogs': 3.88,

'Broncos': 3.8333333333333335,

'Rabbitohs': 3.7916666666666665,

'Warriors': 3.75,

'Titans': 3.7083333333333335,

'Dragons': 3.7083333333333335,

'Knights': 3.32,

'Raiders': 3.4166666666666665,

'Wests Tigers': 3.4166666666666665}


Storing each team's average number of tries in a variable is achieved by the following code:

 

storm_tries = average_tries_dict.get("Storm")

sharks_tries = average_tries_dict.get("Sharks")

cowboys_tries = average_tries_dict.get("Cowboys")

seaeagles_tries = average_tries_dict.get("Sea Eagles")

panthers_tries = average_tries_dict.get("Panthers")

eels_tries = average_tries_dict.get("Eels")

dolphins_tries = average_tries_dict.get("Dolphins")

bulldogs_tries = average_tries_dict.get("Bulldogs")

broncos_tries = average_tries_dict.get("Broncos")

rabbitohs_tries = average_tries_dict.get("Rabbitohs")

warriors_tries = average_tries_dict.get("Warriors")

titans_tries = average_tries_dict.get("Titans")

dragons_tries = average_tries_dict.get("Dragons")

knights_tries = average_tries_dict.get("Knights")

raiders_tries = average_tries_dict.get("Raiders")

tigers_tries = average_tries_dict.get("Wests Tigers")

roosters_tries = average_tries_dict.get("Roosters")



The following Try Line markets were framed this week:


storm_try_line = 5.5

sharks_try_line = 4.5

cowboys_try_line = 4.5

seaeagles_try_line = 3.5

panthers_try_line = 4.5

eels_try_line = 0

dolphins_try_line = 3.5

bulldogs_try_line = 3.5

broncos_try_line = 2.5

rabbitohs_try_line = 2.5

warriors_try_line = 4.5

titans_try_line = 3.5

dragons_try_line = 3.5

knights_try_line = 2.5

raiders_try_line = 4.5

tigers_try_line = 3.5

roosters_try_line = 4.5


Note that the Eels are not playing this week so that variable is set to 0.



Utilising the SciPy library, the probability that an event will occur less than k times given an average is calculated utilising the following formula:




poisson.cdf(k=given number of events, mu=average number of events)




The probability that an event will occur more than k times is simply: 1 minus the abovementioned formula.



1 - poisson.cdf(k=given number of events, mu=average number of events)



In the Storm, Rabbitohs game scheduled for Friday night the market is framed around whether the Storm will score more or less than 5.5 tries and the Rabbitohs will score more or less than 2.5 tries.


# Storm to Score More

probability = 1 - poisson.cdf(k=storm_try_line, mu=storm_tries)

print("The probability that the Storm will score more than "+ str(storm_try_line) + " tries against " + storm_opposition + " is " + str(probability))

 

# Storm to Score Less

probability = poisson.cdf(k=storm_try_line, mu=storm_tries)

print("The probability that the Storm will score less than "+ str(storm_try_line) + " tries against " + storm_opposition + " is " + str(probability))

 

 

# Rabbitohs to Score More

probability = 1 - poisson.cdf(k=rabbitohs_try_line, mu=rabbitohs_tries)

print("The probability that the Rabbitohs will score more than "+ str(rabbitohs_try_line) + " tries against " + rabbitohs_opposition + " is " + str(probability))

 

 

# Rabbitohs to Score Less

probability = poisson.cdf(k=rabbitohs_try_line, mu=rabbitohs_tries)

print("The probability that the Rabbitohs will score less than "+ str(rabbitohs_try_line) + " tries against " + rabbitohs_opposition + " is " + str(probability))


The probabilities are shown below:


The probability that the Storm will score more than 5.5 tries against Rabbitohs is 0.38403934516693705


The probability that the Storm will score less than 5.5 tries against Rabbitohs is 0.615960654833063


The probability that the Rabbitohs will score more than 2.5 tries against Storm is 0.7297546896539465


The probability that the Rabbitohs will score less than 2.5 tries against Storm is 0.2702453103460535


So, whilst the average number of tries the Storm scored per game last season was 5 the probability that they will score more than 5.5 is 0.384 and the probability that they will score less than 5.5 tries is 0.616.


And, whilst the average number of tries the Rabbitohs scored per game last season was 3.79 the probability that they will score more than 2.5 tries is 0.730 and the probability that they will score less than 2.5 tries is 0.270.



Please note that average number of tries were calculated utilising only last year's data and the code is for demonstration purposes only.


The probabilities for the round are below:




Full Script:


import pandas as pd

 

from scipy.stats import poisson

 

storm_try_line = 5.5

sharks_try_line = 4.5

cowboys_try_line = 4.5

seaeagles_try_line = 3.5

panthers_try_line = 4.5

eels_try_line = 0

dolphins_try_line = 3.5

bulldogs_try_line = 3.5

broncos_try_line = 2.5

rabbitohs_try_line = 2.5

warriors_try_line = 4.5

titans_try_line = 3.5

dragons_try_line = 3.5

knights_try_line = 2.5

raiders_try_line = 4.5

tigers_try_line = 3.5

roosters_try_line = 4.5

 

storm_opposition = "Rabbitohs"

rabbitohs_opposition = "Storm"

roosters_opposition = "Dragons"

dragons_opposition = "Roosters"

warriors_opposition = "Knights"

knights_opposition = "Warriors"

broncos_opposition = "Bulldogs"

bulldogs_opposition = "Broncos"

cowboys_opposition = "Titans"

titans_opposition = "Cowboys"

panthers_opposition = "Sea Eagles"

seaeagles_opposition = "Panthers"

raiders_opposition = "Dolphins"

dolphins_opposition = "Raiders"

tigers_opposition = "Sharks"

sharks_opposition = "Tigers"

 

 

 

 

average_tries_dict = {}

 

 

df = pd.read_csv("yourpathgoeshere”)

 

 

for index, row in df.iterrows():

    average_tries = row["Tries"]/row["Games"]

    team = row["Team"]

    average_tries_dict[team] = average_tries

print(average_tries_dict)

 

storm_tries = average_tries_dict.get("Storm")

sharks_tries = average_tries_dict.get("Sharks")

cowboys_tries = average_tries_dict.get("Cowboys")

seaeagles_tries = average_tries_dict.get("Sea Eagles")

panthers_tries = average_tries_dict.get("Panthers")

eels_tries = average_tries_dict.get("Eels")

dolphins_tries = average_tries_dict.get("Dolphins")

bulldogs_tries = average_tries_dict.get("Bulldogs")

broncos_tries = average_tries_dict.get("Broncos")

rabbitohs_tries = average_tries_dict.get("Rabbitohs")

warriors_tries = average_tries_dict.get("Warriors")

titans_tries = average_tries_dict.get("Titans")

dragons_tries = average_tries_dict.get("Dragons")

knights_tries = average_tries_dict.get("Knights")

raiders_tries = average_tries_dict.get("Raiders")

tigers_tries = average_tries_dict.get("Wests Tigers")

roosters_tries = average_tries_dict.get("Roosters")

 

 

# Storm To Score More

probability = 1 - poisson.cdf(k=storm_try_line, mu=storm_tries)

print("The probability that the Storm will score more than "+ str(storm_try_line) + " tries against " + storm_opposition + " is " + str(probability))

 

# Storm to Score Less

probability = poisson.cdf(k=storm_try_line, mu=storm_tries)

print("The probability that the Storm will score less than "+ str(storm_try_line) + " tries against " + storm_opposition + " is " + str(probability))

 

 

# Rabbitohs to Score More

probability = 1 - poisson.cdf(k=rabbitohs_try_line, mu=rabbitohs_tries)

print("The probability that the Rabbitohs will score more than "+ str(rabbitohs_try_line) + " tries against " + rabbitohs_opposition + " is " + str(probability))

 

 

# Rabbitohs to Score Less

probability = poisson.cdf(k=rabbitohs_try_line, mu=rabbitohs_tries)

print("The probability that the Rabbitohs will score less than "+ str(rabbitohs_try_line) + " tries against " + rabbitohs_opposition + " is " + str(probability))

 

 

# Roosters to Score More

probability = 1 - poisson.cdf(k=roosters_try_line, mu=roosters_tries)

print("The probability that the Roosters will score more than "+ str(roosters_try_line) + " tries against " + roosters_opposition + " is " + str(probability))

 

 

# Roosters to Score Less

probability = poisson.cdf(k=roosters_try_line, mu=roosters_tries)

print("The probability that the Roosters will score less than "+ str(roosters_try_line) + " tries against " + roosters_opposition + " is " + str(probability))

 

 

# Dragons to Score More

probability = 1 - poisson.cdf(k=dragons_try_line, mu=dragons_tries)

print("The probability that the Dragons will score more than "+ str(dragons_try_line) + " tries against " + dragons_opposition + " is " + str(probability))

 

 

# Dragons to Score Less

probability = poisson.cdf(k=dragons_try_line, mu=dragons_tries)

print("The probability that the Dragons will score less than "+ str(dragons_try_line) + " tries against " + dragons_opposition + " is " + str(probability))

 

 

# Warriors to Score More

probability = 1 - poisson.cdf(k=warriors_try_line, mu=warriors_tries)

print("The probability that the Warriors will score more than "+ str(warriors_try_line) + " tries against " + warriors_opposition + " is " + str(probability))

 

 

# Warriors to Score Less

probability = poisson.cdf(k=warriors_try_line, mu=warriors_tries)

print("The probability that the Warriors will score less than "+ str(warriors_try_line) + " tries against " + warriors_opposition + " is " + str(probability))

 

# Knights to Score More

probability = 1 - poisson.cdf(k=knights_try_line, mu=knights_tries)

print("The probability that the Knights will score more than "+ str(knights_try_line) + " tries against " + knights_opposition + " is " + str(probability))

 

 

# Knights to Score Less

probability = poisson.cdf(k=knights_try_line, mu=knights_tries)

print("The probability that the Knights will score less than "+ str(knights_try_line) + " tries against " + knights_opposition + " is " + str(probability))

 

# broncos to Score More

probability = 1 - poisson.cdf(k=broncos_try_line, mu=broncos_tries)

print("The probability that the broncos will score more than "+ str(broncos_try_line) + " tries against " + broncos_opposition + " is " + str(probability))

 

 

# broncos to Score Less

probability = poisson.cdf(k=broncos_try_line, mu=broncos_tries)

print("The probability that the broncos will score less than "+ str(broncos_try_line) + " tries against " + broncos_opposition + " is " + str(probability))

 

# bulldogs to Score More

probability = 1 - poisson.cdf(k=bulldogs_try_line, mu=bulldogs_tries)

print("The probability that the bulldogs will score more than "+ str(bulldogs_try_line) + " tries against " + bulldogs_opposition + " is " + str(probability))

 

 

# bulldogs to Score Less

probability = poisson.cdf(k=bulldogs_try_line, mu=bulldogs_tries)

print("The probability that the bulldogs will score less than "+ str(bulldogs_try_line) + " tries against " + bulldogs_opposition + " is " + str(probability))

 

# cowboys to Score More

probability = 1 - poisson.cdf(k=cowboys_try_line, mu=cowboys_tries)

print("The probability that the cowboys will score more than "+ str(cowboys_try_line) + " tries against " + cowboys_opposition + " is " + str(probability))

 

 

# cowboys to Score Less

probability = poisson.cdf(k=cowboys_try_line, mu=cowboys_tries)

print("The probability that the cowboys will score less than "+ str(cowboys_try_line) + " tries against " + cowboys_opposition + " is " + str(probability))

 

# titans to Score More

probability = 1 - poisson.cdf(k=titans_try_line, mu=titans_tries)

print("The probability that the titans will score more than "+ str(titans_try_line) + " tries against " + titans_opposition + " is " + str(probability))

 

 

# titans to Score Less

probability = poisson.cdf(k=titans_try_line, mu=titans_tries)

print("The probability that the titans will score less than "+ str(titans_try_line) + " tries against " + titans_opposition + " is " + str(probability))

 

# panthers to Score More

probability = 1 - poisson.cdf(k=panthers_try_line, mu=panthers_tries)

print("The probability that the panthers will score more than "+ str(panthers_try_line) + " tries against " + panthers_opposition + " is " + str(probability))

 

 

# panthers to Score Less

probability = poisson.cdf(k=panthers_try_line, mu=panthers_tries)

print("The probability that the panthers will score less than "+ str(panthers_try_line) + " tries against " + panthers_opposition + " is " + str(probability))

 

# seaeagles to Score More

probability = 1 - poisson.cdf(k=seaeagles_try_line, mu=seaeagles_tries)

print("The probability that the seaeagles will score more than "+ str(seaeagles_try_line) + " tries against " + seaeagles_opposition + " is " + str(probability))

 

 

# seaeagles to Score Less

probability = poisson.cdf(k=seaeagles_try_line, mu=seaeagles_tries)

print("The probability that the seaeagles will score less than "+ str(seaeagles_try_line) + " tries against " + seaeagles_opposition + " is " + str(probability))

 

# raiders to Score More

probability = 1 - poisson.cdf(k=raiders_try_line, mu=raiders_tries)

print("The probability that the raiders will score more than "+ str(raiders_try_line) + " tries against " + raiders_opposition + " is " + str(probability))

 

 

# raiders to Score Less

probability = poisson.cdf(k=raiders_try_line, mu=raiders_tries)

print("The probability that the raiders will score less than "+ str(raiders_try_line) + " tries against " + raiders_opposition + " is " + str(probability))

 

# dolphins to Score More

probability = 1 - poisson.cdf(k=dolphins_try_line, mu=dolphins_tries)

print("The probability that the dolphins will score more than "+ str(dolphins_try_line) + " tries against " + dolphins_opposition + " is " + str(probability))

 

 

# dolphins to Score Less

probability = poisson.cdf(k=dolphins_try_line, mu=dolphins_tries)

print("The probability that the dolphins will score less than "+ str(dolphins_try_line) + " tries against " + dolphins_opposition + " is " + str(probability))

 

# tigers to Score More

probability = 1 - poisson.cdf(k=tigers_try_line, mu=tigers_tries)

print("The probability that the tigers will score more than "+ str(tigers_try_line) + " tries against " + tigers_opposition + " is " + str(probability))

 

 

# tigers to Score Less

probability = poisson.cdf(k=tigers_try_line, mu=tigers_tries)

print("The probability that the tigers will score less than "+ str(tigers_try_line) + " tries against " + tigers_opposition + " is " + str(probability))

 

# sharks to Score More

probability = 1 - poisson.cdf(k=sharks_try_line, mu=sharks_tries)

print("The probability that the sharks will score more than "+ str(sharks_try_line) + " tries against " + sharks_opposition + " is " + str(probability))

 

 

# sharks to Score Less

probability = poisson.cdf(k=sharks_try_line, mu=sharks_tries)

print("The probability that the sharks will score less than "+ str(sharks_try_line) + " tries against " + sharks_opposition + " is " + str(probability))

 

Apr 25

13 min read

1

10

0

Related Posts

Comments

Share Your ThoughtsBe the first to write a comment.
bottom of page