niesfutbol / ideas

0 stars 0 forks source link

xTable from wyscout #11

Open nepito opened 1 year ago

nepito commented 1 year ago

Using the funtions:

calculate_xpoints <- function(home_xGol, away_xGol) {
  diff_goals <- calculate_diff_goals(home_xGol, away_xGol)
  xpoints <- sum(diff_goals > 0) * 3 / 2000 + sum(diff_goals == 0) / 2000
  return(xpoints)
}

y

calculate_diff_goals <- function(home_xGol, away_xGol) {
  n_sample <- 2000
  diff_goals <- rpois(n_sample, home_xGol) - rpois(n_sample, away_xGol)
  return(diff_goals)
}

La parte truculenta es:

maz_wide |>
  mutate(xP = mapply(function(x,y) calculate_xpoints(x,y), xG_Mazatlán, xG_Rival))
maz_widw <- 
  maz_clean |>
  pivot_wider(
    names_from = Team,
    values_from = c(Goals, xG)
  )