xg_win_prob: Simulate matches to calculate win-draw-win probabilities

View source: R/xg_win_prob.R

xg_win_probR Documentation

Simulate matches to calculate win-draw-win probabilities

Description

Simulate matches to calculate win-draw-win probabilities

Usage

xg_win_prob(
  team_a_shots_xg,
  team_b_shots_xg,
  team_a_name = "team_a",
  team_b_name = "team_b",
  n_sim = 10000,
  seed = 123
)

Arguments

team_a_shots_xg

vector of shot xG values for team A

team_b_shots_xg

vector of shot xG values for team B

team_a_name

name of team A

team_b_name

name of team B

n_sim

number of simulations to run

seed

seed for reproducibility

Examples

## Not run: 
df <- tibble(home_shot_xg = list(c(0.06, 0.03, 0.03, 0.02, 0.07, 0.26, 0.09, 0.08, 0.05, 0.02, 0.06, 0.22, 0.10, 0.06, 0.3, 0.24, 0.05, 0.06, 0.04, 0.21)),
             away_shot_xg = list(c(0.06, 0.03, 0.04, 0.06)),
             team_home = "BYU",
             team_away = "Stanford")

sim_df <- xg_win_prob(team_a_shots_xg = home_shot_xg,
                      team_b_shots_xg = away_shot_xg,
                      team_a_name = team_home,
                      team_b_name = team_away,
                      n_sim = 10000)

#The first data frame contains probabilities for each result
sim_df[[1]]
## label    n   prob team_name points
## 1 team_a 8487 0.8487       BYU      3
## 2 team_b  213 0.0213  Stanford      0
## 3   draw 1300 0.1300      <NA>     NA

The second data frame contains the probabilities for every score combination - arranged by probability
head(sim_df[[2]])
## team_a_goals team_b_goals    n   prob
## 1            2            0 2378 0.2378
## 2            1            0 2181 0.2181
## 3            3            0 1703 0.1703
## 4            0            0  862 0.0862
## 5            4            0  761 0.0761
## 6            2            1  517 0.0517

## End(Not run)

stxlen/soccr documentation built on Feb. 17, 2025, 1:23 a.m.