Expected Goals and Liverpool — An Intro to worldfootballR

This post continues a series of posts that aims to showcase the new worldfootballR R package for extracting world football (soccer) data from popular data site fbref.com.

Jason Zivkovic
Analytics Vidhya

--

worldfootballR R package

This post will aim to analyse expected goals and actual goals, primarily focusing on Liverpool.

This season sees Liverpool in a struggle with a few teams in the hope of going back-to-back. I want to see if there is a difference in how the Reds are scoring this season as opposed to the last few seasons.

Extract Data Using worldfootballR

As always, we first start by installing the package if you haven’t already done so and loading any libraries necessary for the analysis.

devtools::install_github("JaseZiv/worldfootballR")
library(tidyverse)
library(worldfootballR)

To get match results, including goals and xG data, we can use the function get_match_results(). Because we want it for the Men’s Premier League, we pass the following values to the function’s arguments:

xg_data <- get_match_results(country = "ENG", gender = "M", season_end_year = c(2018:2021))

We can also see what the data looks like:

Output of get_match_results()

To get season league tables (which contains goals scored for and against, and expected goals), we can use the get_season_team_stats() functions, and pass the following values to the function arguments:

end_season_summary <- get_season_team_stats(country = "ENG", gender = "M", season_end_year = c(2018:2021), stat_type = "league_table")

And inspect the data:

Output of get_season_team_stats()

The Analysis

So what are expected goals? From Opta Sports;

EXPECTED GOALS (XG) MEASURES THE QUALITY OF A SHOT BASED ON SEVERAL VARIABLES SUCH AS ASSIST TYPE, SHOT ANGLE AND DISTANCE FROM GOAL, WHETHER IT WAS A HEADED SHOT AND WHETHER IT WAS DEFINED AS A BIG CHANCE.

ADDING UP A PLAYER OR TEAM’S EXPECTED GOALS CAN GIVE US AN INDICATION OF HOW MANY GOALS A PLAYER OR TEAM SHOULD HAVE SCORED ON AVERAGE, GIVEN THE SHOTS THEY HAVE TAKEN.

Why are we focusing on expected goals in this post?

Well it can be seen below that for the 2017/18 to 2019/20 seasons, the more teams scored above their expected goals tally, the more points they tended to finish the season on, indicating a fairly strong positive relationship.

How are the Reds tracking?

Which leads us to Liverpool. Below we can chart Liverpool’s cumulative progress after each match played for the last four seasons and can see that in each of the three seasons before the current season, the Reds outperformed their expected goals tally, with last season’s championship team exceeding their expected goals total for the whole season.

This current season, other than the 7–0 drubbing (xG of 2.2) against Crystal Palace at Selhurst Park, Liverpool’s goals tally has closely tracked the expected goals. The Reds marksmen just aren’t able to convert those guilt edge chances this season, which might explain the struggle at the top.

Wrap Up

This was the second post in a series of analyses that will make use of various data extraction functions in the worldfootballR package.

Here we saw that Liverpool appeared to have regressed to the mean somewhat and are struggling to score much higher than they’re expected, based on their shots taken. This is in contrast to the previous three seasons, where the goals scored outpaced the expected goals.

As always, any questions/comments about the piece or the R package, feel free to reach out through the regular channels.

The full version of this post appears here on dontblamethedata.com

--

--