Compute CFB Game Results in Season Simulations
Source:R/compute_results.R
cfbseedR_compute_results.RdThe default compute_results function used by cfb_simulations(). It is
a faithful adaptation of nflseedR's nflseedR_compute_results() (a
variant of 538's ELO model, originally coded by Lee Sharpe and rewritten
by Sebastian Carl): a simple dynamic ELO carried through the teams
table, updated each week from (real or simulated) results.
Arguments
- teams
A data frame of teams by simulation with at least the columns
simandteam. May carry anelocolumn between weeks.- games
A data frame of games with at least
sim,game_type,week,home_team,away_team,result, and optionallyneutral(0/1; a home-field ELO bonus of 20 applies when not neutral).- week_num
The (numeric) week to simulate. Only games with
week == week_num & is.na(result)receive a simulated result.- ...
Optionally pass
elo, a named vector of initial ELO ratings (names = team names). If absent, teams start at random ratings drawn fromrnorm(1500, 150).
Value
A list with two elements, as required by the compute_results
contract (see simulations_verify_fct()):
| Element | Type | Description |
teams | data.frame | The input teams table with the elo column added/updated from this week's results. |
games | data.frame | The input games table with result filled for this week's previously missing results (home margin, integer). |
Details
Mechanics (constants identical to nflseedR): ELO difference is
home - away plus 20 for true home games, multiplied by 1.2 in the
postseason (game_type != "REG"). Win probability is
1 / (10^(-elo_diff / 400) + 1), the margin estimate is elo_diff / 25,
and simulated margins are drawn from rnorm(mean = estimate, sd = 13)
and rounded away from zero. Ties are possible in the regular season only;
a simulated postseason tie is re-decided by the win probability with a
3-point margin. nflseedR's rest-day adjustment is dropped (no rest data
in the CFB schema).
Examples
games <- read.csv(system.file("extdata", "toy_games.csv", package = "cfbseedR"))
teams <- read.csv(system.file("extdata", "toy_teams.csv", package = "cfbseedR"))
games$result[games$week >= 3] <- NA
teams$sim <- 1
games$sim <- 1
out <- cfbseedR_compute_results(teams, games, week_num = 3)
out$games[out$games$week == 3, ]
#> sim week game_type home_team away_team result neutral
#> 9 1 3 REG A1 A4 24 0
#> 10 1 3 REG A2 A3 -15 0
#> 11 1 3 REG B1 B3 17 0
#> 12 1 3 REG B2 B4 -3 0