Overview
Fitba – n. Football; The Beautiful Game
fitba (Functions InTended for footBall Analytics) is a package for carrying out simple football/soccer/fitba analytics in R. Right now it only includes a small handful of functions for tasks like calculating simple team ratings and strength of schedule, but there’s plenty of room for growth!
So far all functions rely on the use of worldfootballR for getting the FBref data that is required for each process. The intention isn’t that the package should strictly be an extension of worldfootballR, but it is an excellent package that makes it much easier to extract football data from sites like FBref & Transfermarkt, so it makes sense to work with it.
Installation
You can install the development version of fitba from GitHub with:
# install.packages("devtools")
devtools::install_github("Paulj1989/fitba")
Usage
You can calculate team ratings using the calculate_team_ratings()
function.
team_ratings <-
worldfootballR::fb_season_team_stats(
country = "ENG", gender = "M", season_end_year = 2024,
stat_type = "standard", tier = "1st"
) |>
fitba::calculate_team_ratings()
Strength of Schedule (SOS) can be calculated by first bringing together the get_fixtures()
and calculate_team_ratings()
functions, with data from worldfootballR, before using calculate_sos()
to compute SOS values for all teams.
remaining_schedule <-
worldfootballR::fb_match_results(
country = "ENG", gender = "M", season_end_year = 2024
) |>
fitba::get_fixtures(remaining = TRUE)
team_ratings <-
worldfootballR::fb_season_team_stats(
country = "ENG", gender = "M", season_end_year = 2024,
stat_type = "standard", tier = "1st"
) |>
fitba::calculate_team_ratings()
fitba::calculate_sos(
ratings = team_ratings,
schedule = remaining_schedule
)