| Title: | Predict the Premier League |
|---|---|
| Description: | Provides functions to predict the outcome of Premier League games and seasons. |
| Authors: | Robin Penfold [aut, cre] |
| Maintainer: | Robin Penfold <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.4.7 |
| Built: | 2026-06-03 08:54:49 UTC |
| Source: | https://github.com/p0bs/PremPredict |
This function finds the index of the most recently played game in this Premier League season.
calc_game_latest(results)calc_game_latest(results)
results |
These are the results generated by running |
## Not run: calc_game_latest( results = data_results ) ## End(Not run)## Not run: calc_game_latest( results = data_results ) ## End(Not run)
This function calculates the points expected to be gained by each team in the remainder of this Premier League season.
calc_points_expected_remaining(games_remaining)calc_points_expected_remaining(games_remaining)
games_remaining |
These are the remaining games, with their associated model parameters, as generated by running |
## Not run: calc_points_expected_remaining( games_remaining = data_results ) ## End(Not run)## Not run: calc_points_expected_remaining( games_remaining = data_results ) ## End(Not run)
This function projects the points expected to be gained by each team across this Premier League season.
calc_points_expected_total(table_current, points_expected)calc_points_expected_total(table_current, points_expected)
table_current |
This is the current table, as generated by running |
points_expected |
These are the expected points per team across the rest of the season, as generated by running |
## Not run: calc_points_expected_total( table_current = data_table_current, points_expected = data_points_expected_remaining ) ## End(Not run)## Not run: calc_points_expected_total( table_current = data_table_current, points_expected = data_points_expected_remaining ) ## End(Not run)
This function takes the relevant outcome probabilities for a match and calculates its projected result based upon the outcome of a random number generator.
calc_points_simulated_match( data_model_parameters_unplayed_slim, randoms, number_sims, value_match )calc_points_simulated_match( data_model_parameters_unplayed_slim, randoms, number_sims, value_match )
data_model_parameters_unplayed_slim |
These are the model parameters assigned to unplayed matches in this Premier League season, as generated by |
randoms |
This is a vector of uniformly-distributed random numbers, with a length of the product of the number of remaining matches and the number of simulations. |
number_sims |
This is the number of simulations to use for each game in the remaining season. Defaults to 50,000. |
value_match |
This is the simulated match to choose within the |
## Not run: calc_points_simulated_match( data_model_parameters_unplayed_slim = data_model_parameters_unplayed, randoms = data_randoms, number_sims = value_number_sims, value_match = 1L ) ## End(Not run)## Not run: calc_points_simulated_match( data_model_parameters_unplayed_slim = data_model_parameters_unplayed, randoms = data_randoms, number_sims = value_number_sims, value_match = 1L ) ## End(Not run)
This function generates the latest standings of this Premier League season.
calc_table_current(results)calc_table_current(results)
results |
These are the results generated by running |
## Not run: calc_table_current( results = data_results ) ## End(Not run)## Not run: calc_table_current( results = data_results ) ## End(Not run)
A dataset containing the results of the Premier League from this season so far (as committed on 2025-04-21).
example_thisSeasonexample_thisSeason
A data frame with many rows (one for each game this season) and 10 variables:
A character of the index for the game in question
The integer version of number_match
The date on which the game occurred
The shortName of the team that played at home in the match
The shortName of the team that played away in the match
The goals scored by the team that played at home in the match
The goals scored by the team that played away in the match
The result of the match, as a factor of "A" (away win), "D" (draw) or "H" (home win)
A logical indicating if this game has been played yet
The calendar year in which the season ended
https://github.com/openfootball/football.json
This function retrieves the latest data on the Premier League results for a given season.
get_footballData(value_link, table_schedule, table_teams, value_yearEnd)get_footballData(value_link, table_schedule, table_teams, value_yearEnd)
value_link |
This is the link for the data on the web. For example, you could use 'https://www.football-data.co.uk/mmz4281/2526/E0.csv'. |
table_schedule |
This is the location of the schedule data, as generated through an in-built dataset or by using |
table_teams |
These are the teams in the season's Premier League, available as the |
value_yearEnd |
This is the integer required as the year in which the season ends. |
https://www.football-data.co.uk
## Not run: get_footballData( value_link = "https://www.football-data.co.uk/mmz4281/2526/E0.csv", table_schedule = schedule_thisSeason, table_teams = teams, value_yearEnd = 2026L ) ## End(Not run)## Not run: get_footballData( value_link = "https://www.football-data.co.uk/mmz4281/2526/E0.csv", table_schedule = schedule_thisSeason, table_teams = teams, value_yearEnd = 2026L ) ## End(Not run)
This function retrieves the latest data on the Premier League results for a given season.
get_openData(value_path, table_teams, value_yearEnd)get_openData(value_path, table_teams, value_yearEnd)
value_path |
This is the location of the data on GitHub. See the example below for reference and use an address of the form, 'https://raw.githubusercontent.com/openfootball/football.json/refs/heads/master/2024-25/en.1.json'. |
table_teams |
These are the teams in the season's Premier League, available as the |
value_yearEnd |
This is the integer required as the year in which the season ends. |
https://github.com/openfootball/football.json
## Not run: get_openData( value_path = "https://raw.githubusercontent.com/openfootball/football.json/refs/etc", table_teams = teams, value_yearEnd = 2025L ) ## End(Not run)## Not run: get_openData( value_path = "https://raw.githubusercontent.com/openfootball/football.json/refs/etc", table_teams = teams, value_yearEnd = 2025L ) ## End(Not run)
This function retrieves the latest data on the Premier League results for a given season.
get_openData_schedule(value_path, table_teams, value_yearEnd)get_openData_schedule(value_path, table_teams, value_yearEnd)
value_path |
This is the location of the data on GitHub. See the example below for reference and use an address of the form, 'https://raw.githubusercontent.com/openfootball/football.json/refs/heads/master/2024-25/en.1.json'. Note that this data is updated with scores later in the season. |
table_teams |
These are the teams in the season's Premier League, available as the |
value_yearEnd |
This is the integer required as the year in which the season ends. |
https://github.com/openfootball/football.json
## Not run: get_openData_schedule( value_path = "https://raw.githubusercontent.com/openfootball/football.json/refs/etc", table_teams = teams, value_yearEnd = 2025L ) ## End(Not run)## Not run: get_openData_schedule( value_path = "https://raw.githubusercontent.com/openfootball/football.json/refs/etc", table_teams = teams, value_yearEnd = 2025L ) ## End(Not run)
This function takes the latest data on this Premier League season and combines it with corresponding results from previous seasons, if desired.
get_results(results_thisSeason, seasons = 0L)get_results(results_thisSeason, seasons = 0L)
results_thisSeason |
These are the results generated by running |
seasons |
This is the integer required for the number of previous seasons to include. It defaults to zero. |
## Not run: get_results( results_thisSeason = data_thisSeason, seasons = 1L ) ## End(Not run)## Not run: get_results( results_thisSeason = data_thisSeason, seasons = 1L ) ## End(Not run)
This function takes the latest data on this Premier League season and combines it with corresponding results from previous seasons, if desired.
get_results_filtered(results, index_game_latest, lookback_rounds)get_results_filtered(results, index_game_latest, lookback_rounds)
results |
These are the results from this and possibly earlier seasons, as generated by |
index_game_latest |
This is the index of the latest game played, which can be generated by |
lookback_rounds |
This is the number of rounds of fixtures to use in a model (so 38 would represent a whole season). |
## Not run: get_results_filtered( results = data_results, index_game_latest = 280L, lookback_rounds = 38L, ) ## End(Not run)## Not run: get_results_filtered( results = data_results, index_game_latest = 280L, lookback_rounds = 38L, ) ## End(Not run)
This function takes the relevant results generated in modelling the strength of the Premier League teams and extracts the relevant parameters.
model_extract_parameters(model_output)model_extract_parameters(model_output)
model_output |
This is the output generated by |
## Not run: model_extract_parameters( model_output = data_model_output ) ## End(Not run)## Not run: model_extract_parameters( model_output = data_model_output ) ## End(Not run)
This function takes the relevant parameters from the model and assigns them to the approapriate teams in each remaining game of the season.
model_parameters_unplayed(model_parameters, results)model_parameters_unplayed(model_parameters, results)
model_parameters |
This is the output generated by |
results |
These are the results from this and possibly earlier seasons, as generated by |
## Not run: model_parameters_unplayed( model_parameters = data_model_parameters, results = data_results ) ## End(Not run)## Not run: model_parameters_unplayed( model_parameters = data_model_parameters, results = data_results ) ## End(Not run)
This function takes the relevant filtered results from the Premier League and combines it in a way that the R prediction model can recognise.
model_prepare_frame(results)model_prepare_frame(results)
results |
These are the results from this and possibly earlier seasons, as generated by |
## Not run: model_prepare_frame( results = data_results ) ## End(Not run)## Not run: model_prepare_frame( results = data_results ) ## End(Not run)
This function takes the relevant filtered results from the Premier League and uses them to model each team's capabilities, both at home and away.
model_run(modelframe)model_run(modelframe)
modelframe |
This is the modelframe generated in |
## Not run: model_run( modelframe = data_modelframe ) ## End(Not run)## Not run: model_run( modelframe = data_modelframe ) ## End(Not run)
A dataset containing the results of the Premier League from previous seasons.
previous_seasonsprevious_seasons
A data frame with many rows (one for each game in recent history that involves two current Premier League teams) and 10 variables:
A character of the index for the game in question
The integer version of number_match
The date on which the game occurred
The shortName of the team that played at home in the match
The shortName of the team that played away in the match
The goals scored by the team that played at home in the match
The goals scored by the team that played away in the match
The result of the match, as a factor of "A" (away win), "D" (draw) or "H" (home win)
A logical indicating if this game has been played yet
The calendar year in which the season ended
https://github.com/openfootball/football.json
This function prints the latest standings of this Premier League season.
print_table_current(table_latest)print_table_current(table_latest)
table_latest |
These are the latest standings generated by running |
## Not run: print_table_current( table_latest = data_calc_table_current ) ## End(Not run)## Not run: print_table_current( table_latest = data_calc_table_current ) ## End(Not run)
This function takes the likelihoods of all possible standings for all clubs over this Premier League season and reformats them for improved presentation..
reformat_outcomes(value)reformat_outcomes(value)
value |
This is the outcome value to be reformatted. |
## Not run: reformat_outcomes( value = 0.94 ) ## End(Not run)## Not run: reformat_outcomes( value = 0.94 ) ## End(Not run)
This function takes the relevant parameters from the model and assigns them to the approapriate teams in each remaining game of the season.
run_simulations( results_thisSeason, number_seasons = 0L, lookback_rounds = 19L, number_simulations = 25000L, value_seed = 120519L )run_simulations( results_thisSeason, number_seasons = 0L, lookback_rounds = 19L, number_simulations = 25000L, value_seed = 120519L )
results_thisSeason |
These are the results generated by running
|
number_seasons |
This is the integer required for the number of previous seasons to include. It defaults to zero. |
lookback_rounds |
This is the integer number of rounds of fixtures to use in a model (so 38L would represent a whole season). Defaults to half a season (that is, 19L). |
number_simulations |
This is the integer number of simulations to use for each game in the remaining season. Defaults to 25000L. |
value_seed |
This is the integer seed to use for the random numbers in the simulation. Defaults to 120519L (which, IMHO, was a great footballing day). |
## Not run: run_simulations( results_thisSeason = example_thisSeason, number_seasons = 1L, lookback_rounds = 78L, number_simulations = 25000L, value_seed = 120519L ) ## End(Not run)## Not run: run_simulations( results_thisSeason = example_thisSeason, number_seasons = 1L, lookback_rounds = 78L, number_simulations = 25000L, value_seed = 120519L ) ## End(Not run)
A dataset containing the schedule of the Premier League this.
schedule_thisSeasonschedule_thisSeason
A data frame with many rows (one for each game this season) and 6 variables:
A character of the index for the game in question
The integer version of number_match
The date on which the game occurred
The shortName of the team that played at home in the match
The shortName of the team that played away in the match
The calendar year in which the season ended
https://github.com/openfootball/football.json
This function takes the relevant parameters from the model and assigns them to the approapriate teams in each remaining game of the season.
simulate_games( data_model_parameters_unplayed, value_number_sims = 50000, value_seed = 120519L )simulate_games( data_model_parameters_unplayed, value_number_sims = 50000, value_seed = 120519L )
data_model_parameters_unplayed |
These are the model parameters assigned to unplayed games in this Premier League season, as generated by |
value_number_sims |
This is the number of simulations to use for each game in the remaining season. Defaults to 50,000. |
value_seed |
This is the seed to use for the random numbers in the simulation. Defaults to 120519 (which, IMHO, was a great footballing day). |
## Not run: simulate_games( data_model_parameters_unplayed = data_model_parameters_unplayed, value_number_sims = 1000000, value_seed = 120519L ) ## End(Not run)## Not run: simulate_games( data_model_parameters_unplayed = data_model_parameters_unplayed, value_number_sims = 1000000, value_seed = 120519L ) ## End(Not run)
This function takes the relevant data from the simulations and the current table to the likelihoods of all possible standings for all clubs over this Premier League season.
simulate_outcomes(data_standings_simulations, value_number_sims)simulate_outcomes(data_standings_simulations, value_number_sims)
data_standings_simulations |
These are the standings for each club in each scenario run, as generated by |
value_number_sims |
This is the number of simulations to use for each game in the remaining season. Defaults to 50,000. |
## Not run: simulate_outcomes( data_standings_simulations = data_standings_simulations, value_number_sims = 1000000 ) ## End(Not run)## Not run: simulate_outcomes( data_standings_simulations = data_standings_simulations, value_number_sims = 1000000 ) ## End(Not run)
This function takes the relevant data from the simulations and finds the standings for each team at the end of the season.
simulate_standings(data_game_simulations, data_table_latest)simulate_standings(data_game_simulations, data_table_latest)
data_game_simulations |
These are the outcome scenarios of the unplayed games in this Premier League season, as generated by |
data_table_latest |
These are the latest standings generated by running |
## Not run: simulate_standings( data_game_simulations = data_game_simulations, data_table_latest = data_table_latest ) ## End(Not run)## Not run: simulate_standings( data_game_simulations = data_game_simulations, data_table_latest = data_table_latest ) ## End(Not run)
A dataset containing the teams in the latest Premier League season.
teamsteams
A data frame with 20 rows (one for each team) and 4 variables:
The long name of the team in question, used in footballData
The three-letter code of the team in question
The more-readable name of the team in question
The more-readable name of the team in question, used in openData
https://www.premierleague.com/