knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "README-"
)
options(digits = 0)

require(rnflstats)
require(magrittr)
require(grid)

This R package will eventually simplify a multitude of tasks when analyzing NFL play-by-play data. In its current iteration, it is based on the New York Times 4th Down Bot (Github repository) and performs tasks limited to evaluating decisionmaking on 4th down plays. Using NFL play-by-play data from Armchair Analysis, this code will:

The Armchair Analysis data is not free. It costs $49 (one-time) to gain access to play-by-play data from the 2000-2014 NFL seasons. There is also a professional package that will provide weekly updates. Without the Armchair Analysis data, you will not be able to use much of this code.

Usage

Unzip the play-by-play data into a directory. Run the following code from the directory where you want the Fourth Down Bot code to live. It will create the subdirectories models and data to store files. The significant difference from the NYT 4th Down Bot is a more basic field goal success prediction model (still a work-in-progress).

data_prep("data/armchair_analysis/")
model_train()
fg_model_train()

If you wish to view the calibration plots and ROC curves for the model, run model_train or fg_model_train with the plot = TRUE flag, like so (as you will see, the field goal model needs a lot more work to even match the current NYT model):

model_train(plot = TRUE)
fg_model_train(plot = TRUE)

To evaluate the optimal decision, you must first load the already compiled data into your R workspace, then run the run_bot function. Currently you can only input your key information interactively via text prompts in R. Alternatively, for testing purposes you can use the random_play function to randomly generate fake data to test the package's functions. I am currently working on a better way to return summary information on this decision.

nfl_data <- load_data()
results <- run_bot(nfl_data$data, nfl_data$win_model, nfl_data$fg_model, random_play(nfl_data$data))
plot_decision(results) %>%
  grid.draw

| Option | Chance of Converting | Before Play | After Play | Change | |:-------|:---------------------|:------------|:-----------|:-------| | Go for it | r results$decision$prob_success * 100% | r results$probs$pre_play_wp * 100% | r results$probs$wp_ev_goforit * 100% | r (results$probs$wp_ev_goforit - results$probs$pre_play_wp) * 100% | | Punt | -- | r results$probs$pre_play_wp * 100% | r results$probs$punt_wp * 100% | r (results$probs$punt_wp - results$probs$pre_play_wp) * 100% | | Field goal try | r results$probs$prob_success_fg * 100% | r results$probs$pre_play_wp * 100% | r results$probs$fg_ev_wp * 100% | r (results$probs$fg_ev_wp - results$probs$pre_play_wp) * 100% |



bensoltoff/rnflstats documentation built on May 12, 2019, 2:08 p.m.