knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "man/figures/README-", out.width = "100%", error = TRUE )
The goal of piratings is to calculate dynamic performance ratings for association football teams in a competitive match setting. The pi rating system takes into account the team's performance in recent matches, the well-known home advantage effect and, the fact that a win is more important than increasing the score difference. The dynamic rating system has proven to obtain superior results in predicting the outcome of association football matches.
The pi rating system was developed by Constantinou and Fenton (2013) <\doi:10.1515/jqas-2012-0036>
library(piratings) library(ggplot2) knitr::opts_chunk$set(echo = T, results = "hide")
This is a basic example which shows you how to use the package:
## example data from the European Soccer Dataset ## for the English Premier League during the seasons ## 2008/2009 to 2015/2016 data("EPL2008_2015") head(EPL2008_2015)
We prepare the function arguments:
``` {r echo = T, results = "hide", message = F}
teams <- as.matrix(EPL2008_2015[, c("home_team", "away_team")]) outcomes <- as.matrix(EPL2008_2015[, c("home_goals", "away_goals")])
grid <- optimize_pi_ratings(teams, outcomes, seq(0.04, 0.08, 0.005), seq(0.3, 0.7, 0.05))
Finally, we can plot the result of the grid optimization using ggplot2: ```r ## we plot this grid using the ggplot2 library library(ggplot2) ggplot(data = grid, aes(x = lambda, y = gamma, fill = mean.squared.error)) + geom_tile() + scale_fill_gradient2(low = "blue", mid = "white", high = "red", midpoint = 2.668) + labs(x = "lambda", y = "gamma", title = "grid optimization", fill = "Mean \nsquared \nerror") + theme(plot.title = element_text(hjust = 0.5)) ## we find the optimal parameter settings to be ## lambda = 0.06 and gamma = 0.6 piratings <- calculate_pi_ratings(teams, outcomes, 0.06, 0.6) tail(piratings)
Contains information from the European Soccer Database, which is made available here under the Open Database License (ODbL) .
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.