An Introduction to the worldfootballR R Package | by Jason Zivkovic | Towards Data Science

With the creation of the worldfootballR R package; a new R package to aid in the extraction of Football (Soccer) data from fbref.com, I will be trying to highlight ways the package can be used.
The package released is currently a development version and only available on GitHub, but will be made available on CRAN once user testing has been completed.
In this piece, I will analyse Liverpool’s use of substitutions in the English Premier League (EPL) over the last three seasons to understand whether there has been a change in behaviour in the current season, and whether there was a change around the COVID outbreak and subsequent pause taken during the 2019–2020 season.
Data was extracted for the last two and a half seasons, up to the end of Matchweek 17 in the 2020/21 EPL season.
The package has a function called get_match_summary which extracts match summary (goals, subs, red/yellow cards) data for a match URLs (along with other metadata regarding the matches.
To get the match URLs, another function — get_match_urls - can be used, which accepts a country code (“ENG” for England), gender and the year the season(s) ended, and returns a vector of match URLs.
devtools::install_github("JaseZiv/worldfootballR")library(worldfootballR)match_urls <- get_match_urls(country = "ENG", gender = "M", season_end_year = c(2019:2021))match_summaries <- get_match_summary(match_url = match_urls)
This is what the output of the function looks like:
Now that the package instructions are out of the way, we turn our attention to the analysis of substitution data in the Premier League, and specifically ask the question, has there been a change in Liverpool’s substitution behaviour.
The analysis was loosely inspired by a piece done by FiveThirtyEight on Bundesliga team susbstitutions before and after the league restart.
In all seasons analysed, Liverpool make slightly more subs in a season compared to the league average, with the average number of subs in a season peaking after the restart last season to 4.67 subs per game. The current season has seen this revert to pre-COVID levels.
Interestingly, while Liverpool’s first sub typically comes slightly later than the league average (56 minutes compared to 52 minutes), the Reds have stuck close to their first sub time after the season restart, while the league average has reverted back to pre-COVID levels, reversing the league-wide trend.
The Reds made 12% of their substitutions in the first hour during the combined 2019–20 season (double that of their 2018–19 season), and this season has seen this percentage again double through the first 16 games. The league however has experienced a direct reversal of this trend, spiking to 24% during the restarted part of the 19/20 season, and settling back down at the league average for the previous seasons.
It will be interesting to see how this trend continues throughout the latter parts of this season.
This was the first in a series of analyses that will make use of various data extraction functions in the worldfootballR package.
Here we saw that Liverpool are making their first substitution earlier than their previous trends, and are deviating from the league averages. I will follow this analysis to see if this trend has continued.
As always, any questions/comments about the piece or the R package, feel free to reach out through the regular channels.
GO REDS!!
The full version of this post appears here on dontblamethedata.com