Learn R Programming

nflscrapR (version 1.8.3)

add_ep_variables: Calculate and add the expected points variables to include in a `nflscrapR` play-by-play data frame

Description

Given a `nflscrapR` play-by-play data frame, calculate the expected points for a play using the `nflscrapR` expected points model and include the columns to the input data frame. See here for an explanation of the model methodology: https://arxiv.org/abs/1802.00998. Source code for fitting the model is located here https://github.com/ryurko/nflscrapR-models/blob/master/R/init_models/init_ep_fg_models.R.

Usage

add_ep_variables(pbp_data)

Arguments

pbp_data

Data frame with all of the necessary columns used to estimate the expected points for a play.

Value

The input data frame with additional columns included for the expected points (ep), no score probability (no_score_prob), opponent field goal probability (opp_fg_prob), opponent safety probability (opp_safety_prob), opponent TD probability (opp_td_prob), own field goal probability (fg_prob), own safety probability (safety_prob), own TD probability (td_prob), as well as the expected points added (epa) and cumulative EPA totals for both the home and away teams (total_home_epa, total_away_epa).