Title: | Functions to Calculate Optimal Fourth Down Decisions in the National Football League |
---|---|
Description: | A set of functions to estimate outcomes of fourth down plays in the National Football League and obtain fourth down plays from <https://www.nfl.com/> and <https://www.espn.com/>. |
Authors: | Ben Baldwin [aut, cre, cph], Sebastian Carl [ctb] |
Maintainer: | Ben Baldwin <[email protected]> |
License: | MIT + file LICENSE |
Version: | 1.0.4.9005 |
Built: | 2024-10-27 06:21:41 UTC |
Source: | https://github.com/nflverse/nfl4th |
Get various probabilities associated with each option on PATs (go for it, kick PAT).
add_2pt_probs(df)
add_2pt_probs(df)
df |
A data frame of decisions to be computed for. |
Original data frame Data frame plus the following columns added:
first_down_prob, wp_fail, wp_succeed, go_wp, fg_make_prob, miss_fg_wp, make_fg_wp, fg_wp, punt_wp
Win probability when scoring 0 points on PAT.
Win probability when scoring 1 point on PAT.
Win probability when scoring 2 points on PAT.
Probability of making PAT kick.
Probability of converting 2-pt attempt.
Win probability associated with going for 1.
Win probability associated with going for 2.
play <- tibble::tibble( # things to help find the right game (use "reg" or "post") home_team = "GB", away_team = "TB", posteam = "GB", type = "post", season = 2020, # information about the situation qtr = 4, quarter_seconds_remaining = 123, score_differential = -2, home_opening_kickoff = 0, posteam_timeouts_remaining = 3, defteam_timeouts_remaining = 3 ) probs <- nfl4th::add_2pt_probs(play) dplyr::glimpse(probs)
play <- tibble::tibble( # things to help find the right game (use "reg" or "post") home_team = "GB", away_team = "TB", posteam = "GB", type = "post", season = 2020, # information about the situation qtr = 4, quarter_seconds_remaining = 123, score_differential = -2, home_opening_kickoff = 0, posteam_timeouts_remaining = 3, defteam_timeouts_remaining = 3 ) probs <- nfl4th::add_2pt_probs(play) dplyr::glimpse(probs)
Get various probabilities associated with each option on 4th downs (go for it, kick field goal, punt).
add_4th_probs(df)
add_4th_probs(df)
df |
A data frame of decisions to be computed for. |
Original data frame Data frame plus the following columns added:
Gain (or loss) in win prob associated with choosing to go for it (percentage points).
Probability of earning a first down if going for it on 4th down.
Win probability in the event of a failed 4th down attempt.
Win probability in the event of a successful 4th down attempt.
Average win probability when going for it on 4th down.
Probability of making field goal.
Win probability in the event of a missed field goal.
Win probability in the event of a made field goal.
Average win probability when attempting field goal.
Average win probability when punting.
play <- tibble::tibble( # things to help find the right game (use "reg" or "post") home_team = "GB", away_team = "TB", posteam = "GB", type = "post", season = 2020, # information about the situation qtr = 4, quarter_seconds_remaining = 129, ydstogo = 8, yardline_100 = 8, score_differential = -8, home_opening_kickoff = 0, posteam_timeouts_remaining = 3, defteam_timeouts_remaining = 3 ) probs <- nfl4th::add_4th_probs(play) dplyr::glimpse(probs)
play <- tibble::tibble( # things to help find the right game (use "reg" or "post") home_team = "GB", away_team = "TB", posteam = "GB", type = "post", season = 2020, # information about the situation qtr = 4, quarter_seconds_remaining = 129, ydstogo = 8, yardline_100 = 8, score_differential = -8, home_opening_kickoff = 0, posteam_timeouts_remaining = 3, defteam_timeouts_remaining = 3 ) probs <- nfl4th::add_4th_probs(play) dplyr::glimpse(probs)
Get 4th down plays from a game.
get_4th_plays(gid)
get_4th_plays(gid)
gid |
A game to get 4th down decisions of. |
Obtains a data frame that can be used with add_4th_probs()
. The following columns
must be present:
game_id : game ID in nflfastR format (eg '2020_20_TB_GB')
Original data frame Data frame plus the following columns added:
Play description from ESPN.
Play type text from ESPN.
Index number of play from a given game. Useful for tracking plays (e.g. for 4th down bot).
All the columns needed for add_4th_probs().
plays <- nfl4th::get_4th_plays('2020_20_TB_GB') dplyr::glimpse(plays)
plays <- nfl4th::get_4th_plays('2020_20_TB_GB') dplyr::glimpse(plays)
nflfastR
dataLoad calculated 4th down probabilities from nflfastR
data.
load_4th_pbp(seasons, fast = FALSE)
load_4th_pbp(seasons, fast = FALSE)
seasons |
Seasons to load. Must be 2014 and later. |
fast |
Defaults to FALSE. If TRUE, loads pre-computed decisions from repository |
nflfastR
data on 4th downs with the add_4th_probs()
columns added and also the following:
100 if a team went for it on 4th down, 0 otherwise. It's 100 and 0 as a convenience for obtaining percent of times going for it.
try({# Wrap in try to avoid CRAN test problems probs <- load_4th_pbp(2019:2020) dplyr::glimpse(probs) })
try({# Wrap in try to avoid CRAN test problems probs <- load_4th_pbp(2019:2020) dplyr::glimpse(probs) })
Get a table with the probabilities associated with a 2-pt decision.
make_2pt_table_data(probs)
make_2pt_table_data(probs)
probs |
A data frame consisting of one play that has had |
A table showing the probabilities associated with each possible choice.
play <- tibble::tibble( # things to help find the right game (use "reg" or "post") home_team = "GB", away_team = "TB", posteam = "GB", type = "post", season = 2020, # information about the situation qtr = 4, quarter_seconds_remaining = 123, score_differential = -2, home_opening_kickoff = 0, posteam_timeouts_remaining = 3, defteam_timeouts_remaining = 3 ) probs <- nfl4th::add_2pt_probs(play) nfl4th::make_2pt_table_data(probs)
play <- tibble::tibble( # things to help find the right game (use "reg" or "post") home_team = "GB", away_team = "TB", posteam = "GB", type = "post", season = 2020, # information about the situation qtr = 4, quarter_seconds_remaining = 123, score_differential = -2, home_opening_kickoff = 0, posteam_timeouts_remaining = 3, defteam_timeouts_remaining = 3 ) probs <- nfl4th::add_2pt_probs(play) nfl4th::make_2pt_table_data(probs)
Get a table with the probabilities on 4th down.
make_table_data(probs)
make_table_data(probs)
probs |
A data frame consisting of one play that has had |
A table showing the probabilities associated with each possible choice.
play <- tibble::tibble( # things to help find the right game (use "reg" or "post") home_team = "GB", away_team = "TB", posteam = "GB", type = "post", season = 2020, # information about the situation qtr = 4, quarter_seconds_remaining = 129, ydstogo = 8, yardline_100 = 8, score_differential = -8, home_opening_kickoff = 0, posteam_timeouts_remaining = 3, defteam_timeouts_remaining = 3 ) probs <- nfl4th::add_4th_probs(play) nfl4th::make_table_data(probs)
play <- tibble::tibble( # things to help find the right game (use "reg" or "post") home_team = "GB", away_team = "TB", posteam = "GB", type = "post", season = 2020, # information about the situation qtr = 4, quarter_seconds_remaining = 129, ydstogo = 8, yardline_100 = 8, score_differential = -8, home_opening_kickoff = 0, posteam_timeouts_remaining = 3, defteam_timeouts_remaining = 3 ) probs <- nfl4th::add_4th_probs(play) nfl4th::make_table_data(probs)
Reset nfl4th Package Cache
nfl4th_clear_cache(type = c("games", "fd_model", "wp_model", "all"))
nfl4th_clear_cache(type = c("games", "fd_model", "wp_model", "all"))
type |
One of |
Returns TRUE
invisibly if cache has been cleared.
nfl4th_clear_cache()
nfl4th_clear_cache()