Hey team! With the amazingness that is the ‘festival of footy’ and 20 days straight of games - spare a thought for us poor modellers as we scramble to update our tips and blogs between rounds that have no distinct gap!
I’m working on a few things in fitzRoy
that might help but thought I’d share something that I’ve been working on. Orginally it was just going to be some internal code that allowed me to submit my Monash Probabilistic Tipping Comp tips from R when I updated my models.
I figured that it could be useful for others in that comp. I understand that the venn diagram of people who enter tips into that comp AND use R AND want to save 5 minutes of manual clicking is very small. But I like playing around with R. So here we are!
I’ve created the monashtipr
package. It is a simple package that provides an API for submitting your tips through R! You can view the pkgdown site for all the info but thought I’d walk through submitting my tips for the week.
Overview
There are basically two main functions. get_games
will return a data frame of the games for a particular round and submit_tips
will let you submit tips for a particular round and competition!
Submitting tips
See the steps below for how to use it in real life (this is from my own tips for Round 9).
NOTE
Please be carefull with this. While I’ve tried to test it, there is the chance to screw with your tips. I reccomend checking things manually while this is still new and not stable.
Step 1 - install the package!
You can get it from github. You’ll need devtools
if you don’t already have it.
# install.packages("devtools")
devtools::install_github("jimmyday12/monash_tipr")
library(monashtipr)
library(tidyverse)
## ── Attaching packages ──────────────────────────────────────── tidyverse 1.3.0 ──
## ✓ ggplot2 3.3.0 ✓ purrr 0.3.4
## ✓ tibble 3.0.1 ✓ dplyr 0.8.5
## ✓ tidyr 1.0.3 ✓ stringr 1.4.0
## ✓ readr 1.3.1 ✓ forcats 0.5.0
## ── Conflicts ─────────────────────────────────────────── tidyverse_conflicts() ──
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
Step 2 - do your predictions
I’m not going to step through how I do these but ultimately I end up with something like below.
predictions <- read_csv(here::here("data_files", "raw-data", "predictions.csv"))
## Parsed with column specification:
## cols(
## Day = col_character(),
## Time = col_time(format = ""),
## Round.Number = col_double(),
## Venue = col_character(),
## Home.Team = col_character(),
## Away.Team = col_character(),
## Prediction = col_double(),
## Probability = col_double(),
## Result = col_character()
## )
predictions
## # A tibble: 91 x 9
## Day Time Round.Number Venue Home.Team Away.Team Prediction Probability
## <chr> <time> <dbl> <chr> <chr> <chr> <dbl> <dbl>
## 1 Wed,… 00'00" 9 Carr… Footscray Richmond -1.9 0.481
## 2 Thu,… 00'00" 9 Pert… Carlton Hawthorn -0.9 0.491
## 3 Thu,… 00'00" 9 Gabba Melbourne Port Ade… -4 0.46
## 4 Fri,… 00'00" 9 Carr… Essendon Brisbane… -9.6 0.405
## 5 Sat,… 00'00" 9 Carr… North Me… Adelaide 9.3 0.592
## 6 Sat,… 00'00" 9 Gabba St Kilda Sydney 11.1 0.609
## 7 Sat,… 00'00" 9 Pert… West Coa… Geelong 0.9 0.509
## 8 Sun,… 00'00" 9 Carr… Gold Coa… GWS -3 0.47
## 9 Sun,… 00'00" 9 Pert… Fremantle Collingw… -6.1 0.439
## 10 Mon,… 00'00" 9 Adel… Port Ade… Footscray 16.1 0.656
## # … with 81 more rows, and 1 more variable: Result <chr>
Step 3 - get this weeks games
The first function in monashtipr
that is useful is get_games
. This returns a dataframe of the weeks games based on the round you supply. If you don’t supply a round, it will return the earliest available round for tipping.
Note you can supply your username and password as plain text but I’m storing then in my .Renviron
file. Read more about that here.
The comp needs to be one of “normal”, “gauss” or “info” (info is the probability comp).
user <- Sys.getenv("MONASH_USER")
pass = Sys.getenv("MONASH_PASS")
monash_games <- get_games(user, pass, comp = "normal")
## Login succesfull!
## Returning current rounds games below...
monash_games
## Game Ground Home Away Margin
## 1 1 Metricon Stadium W_Bulldogs Richmond NA
## 2 2 Gabba Melbourne P_Adelaide NA
## 3 3 Optus Stadium Carlton Hawthorn NA
## 4 4 Metricon Stadium Essendon Brisbane NA
## 5 5 Metricon Stadium Kangaroos Adelaide NA
## 6 6 Gabba St_Kilda Sydney NA
## 7 7 Optus Stadium W_Coast Geelong NA
## 8 8 Metricon Stadium Gold_Coast G_W_Sydney NA
## 9 9 Optus Stadium Fremantle Collingwood NA
Step 4 - Join predictions to monash games
I now need to add my predictions to the data frame of monash tips. Because my teams don’t really match up, I’ve written a quick and dirty function to replace these.
# Function to replace team names
map_names_to_monash <- function(names) {
dplyr::case_when(
names == "Footscray" ~ "W_Bulldogs",
names == "North Melbourne" ~ "Kangaroos",
names == "St Kilda" ~ "St_Kilda",
names == "West Coast" ~ "W_Coast",
names == "Gold Coast" ~ "Gold_Coast",
names == "Port Adelaide" ~ "P_Adelaide",
names == "Brisbane Lions" ~ "Brisbane",
names == "GWS" ~ "G_W_Sydney",
TRUE ~ names
)
}
predictions <- predictions %>%
filter(Round.Number == min(Round.Number)) %>%
mutate_at(c("Home.Team", "Away.Team"), map_names_to_monash) %>%
mutate(Margin = round(Prediction),
`Std. Dev.` = 40) %>%
rename(Home = Home.Team,
Away = Away.Team) %>%
select(Home, Away, Margin, `Std. Dev.`, Probability)
predictions_joined <- monash_games %>%
select(-Margin) %>%
left_join(predictions, by = c("Home", "Away"))
predictions_joined
## Game Ground Home Away Margin Std. Dev. Probability
## 1 1 Metricon Stadium W_Bulldogs Richmond -2 40 0.481
## 2 2 Gabba Melbourne P_Adelaide -4 40 0.460
## 3 3 Optus Stadium Carlton Hawthorn -1 40 0.491
## 4 4 Metricon Stadium Essendon Brisbane -10 40 0.405
## 5 5 Metricon Stadium Kangaroos Adelaide 9 40 0.592
## 6 6 Gabba St_Kilda Sydney 11 40 0.609
## 7 7 Optus Stadium W_Coast Geelong 1 40 0.509
## 8 8 Metricon Stadium Gold_Coast G_W_Sydney -3 40 0.470
## 9 9 Optus Stadium Fremantle Collingwood -6 40 0.439
Step 5 - Submit tips!
Now we’ve done that, we can submit our tips using submit_tips
. This function expects a data frame in the same format as the one returned by get_games
which is why I did the steps of renaming teams and joining my tips to that data frame.
# Submit - normal
predictions_joined %>%
select(-`Std. Dev.`, -Probability) %>%
monashtipr::submit_tips(user = user, pass = pass, comp = "normal")
## Login succesfull!
## Submitting with '.submit'
## Game Team Margin Status
## 1 1 Richmond 2 Too late! (skipped)
## 2 2 P_Adelaide 4 Updated.
## 3 3 Hawthorn 1 Updated.
## 4 4 Brisbane 10 Updated.
## 5 5 Kangaroos 9 Updated.
## 6 6 St_Kilda 11 Updated.
## 7 7 W_Coast 1 Updated.
## 8 8 G_W_Sydney 3 Updated.
## 9 9 Collingwood 6 Updated.
# Submit - gauss
predictions_joined %>%
select(-Probability) %>%
monashtipr::submit_tips(user = user, pass = pass, comp = "gauss")
## Login succesfull!
## Submitting with '.submit'
## Game Team Margin Std.Dev. Status
## 1 1 Richmond 2 40 Too late! (skipped)
## 2 2 P_Adelaide 4 40 Updated.
## 3 3 Hawthorn 1 40 Updated.
## 4 4 Brisbane 10 40 Updated.
## 5 5 Kangaroos 9 40 Updated.
## 6 6 St_Kilda 11 40 Updated.
## 7 7 W_Coast 1 40 Updated.
## 8 8 G_W_Sydney 3 40 Updated.
## 9 9 Collingwood 6 40 Updated.
# Submit - prob
predictions_joined %>%
select(-`Std. Dev.`, -Margin) %>%
monashtipr::submit_tips(user = user, pass = pass, comp = "info")
## Login succesfull!
## Submitting with '.submit'
## Game Team Probability Bestcasescore Worstcasescore Status
## 1 1 W_Bulldogs 0.481 0.05 -0.06 Too late! (skipped)
## 2 2 Melbourne 0.460 0.11 -0.12 Updated.
## 3 3 Carlton 0.491 0.03 -0.03 Updated.
## 4 4 Essendon 0.405 0.25 -0.30 Updated.
## 5 5 Kangaroos 0.592 0.24 -0.29 Updated.
## 6 6 St_Kilda 0.609 0.28 -0.35 Updated.
## 7 7 W_Coast 0.509 0.03 -0.03 Updated.
## 8 8 Gold_Coast 0.470 0.08 -0.09 Updated.
## 9 9 Fremantle 0.439 0.17 -0.19 Updated.
That’s about it. Hopefully some people get some use out it. Let me know if it works or you run into issues.