knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.width = 7, fig.height = 5 ) options(dplyr.summarise.inform = FALSE)
library(ffsimulator) library(ggplot2)
ffsimulator runs simulations on a given fantasy league based that league's rosters, scoring settings, and current redraft rankings, connecting this data to historical weekly performances for each (preseason) positional ranking.
This vignette will introduce the basic usage of ffsimulator - you may also be interested in the motivations and custom simulations vignettes!
ffsimulator connects directly to your league (via the ffscrapr package) and can be used at a high level with just a few lines of code:
foureight_conn <- mfl_connect(2021, 22627) foureight_sim <- ff_simulate(conn = foureight_conn, n_seasons = 10, n_weeks = 14) foureight_sim
foureight_sim <- readRDS(system.file("cache/foureight_sim.rds", package = "ffsimulator")) foureight_sim
ffsimulator includes a few automatic plots that can be run on this ff_simulation object to get a quick sense of the simulation output:
plot(foureight_sim) # defaults to type = "wins" plot(foureight_sim, type = "rank") plot(foureight_sim, type = "points")
You can also access the various component dataframes by name, for further analysis.
The summary_simulation
table is a team-level summary across all of the simulated seasons.
foureight_sim$summary_simulation
The summary_season
table is a season-level summary of all weeks within those seasons - any one of these seasons "could" theoretically be the outcome of the upcoming season!
foureight_sim$summary_season
The summary_week
table is a week-level summary of each team's performance, including the optimal lineup that could have been played by the team and the randomly-generated lineup efficiency factor:
foureight_sim$summary_week
The roster_scores
and projected_scores
tables both provide individual player-week level scores, with the difference being that the roster_scores
table is attached to franchise rosters (and thus duplicates rows if there are multiple copies of players within the league).
foureight_sim$roster_scores
Finally, some basic parameters are included, including league_info
which is generated by ffscrapr::ff_league()
.
foureight_sim$league_info
As of the 1.1.0 release, ffsimulator also has functions to simulate an individual week, with that week's FP rankings!
foureight_conn <- mfl_connect(2021, 22627) foureight_sim_week <- ff_simulate_week(conn = foureight_conn, n = 10) foureight_sim_week
foureight_sim_week <- .ffs_cache("foureight_sim_week.rds") foureight_sim_week
This simulation object has many of the same dataframes, including a summary_simulation, summary_week, roster_scores, projected_scores, league_info, and simulation_params.
It also has some different automatic plots, including one for schedule luck:
plot(foureight_sim_week,type = "luck")
and the usual points distribution:
plot(foureight_sim_week, type = "points")
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.