simulate_nfl {nflseedR} | R Documentation |
Simulate an NFL Season
Description
This function simulates a given NFL season multiple times using custom functions to estimate and simulate game results and computes the outcome of the given season including playoffs and draft order. It is possible to run the function in parallel processes by calling the appropriate plan. Progress updates can be activated by calling handlers before the start of the simulations. Please see the below given section "Details" for further information.
Usage
simulate_nfl(
nfl_season = NULL,
process_games = NULL,
...,
playoff_seeds = ifelse(nfl_season >= 2020, 7, 6),
if_ended_today = FALSE,
fresh_season = FALSE,
fresh_playoffs = FALSE,
tiebreaker_depth = 3,
test_week = NULL,
simulations = 1000,
sims_per_round = max(ceiling(simulations/future::availableCores() * 2), 100),
.debug = FALSE,
print_summary = FALSE,
sim_include = c("DRAFT", "REG", "POST")
)
Arguments
nfl_season |
Season to simulate |
process_games |
A function to estimate and simulate the results of games. Uses team, schedule, and week number as arguments. |
... |
Additional parameters passed on to the function |
playoff_seeds |
Number of playoff teams per conference (increased in 2020 from 6 to 7). |
if_ended_today |
Either |
fresh_season |
Either |
fresh_playoffs |
Either |
tiebreaker_depth |
A single value equal to 1, 2, or 3. The default is 3. The value controls the depth of tiebreakers that shall be applied. The deepest currently implemented tiebreaker is strength of schedule. The following values are valid:
|
test_week |
Aborts after the simulator reaches this week and returns the results from your process games call. |
simulations |
Equals the number of times the given NFL season shall be simulated |
sims_per_round |
The number of |
.debug |
Either |
print_summary |
If |
sim_include |
One of
|
Details
More Speed Using Parallel Processing
We recommend choosing a default parallel processing method and saving it as an environment variable in the R user profile to make sure all futures will be resolved with the chosen method by default. This can be done by following the below given steps.
First, run the following line and the user profile should be opened automatically. If you haven't saved any environment variables yet, this will be an empty file.
usethis::edit_r_environ()
In the opened file add the next line, then save the file and restart your R session. Please note that this example sets "multisession" as default. For most users this should be the appropriate plan but please make sure it truly is.
R_FUTURE_PLAN="multisession"
After the session is freshly restarted please check if the above method worked
by running the next line. If the output is FALSE
you successfully set up a
default non-sequential future::plan()
. If the output is TRUE
all functions
will behave like they were called with purrr::map()
and NOT in multisession.
inherits(future::plan(), "sequential")
For more information on possible plans please see the future package Readme.
Get Progress Updates while Functions are Running
Most nflfastR functions are able to show progress updates
using progressr::progressor()
if they are turned on before the function is
called. There are at least two basic ways to do this by either activating
progress updates globally (for the current session) with
progressr::handlers(global = TRUE)
or by piping the function call into progressr::with_progress()
:
simulate_nfl(2020, fresh_season = TRUE) %>% progressr::with_progress()
For more information how to work with progress handlers please see progressr::progressr.
Value
An nflseedR_simulation
object containing a list of 6 data frames
data frames with the results of all simulated games,
the final standings in each simulated season (incl. playoffs and draft order),
summary statistics across all simulated seasons, and the simulation parameters. For a full list,
please see the package website.
See Also
The examples on the package website
The method summary.nflseedR_simulation()
that creates a pretty html summary table.
Examples
library(nflseedR)
# Activate progress updates
# progressr::handlers(global = TRUE)
# Parallel processing can be activated via the following line
# future::plan("multisession")
try({#to avoid CRAN test problems
# Simulate the season 4 times in 2 rounds
sim <- nflseedR::simulate_nfl(
nfl_season = 2020,
fresh_season = TRUE,
simulations = 4,
sims_per_round = 2
)
# Overview output
dplyr::glimpse(sim)
})