# ffopportunity
*Models and Data for Expected Fantasy Points*
ffopportunity builds a dataframe of Expected Fantasy Points by
preprocessing and applying an xgboost model to nflverse play-by-play
data. It also includes utilities to download precomputed data from
automated GitHub releases.
## About
Expected Fantasy Points are a measure of player opportunities in fantasy
football - essentially aiming to quantify how many points the average
player would score given a specific situation and opportunity. It uses
xgboost and tidymodels trained on public nflverse data from 2006-2020 to
do this.
For more on the modeling details, see the articles posted to this
website:
## Installation
Install the development version from GitHub with:
``` r
install.packages("ffopportunity", repos = c("https://ffverse.r-universe.dev", getOption("repos")))
# or use remotes/devtools
# install.packages("remotes")
remotes::install_github("ffverse/ffopportunity")
```
## Usage
The two main functions of {ffopportunity} are
[`ep_load()`](https://ffopportunity.ffverse.com/reference/ep_load.md)
and
[`ep_build()`](https://ffopportunity.ffverse.com/reference/ep_build.md).
You can download the latest version of the EP data with
[`ep_load()`](https://ffopportunity.ffverse.com/reference/ep_load.md) as
follows:
``` r
library(ffopportunity)
#> Warning: package 'ffopportunity' was built under R version 4.2.1
ep_load(season = 2020:2021, type = "weekly")
#> →
#> → Generated 2022-09-12 12:59:18 with ep model version "latest"
#> # A tibble: 11,769 × 159
#> season posteam week game_id playe…¹ full_…² posit…³ pass_…⁴ rec_a…⁵ rush_…⁶
#>
#> 1 2020 SF 1 2020_01… 00-003… Jimmy … QB 33 0 1
#> 2 2020 SF 1 2020_01… 00-003… George… TE 0 5 1
#> 3 2020 ARI 1 2020_01… 00-003… Kyler … QB 39 0 11
#> 4 2020 ARI 1 2020_01… 00-003… DeAndr… WR 0 16 0
#> 5 2020 ARI 1 2020_01… 00-002… Larry … WR 0 5 0
#> 6 2020 ARI 1 2020_01… 0 2 0
#> 7 2020 SF 1 2020_01… 00-003… Raheem… RB 0 5 15
#> 8 2020 ARI 1 2020_01… 00-003… Kenyan… RB 0 2 16
#> 9 2020 ARI 1 2020_01… 00-003… Christ… WR 0 5 0
#> 10 2020 SF 1 2020_01… 00-003… Trent … WR 0 5 0
#> # … with 11,759 more rows, 149 more variables: pass_air_yards ,
#> # rec_air_yards , pass_completions , receptions ,
#> # pass_completions_exp , receptions_exp , pass_yards_gained ,
#> # rec_yards_gained , rush_yards_gained ,
#> # pass_yards_gained_exp , rec_yards_gained_exp ,
#> # rush_yards_gained_exp , pass_touchdown , rec_touchdown ,
#> # rush_touchdown , pass_touchdown_exp , rec_touchdown_exp , …
#> # ℹ Use `print(n = ...)` to see more rows, and `colnames()` to see all variable names
```
You can also build EP from base nflverse data with
[`ep_build()`](https://ffopportunity.ffverse.com/reference/ep_build.md)
as follows:
``` r
ep_build(season = 2021, version = "latest")
```
``` R
#> -- Starting ep build for 2021 season(s)! 2022-01-11 07:58:44 -------------------
#> > Loading pbp 2022-01-11 07:58:44
#> > Preprocessing pbp 2022-01-11 07:58:46
#> > Generating predictions 2022-01-11 07:58:54
#> > Summarizing data 2022-01-11 07:59:33
#> -- Finished building ep for 2021 season(s)! 2022-01-11 07:59:33 ----------------
#> >
#> > Generated 2022-01-11 07:59:33 with model version latest
#> List of 5
#> $ ep_weekly : tibble [5,756 x 159] (S3: tbl_df/tbl/data.frame)
#> $ ep_pbp_pass: tibble [18,747 x 57] (S3: tbl_df/tbl/data.table/data.frame)
#> $ ep_pbp_rush: tibble [14,038 x 47] (S3: tbl_df/tbl/data.table/data.frame)
#> $ ep_version : chr "latest"
#> $ timestamp : POSIXct[1:1], format: "2022-01-11 07:59:33"
```
## Data
ffopportunity data is automated with GitHub Actions and can be manually
downloaded in RDS, parquet, and csv formats from the [releases
page](https://github.com/ffverse/ffopportunity/releases).
## Getting help
The best places to get help on this package are:
- the [nflverse discord](https://discord.com/invite/5Er2FBnnQa) (for
both this package as well as anything R/NFL related)
- opening [an
issue](https://github.com/ffverse/ffopportunity/issues/new/choose)
## Contributing
Many hands make light work! Here are some ways you can contribute to
this project:
- You can [open an
issue](https://github.com/ffverse/ffopportunity/issues/new/choose) if
you’d like to request specific data or report a bug/error.
- If you’d like to contribute code, please check out [the contribution
guidelines](https://ffopportunity.ffverse.com/CONTRIBUTING.html).
## Terms of Use
The R code for this package is released as open source under the [GPL v3
License](https://ffopportunity.ffverse.com/LICENSE.html). The models and
expected points data included within this package’s are licensed under
[Creative Commons Attribution-ShareAlike 4.0 International
License](https://creativecommons.org/licenses/by-sa/4.0/)
## Code of Conduct
Please note that the ffopportunity project is released with a
[Contributor Code of
Conduct](https://contributor-covenant.org/version/2/0/CODE_OF_CONDUCT.html).
By contributing to this project, you agree to abide by its terms.
# Package index
## Main
Download or build expected fantasy points
- [`ep_load()`](https://ffopportunity.ffverse.com/reference/ep_load.md)
: Load Expected Points data
- [`ep_build()`](https://ffopportunity.ffverse.com/reference/ep_build.md)
: Build EP
## Misc
Helper functions for used by the main functions
- [`ep_cache_models()`](https://ffopportunity.ffverse.com/reference/ep_cache_models.md)
: Model versioning
- [`ep_predict()`](https://ffopportunity.ffverse.com/reference/ep_predict.md)
: Predict EP
- [`ep_preprocess()`](https://ffopportunity.ffverse.com/reference/ep_preprocess.md)
: Preprocess Data
- [`ep_summarize()`](https://ffopportunity.ffverse.com/reference/ep_summarize.md)
: Summarize EP
# Articles
### All vignettes
- [Expected Rushing
Yards](https://ffopportunity.ffverse.com/articles/rushing_yards_vignette.md):