knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
This vignette will describe basic usage of the model to predict games and generate graphics.
library(HockeyModel)
At it's most simple, we'll ask the model to retrieve the required data and predict results. You can specify a particular raw data location if you prefer by changing the data_dir parameter.
model <- updateModel(data_dir = devtools::package_file("data-raw"))
We can call this directly because the package has historical data already saved within it. This historical data can always be viewed by calling HockeyModel::scores
, in an interactive session, or more simply just scores
if the package is loaded. Of course, this will return all historical data for the NHL and WHL since their inceptions, so it may be more interesting to subset this data. For examples, scores since the start of the 2019-2020 season can be viewed by calling scores[scores$Date > as.Date("2019-10-01"),]
.
Having performed the model update and retrieved the parameters by calling model <- updateModel()
above, we can generate predictions for today's game(s).
todayOdds(params = model$params, schedule = model$schedule)
knitr::include_graphics("https://github.com/pbulsink/HockeyModel/raw/master/prediction_results/graphics/today_odds.png")
Playoff odds, president trophy odds, expected points, etc. can all be generated as well. Start by updating the predictions, then generate the images. Depending on how long it has been since predictions were generated, this may take some time.
updatePredictions(data_dir = devtools::package_file("prediction_results"), scores = model$scores, schedule = model$schedule) playoffOdds()
knitr::include_graphics("https://github.com/pbulsink/HockeyModel/raw/master/prediction_results/graphics/playoff_odds.png")
There's a playoff solver placed in the package. It works only before the playoffs start through the end of the first round, and returns a tibble of likely playoff position and progression for each team as a tidyverse::tibble
. The results aren't guaranteed to be accurate. We'll look at what these playoff odds looked like as of the start of the 2021-2022 season. We'll download the predictions file from that date so we don't have to generate it ourselves.
simulatePlayoffs(summary_results = readRDS(url("https://github.com/pbulsink/HockeyModel/raw/master/prediction_results/2021-08-12-predictions.RDS", "rb")))
po <- simulatePlayoffs(summary_results = HockeyModel::summary_results_testing, nsims = 10, cores = 2) knitr::kable(po, caption = "Playoff Simulation from the start of the 2021-2022 season")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.