
How the winner won it: a college football game story in expected points
Source:R/cfb_game_story.R
cfb_game_story.RdTurns the ESPN-processed plays of one or many games into six tidy frames
that explain the result: the winner's edges in expected points, the play
that swung the game, the score by quarter, each side's longest unanswered
run and each side's top performer. It returns the same frames, column for
column, as sportsdataverse-py's cfb_game_story() (the play id is
character here), and a parity test replays that function's output on real
games.
Each side's value for an edge is the sum of its offense's EPA over the
edge's plays, so a defense's work shows as the other offense's lower EPA.
points_worth is the winner's points less the loser's.
Accounting edges cover every play with an
EPAonce:passing(passscrimmage plays),rushing(rushscrimmage plays),special_teams(kickoffs, punts and field goals) andother(penalties without a play, kneels, conversions). Their sum is the net EPA, which telescopes to the margin less the expected points that halves start and end with: close to it, not equal.Splits are overlapping cuts:
turnovers(plays the offense turned over),explosive_plays(EPA_explosive),red_zone(scrimmage plays from 20 yards out or closer),late_downs(third and fourth down) andsuccess_rate. The success rate's value is each offense's rate on scrimmage plays (EPA_success); its points are(rate - game rate) * plays * (e_s - e_f): the successes above the game's pooled rate, priced at the game's own mean EPA of a successful play less an unsuccessful one.
The moment is the play with the largest absolute wpa, turned to the home
side (earliest on ties). A game with no wpa falls back to the winner's
first score after the last play it was level or behind after, so the
winner leads on every play from there to the end. The top performer is the player with the
most EPA as passer, rusher or receiver combined (a target credits both the
passer and the receiver; ties go to touchdowns, then the smaller id).
The final score is the release's homeFinalScore / awayFinalScore where
present, else the last running score. The quarters are rebuilt from the
running score, so periods_agree is FALSE when the plays end on another
score than the official final. A tie has no winner: winner_team_id and
loser_team_id are NA and the edges read from the home side's view.
Arguments
- pbp
The ESPN-processed plays of one or many games, as returned by
load_espn_cfb_pbp()(adata.frame, tibble ordata.table). Needsgame_id,id,game_play_number,period.number,clock.displayValue,text,pos_team_id(orpos_teamholding the team id),homeTeamId,awayTeamId,homeScore,awayScore,EPA,wpa,scrimmage_play,pass,rush,type.text,is_pos_team_turnover,EPA_explosive,EPA_success,start.yardsToEndzoneandlate_down. Thepasser_*,rusher_*andreceiver_*_player_id/_player_namepairs,pass_td,rush_td,homeFinalScoreandawayFinalScoreare used where present. Plays without agame_idare dropped with a warning.
Value
A named list of six tibbles, each sorted by game_id. A game whose
final is missing is dropped; a game without plays has no periods,
runs or moment rows, and one without an EPA has no edges or
performers rows. Without wpa, a tie has no moment row, nor does a
game whose plays end with the winner level or behind or whose winner
never scores again after it was last level or behind. Integer ids are R integers except the play id,
which is character (ESPN play ids pass 2^53), as in load_espn_cfb_pbp().
summary: one row per game.
| col_name | types | description |
| game_id | integer | The game's ESPN game id. |
| home_team_id | integer | Home team's ESPN team id. |
| away_team_id | integer | Away team's ESPN team id. |
| home_score | integer | Home team's official final score. |
| away_score | integer | Away team's official final score. |
| winner_team_id | integer | Winning team's id; NA on a tie. |
| loser_team_id | integer | Losing team's id; NA on a tie. |
| margin | integer | Winner's final score less the loser's; 0 on a tie. |
| decided | logical | TRUE when the game has a winner (FALSE on a tie). |
| periods_agree | logical | TRUE when the quarter sums (from the running score) equal the official final; FALSE flags plays that end on another score. |
| n_periods | integer | Periods played, overtimes included. |
| overtime | logical | TRUE when the game went past regulation. |
edges: one row per game and edge, ranked.
| col_name | types | description |
| game_id | integer | The game's ESPN game id. |
| winner_team_id | integer | Winning team's id (NA on a tie, where the edges read from the home side's view). |
| loser_team_id | integer | Losing team's id (NA on a tie). |
| edge | character | Edge name. Accounting: passing, rushing, special_teams, other. Splits: turnovers, explosive_plays, success_rate, red_zone, late_downs. |
| kind | character | accounting for the edges that partition the game's EPA, split for overlapping cuts. |
| unit | character | Always points: expected points, the unit the edges are priced in. |
| winner_value | double | Winner's value for the edge: its offense's EPA, or its success rate for success_rate. |
| loser_value | double | Loser's value for the edge, in the same unit as winner_value. |
| points_worth | double | The winner's edge in points: the winner's points from the edge less the loser's. Positive favours the winner. |
| rank | integer | Rank of the edge within the game by points_worth, 1 = largest; equal worths keep the edge list's order. |
moment: the play that decided each game.
| col_name | types | description |
| game_id | integer | The game's ESPN game id. |
| play_id | character | ESPN play id of the deciding moment. |
| order | integer | The play's game_play_number. |
| period | integer | Quarter of the play (5 and up: overtime). |
| clock | character | Game clock of the play as ESPN shows it. |
| team_id | integer | The offense's team id. |
| text | character | Play description as ESPN writes it. |
| wpa | double | Home win probability after the play less before it. |
| winner_wpa | double | The same change from the winner's side (NA on a tie). |
| home_score | integer | Home score after the play. |
| away_score | integer | Away score after the play. |
| rule | character | max_abs_wpa: the play with the largest absolute win-probability change (earliest on ties); deciding_score where no play has one: the winner's first score after it was last level or behind, so it leads from there to the end. |
periods: one row per game and quarter.
| col_name | types | description |
| game_id | integer | The game's ESPN game id. |
| period | integer | Period number, from 1; overtimes follow regulation. |
| period_label | character | Q1-Q4, then OT, OT2, ... |
| is_overtime | logical | TRUE for a period after regulation. |
| home_pts | integer | Home points in the period: its last running score less the previous period's. |
| away_pts | integer | Away points in the period. |
| home_cum | integer | Home running score at the end of the period. |
| away_cum | integer | Away running score at the end of the period. |
runs: each side's largest unanswered run (home first).
| col_name | types | description |
| game_id | integer | The game's ESPN game id. |
| team_id | integer | Team that made the run. |
| points | integer | Points the side scored in a row with no score by the other side (a score correction stays in the run and counts against its side; both sides scoring on one play ends any run). Earliest on ties. |
| start_order | integer | Play order of the run's first score. |
| end_order | integer | Play order of the run's last score. |
| start_period | integer | Period of the run's first score. |
| end_period | integer | Period of the run's last score. |
| home_score_after | integer | Home score at the end of the run. |
| away_score_after | integer | Away score at the end of the run. |
performers: each side's top player.
| col_name | types | description |
| game_id | integer | The game's ESPN game id. |
| team_id | integer | Team of the top performer. |
| player_id | integer | ESPN athlete id of the side's top performer. |
| player_name | character | Player's display name. |
| metric | character | Always epa: the expected points added the performer is chosen by. |
| value | double | The player's EPA as passer, rusher and receiver combined. |
See also
load_espn_cfb_pbp() for the plays.
Examples
# Downloads a whole season of play-by-play (about 500 columns).
pbp <- load_espn_cfb_pbp(2024)
story <- cfb_game_story(pbp[pbp$game_id == 401628333, ])
story$summary
#> # A tibble: 1 × 12
#> game_id home_team_id away_team_id home_score away_score winner_team_id
#> <int> <int> <int> <int> <int> <int>
#> 1 401628333 238 259 34 27 238
#> # ℹ 6 more variables: loser_team_id <int>, margin <int>, decided <lgl>,
#> # periods_agree <lgl>, n_periods <int>, overtime <lgl>
head(story$edges, 3)
#> # A tibble: 3 × 10
#> game_id winner_team_id loser_team_id edge kind unit winner_value
#> <int> <int> <int> <chr> <chr> <chr> <dbl>
#> 1 401628333 238 259 red_zone split points 12.5
#> 2 401628333 238 259 turnovers split points 0
#> 3 401628333 238 259 success_rate split points 0.516
#> # ℹ 3 more variables: loser_value <dbl>, points_worth <dbl>, rank <int>
story$moment[, c("text", "winner_wpa")]
#> # A tibble: 1 × 2
#> text winner_wpa
#> <chr> <dbl>
#> 1 Kyron Drones pass complete to Ali Jennings for 62 yds for a TD (Jo… -0.288