First load the packages and some data.
nflfastR data and computes 4th down probabilities (depending on your computer, this may take up to a minute or two per season).
Here’s what the data obtained using
load_4th_pbp() looks like:
Or we can add some filters to look up a certain game:
We see the infamous field goal at the bottom.
The below shows the bare minimum amount of information that has to be fed to
nfl4th in order to compute 4th down decision recommendations. The main function on user-input data is
The reason teams from a specific game have to be used is that the model depends on factors such as point spread, team totals, and indoor/outdoor and the program automatically looks these up so that users don’t have to provide them.
one_play <- tibble::tibble( # things to help find the right game (use "reg" or "post" for type) 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 ) one_play %>% nfl4th::add_4th_probs() %>% dplyr::select( posteam, ydstogo, yardline_100, posteam, go_boost, first_down_prob, wp_fail, wp_succeed, go_wp, fg_make_prob, miss_fg_wp, make_fg_wp, fg_wp, punt_wp ) %>% knitr::kable(digits = 2) #> Computing probabilities for 1 plays. . .
Comparing this and the table above, we see the exact same numbers as expected.
Let’s put the play above into a table using the provided function
make_table_data(), which makes it easier to interpret the recommendations for a play. This function only works with one play at a time since it makes a table using the results from the play.
one_play %>% nfl4th::add_4th_probs() %>% nfl4th::make_table_data() %>% knitr::kable(digits = 1) #> Computing probabilities for 1 plays. . .
|Go for it||12.7||32.7||3.5||31.5|
|Field goal attempt||8.9||97.5||3.0||9.0|
Looking at the table, the Packers would be expected to have 12.7% win probability if they had gone for it and 8.9% if they kicked a field goal. This difference of 3.8 percentage points is almost exactly the same as PFF’s 3.5 percentage points for the decision.
nfl4th also contains a function to calculate 2-point decisions. Let’s put in the situation that would have happened if the Packers had scored a touchdown on the 4th & 8. We don’t need a calculator to know that they should have gone for two, but let’s practice by putting in the numbers, assuming that the 4th down play took 6 seconds while resulting in a touchdown.
another_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 ) another_play %>% nfl4th::add_2pt_probs() %>% nfl4th::make_2pt_table_data() %>% knitr::kable(digits = 1) #> Computing probabilities for 1 plays. . .
|Go for 2||31.5||58.9||18.4||40.6|
Note that the go for 2 probability here is identical to the win probability associated with a successful 4th down conversion above because the 4th down model assumes that the Packers would go for 2 if they scored.
nflfastR isn’t available for live games and typing all the plays in by hand is annoying. So how does the 4th down bot work? With thanks to the ESPN API, which can be accessed using
plays <- get_4th_plays("2020_20_TB_GB") %>% tail(1) plays %>% select(desc, quarter_seconds_remaining) #> # A tibble: 1 × 2 #> desc quarter_seconds_remaining #> <chr> <dbl> #> 1 "Mason Crosby 26 Yd Field Goal " 125 plays %>% nfl4th::add_4th_probs() %>% nfl4th::make_table_data() %>% knitr::kable(digits = 1) #> Computing probabilities for 1 plays. . .
|Go for it||12.0||32.7||3.2||30.3|
|Field goal attempt||7.8||97.5||2.7||7.9|
Note that the probabilities are slightly different here because ESPN has the wrong value for time remaining (125 seconds instead of 129). This doesn’t affect a lot of plays but is something to be aware of.