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.
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")
)
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.
Season to simulate
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 process_games
.
Number of playoff teams per conference (increased in 2020 from 6 to 7).
Either TRUE
or FALSE
. If TRUE, ignore remaining regular
season games and cut to playoffs based on current regular season data.
Either TRUE
or FALSE
. Whether to blank out all game results
and simulate the the season from scratch (TRUE) or take game results so far as a given
and only simulate the rest (FALSE).
Either TRUE
or FALSE
. Whether to blank out all playoff
game results and simulate the postseason from scratch (TRUE) or take game results so far
as a given and only simulate the rest (FALSE).
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:
Break all ties with a coinflip. Fastest variant.
Apply head-to-head and division win percentage tiebreakers. Random if still tied.
Apply all tiebreakers through strength of schedule. Random if still tied.
Aborts after the simulator reaches this week and returns the results from your process games call.
Equals the number of times the given NFL season shall be simulated
The number of simulations
can be split into
multiple rounds and be processed parallel. This parameter controls the number
of simulations per round. The default value determines the number of
locally available cores and calculates the number of simulations per round
to be equal to half of the available cores (various benchmarks showed this
results in optimal performance).
Either TRUE
or FALSE
. Controls whether additional
messages are printed to the console showing what the tie-breaking algorithms
are currently performing.
If TRUE
, prints the summary statistics to the console.
One of "REG"
, "POST"
, "DRAFT"
(the default).
Simulation will behave as follows:
Simulate the regular season and compute standings, division ranks, and playoff seeds
Do REG + simulate the postseason
Do POST + compute draft order
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.
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.
The examples on the package website
The method summary.nflseedR_simulation()
that creates a pretty html summary table.
# \donttest{
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)
})
# }
Run the code above in your browser using DataLab