The following document shows the results of the model that aims to predict the results of the matches to be played by the national teams participating in the Qatar 2022 World Cup.
The model starts by taking into consideration the FIFA Ranking prior to the start of the tournament, then, for each match, the probability that the team has of winning (or losing) the match is calculated, subsequently, after the match the calculation of the FIFA Ranking is updated. This process is repeated from the opening game to the grand final of the Qatar 2022 World Cup.
Nomenclature
id: match id
group: FIFA group
date: match date
rounds: group stage (Round-1 to Round-3) & knockout rounds
home: home team
away: away team
prob_home: win probability home team
prob_away: win probability away team
winner: winner team
loser: loser team
home_rank: home team FIFA rank after match
away_rank: away team FIFA rank after match
Group stage
Only the results of the 8 teams with the highest value in the FIFA ranking are shown. In the final part of this document the results of all the confrontations of the participating teams are shown.
Group stage: Round-1
The following values correspond to the FIFA ranking of August 25, 2022 and taken from the following link:
In the Round of 16, groups are paired up and winners in one group face the runner-ups from the other: Group A was paired with Group B, C with D, E with F and G with H.
Code
# phase 1/8 schedule# schl18 <- sch %>%filter(group =="1/8 final") %>%select(id, group, date, home, away)# join sch18 & trw to set home# da1 <- schl18 %>%rename(winner = home) %>%full_join(trw, by ="winner") %>%drop_na(id) %>%select(id, date, home = team, home_rank = rank)# join sch18 & trw to set away #da2 <- schl18 %>%rename(winner = away) %>%full_join(trw, by ="winner") %>%drop_na(id) %>%select(id, away = team, away_rank = rank)# join to get updated schedule 1/8#r18 <-full_join(da1, da2, by ="id") %>%mutate(group ="r18", rounds ="r18") %>%select("id", "group", "date", "rounds", "home","away", "home_rank", "away_rank")# Final result r18 run update_point function # round18 <-update_point(r18, "r18", home_rank, away_rank, I, prob_home, prob_away)
Below are the results of all the matches. You can indicate the name of a country in Search in order to visualize its performance in Qatar 2022 World Cup
Source Code
---title: "Qatar 2022: Predict which teams will move their to glory"author: "Andres PENA"date: 2022-10-20toc: trueformat: html: theme: cerulean html-math-method: katex code-tools: true self-contained: trueexecute: warning: false---# IntroductionThe following document shows the results of the model that aims to predict the results of the matches to be played by the national teams participating in the Qatar 2022 World Cup.The model starts by taking into consideration the **FIFA Ranking** prior to the start of the tournament, then, for each match, the probability that the team has of winning (or losing) the match is calculated, subsequently, after the match the calculation of the FIFA Ranking is updated. This process is repeated from the opening game to the grand final of the Qatar 2022 World Cup.```{r message=FALSE, warning=FALSE, include=FALSE}#| code-fold: true# https://www.sportingnews.com/uk/soccer/news/world-cup-2022-group-winner-predictions-qatar/hqlnkvls6iskficxgtzps53o# # https://rpubs.com/EulerEnergy/962786rm(list =ls())# load libraries# libs <-c('readxl', 'janitor', 'lubridate', 'stringi', 'tidyverse', "tidytext", "DT", "scales","knitr", "reactable") invisible(lapply(libs, library, character.only =TRUE))# load functions # sapply(list.files(pattern ="[.]R$", path ="~/Documents/elo/R", full.names =TRUE), source)# # favorite_teams <-c("Netherlands", "Argentina", "England", "France", "Spain", "Brazil", "Belgium", "Portugal" )# default values# C =600I =50# read schedule# setwd("~/Documents/elo/data")sch <-read_excel("wc-2022-schedule.xlsx", col_types =c("numeric", "text", "date", "date", "text", "text", "text"))sch <- sch %>%mutate(rounds =case_when( date =="2022-11-20"| date <="2022-11-24"~"r1", date =="2022-11-25"| date <="2022-11-28"~"r2", date =="2022-11-29"| date <="2022-12-02"~"r3", date =="2022-12-03"| date <="2022-12-06"~"1/8 final", date =="2022-12-09"| date <="2022-12-10"~"1/4 final", date =="2022-12-13"| date <="2022-12-14"~"1/2 final", date =="2022-12-17"~"3rd place", date =="2022-12-18"~"Final"))# read fifa ranking# setwd("~/Documents/elo/data")fr <-read_csv("fifa_ranking-2022-08-25.csv") %>%filter(rank_date =="2022-08-25") %>%select(rank, team = country_full,rank_bQ22 = total_points)# extract country# countries <-unique(sch$home)countries <- countries[1:32] %>%sort()fr <- fr %>%mutate(team =case_when( team =="USA"~"United States", team =="IR Iran"~"Iran", team =="Korea Republic"~"South Korea",TRUE~as.character(team)))fr <- fr %>%filter(team %in% countries) %>%arrange(team) %>%select(-rank)```# Nomenclature- **id**: match id\- **group**: FIFA group\- **date**: match date\- **rounds**: group stage (Round-1 to Round-3) & knockout rounds\- **home**: home team\- **away**: away team\- **prob_home**: win probability home team\- **prob_away**: win probability away team\- **winner**: winner team\- **loser**: loser team\- **home_rank**: home team FIFA rank after match\- **away_rank**: away team FIFA rank after match# Group stageOnly the results of the 8 teams with the highest value in the FIFA ranking are shown. In the final part of this document the results of all the confrontations of the participating teams are shown.## Group stage: Round-1The following values correspond to the FIFA ranking of August 25, 2022 and taken from the following link:https://www.fifa.com/fifa-world-ranking/men?dateId=id13792```{r }#| code-fold: true# Data prep Round-1 # # add FIFA ranking to schedule# r1 <- sch %>%filter(rounds =="r1") %>%rename(team = home) %>%full_join(fr, by ="team") %>%rename(home = team, home_rank = rank_bQ22)r1 <- r1 %>%rename(team = away) %>%full_join(fr, by ="team") %>%rename(away = team, away_rank = rank_bQ22) %>%drop_na(id)r1 <- r1 %>%select(id:date, rounds, home:away_rank)# Final result Round-1 run update_point function # round1 <-update_point(r1, "r1", home_rank, away_rank, I, prob_home, prob_away)``````{r echo=FALSE}knitr::kable(r1 %>%filter(home %in% favorite_teams | away %in% favorite_teams) %>%select(home, home_rank, away, away_rank), aling ="l", digits =0,caption ="Qatar 2022 - Before Round-1")knitr::kable(round1 %>%filter(home %in% favorite_teams | away %in% favorite_teams) %>%select(home:prob_away, home_rank, away_rank), aling ="l", digits =0,caption ="Qatar 2022 - After Round-1")```## Group stage: Round-2```{r }#| code-fold: true# update fr with r1 results# fr <-tibble(team =c(r1$home, r1$away),rank =c(r1$home_rank, r1$away_rank)) # add FIFA ranking to schedule# r2 <- sch %>%filter(rounds =="r2") %>%rename(team = home) %>%full_join(fr, by ="team") %>%rename(home = team, home_rank = rank)r2 <- r2 %>%rename(team = away) %>%full_join(fr, by ="team") %>%rename(away = team, away_rank = rank) %>%drop_na(id)r2 <- r2 %>%select(id:date, rounds, home:away_rank)# Final result Round-2 run update_point function # round2 <-update_point(r2, "r2", home_rank, away_rank, I, prob_home, prob_away)``````{r echo=FALSE}knitr::kable(r2 %>%filter(home %in% favorite_teams | away %in% favorite_teams) %>%select(home, home_rank, away, away_rank), aling ="l", digits =0,caption ="Qatar 2022 - Before Round-2")knitr::kable(round2 %>%filter(home %in% favorite_teams | away %in% favorite_teams) %>%select(home:prob_away, home_rank, away_rank), aling ="l", digits =0,caption ="Qatar 2022 - After Round-2")```## Group stage: Round-3```{r }#| code-fold: true# update fr with r1 results# fr <-tibble(team =c(r2$home, r2$away),rank =c(r2$home_rank, r2$away_rank)) # add FIFA ranking to schedule# r3 <- sch %>%filter(rounds =="r3") %>%rename(team = home) %>%full_join(fr, by ="team") %>%rename(home = team, home_rank = rank)r3 <- r3 %>%rename(team = away) %>%full_join(fr, by ="team") %>%rename(away = team, away_rank = rank) %>%drop_na(id)r3 <- r3 %>%select(id:date, rounds, home:away_rank)# Final result Round-3 run update_point function # round3 <-update_point(r3, "r3", home_rank, away_rank, I, prob_home, prob_away)``````{r echo=FALSE}knitr::kable(r3 %>%filter(home %in% favorite_teams | away %in% favorite_teams) %>%select(home, home_rank, away, away_rank), aling ="l", digits =0,caption ="Qatar 2022 - Before Round-3")knitr::kable(round3 %>%filter(home %in% favorite_teams | away %in% favorite_teams) %>%select(home:prob_away, home_rank, away_rank), aling ="l", digits =0,caption ="Qatar 2022 - After Round-3")``````{r }#| code-fold: true# Group stage results # phase_group_results <-rbind(round1, round2, round3)# rank after r3# df <- phase_group_results %>%filter(rounds =="r3") %>%select(group, home, away, home_rank, away_rank)rank_after_r3 <-tibble(team =c(df$home, df$away),rank =c(df$home_rank, df$away_rank))# phase_group_winners# phase_group_winners <- phase_group_results %>%group_by(winner) %>%summarise(group =unique(group),team =unique(winner),nw =n()) %>%filter(nw >1) %>%mutate(win =ifelse(nw ==3, "1", "2"),winner =paste(win, group, sep ="")) %>%select(winner, team)# trw: team, rank & winner#trw <-full_join(rank_after_r3, phase_group_winners, by ="team") %>%drop_na(winner)```# Knockout rounds## Phase: **Round of 16** - r18In the Round of 16, groups are paired up and winners in one group face the runner-ups from the other: Group A was paired with Group B, C with D, E with F and G with H.```{r }#| code-fold: true# phase 1/8 schedule# schl18 <- sch %>%filter(group =="1/8 final") %>%select(id, group, date, home, away)# join sch18 & trw to set home# da1 <- schl18 %>%rename(winner = home) %>%full_join(trw, by ="winner") %>%drop_na(id) %>%select(id, date, home = team, home_rank = rank)# join sch18 & trw to set away #da2 <- schl18 %>%rename(winner = away) %>%full_join(trw, by ="winner") %>%drop_na(id) %>%select(id, away = team, away_rank = rank)# join to get updated schedule 1/8#r18 <-full_join(da1, da2, by ="id") %>%mutate(group ="r18", rounds ="r18") %>%select("id", "group", "date", "rounds", "home","away", "home_rank", "away_rank")# Final result r18 run update_point function # round18 <-update_point(r18, "r18", home_rank, away_rank, I, prob_home, prob_away)``````{r echo=FALSE}knitr::kable(r18 %>%filter(home %in% favorite_teams | away %in% favorite_teams) %>%select(home, home_rank, away, away_rank), aling ="l", digits =0,caption ="Qatar 2022 - Before **Round of 16**")knitr::kable(round18 %>%filter(home %in% favorite_teams | away %in% favorite_teams) %>%select(home:prob_away, home_rank, away_rank), aling ="l", digits =0,caption ="Qatar 2022 - After **Round of 16**")```## Phase: **Quarterfinals** - r14```{r }#| code-fold: true# importance of matchI =60r14 <- round18 %>%mutate(game =paste("W", id, sep ="")) %>%mutate(rank =ifelse(home == winner, home_rank, away_rank)) %>%select(team = winner, game, rank)sch14 <- sch %>%filter(group =="1/4 final") %>%select(id, group, date, rounds, home, away)db <- r14 %>%rename(home = game) %>%full_join(sch14, by ="home") %>%drop_na(id) %>%select(id, group, date, rounds, home = team, home_rank = rank)dc <- r14 %>%rename(away = game) %>%full_join(sch14, by ="away") %>%drop_na(id) %>%select(away = team, away_rank = rank)r14 <-cbind(db, dc)# Final result r18 run update_point function # r14 <- r14 %>%mutate(group ="r14", rounds ="r14") %>%select("id", "group", "date", "rounds", "home","away", "home_rank", "away_rank")round14 <-update_point(r14, "r14", home_rank, away_rank, I, prob_home, prob_away)``````{r echo=FALSE}knitr::kable(r14 %>%filter(home %in% favorite_teams | away %in% favorite_teams) %>%select(home, home_rank, away, away_rank), aling ="l", digits =0,caption ="Qatar 2022 - Before Quarterfinals")knitr::kable(round14 %>%filter(home %in% favorite_teams | away %in% favorite_teams) %>%select(home:prob_away, home_rank, away_rank), aling ="l", digits =0,caption ="Qatar 2022 - After Quarterfinals")```## Phase: **Semifinals** - r12```{r }#| code-fold: truer12 <- round14 %>%mutate(game =paste("W", id, sep ="")) %>%mutate(rank =ifelse(home == winner, home_rank, away_rank)) %>%select(team = winner, game, rank)sch12 <- sch %>%filter(group =="1/2 final") %>%select(id, group, date, rounds, home, away)cb <- r12 %>%rename(home = game) %>%full_join(sch12, by ="home") %>%drop_na(id) %>%select(id, group, date, rounds, home = team, home_rank = rank)cc <- r12 %>%rename(away = game) %>%full_join(sch12, by ="away") %>%drop_na(id) %>%select(away = team, away_rank = rank)r12 <-cbind(cb, cc)# Final result r18 run update_point function # r12 <- r12 %>%mutate(group ="r12", rounds ="r12") %>%select("id", "group", "date", "rounds", "home","away", "home_rank", "away_rank")round12 <-update_point(r12, "r12", home_rank, away_rank, I, prob_home, prob_away)``````{r echo=FALSE}knitr::kable(r12 %>%filter(home %in% favorite_teams | away %in% favorite_teams) %>%select(home, home_rank, away, away_rank), aling ="l", digits =0,caption ="Qatar 2022 - Before Semifinals")knitr::kable(round12 %>%filter(home %in% favorite_teams | away %in% favorite_teams) %>%select(home:prob_away, home_rank, away_rank), aling ="l", digits =0,caption ="Qatar 2022 - After Semifinals")``````{r eval=FALSE, include=FALSE}#| code-fold: true# 3rd place# r3p <- round12 %>%mutate(game =paste("L", id, sep ="")) %>%mutate(rank =ifelse(home == winner, home_rank, away_rank)) %>%select(team = winner, game, rank)sch3p <- sch %>%filter(group =="3rd place") %>%mutate(rounds ="3rd place") %>%select(id, group, date, rounds, home, away)eb <- r3p %>%rename(home = game) %>%full_join(sch3p, by ="home") %>%drop_na(id) %>%select(id, group, date, rounds, home = team, home_rank = rank)ec <- r3p %>%rename(away = game) %>%full_join(sch3p, by ="away") %>%drop_na(id) %>%select(away = team, away_rank = rank)r3p <-cbind(eb, ec)# qc before update# knitr::kable(rbind( r3p %>%filter(home =="Belgium"| away =="Belgium")) %>%select(home, home_rank, away, away_rank), caption ="Before Phase: 3rd place")# Final result r18 run update_point function # r3p <- r3p %>%mutate(group ="r3p", rounds ="r3p") %>%select("id", "group", "date", "rounds", "home","away", "home_rank", "away_rank")r3p <-update_point(r3p, "r3p", home_rank, away_rank, I, prob_home, prob_away)```## Phase: **Final** - rf```{r }#| code-fold: truerf <- round12 %>%mutate(game =paste("W", id, sep ="")) %>%mutate(rank =ifelse(home == winner, home_rank, away_rank)) %>%select(team = winner, game, rank)schf <- sch %>%filter(group =="final") %>%select(id, group, date, rounds, home, away)db <- rf %>%rename(home = game) %>%full_join(schf, by ="home") %>%drop_na(id) %>%select(id, group, date, rounds, home = team, home_rank = rank)dc <- rf %>%rename(away = game) %>%full_join(schf, by ="away") %>%drop_na(id) %>%select(away = team, away_rank = rank)rf <-cbind(db, dc)# Final result r18 run update_point function # rf <- rf %>%mutate(group ="rf", rounds ="rf") %>%select("id", "group", "date", "rounds", "home","away", "home_rank", "away_rank")roundf <-update_point(rf, "rf", home_rank, away_rank, I, prob_home, prob_away)``````{r echo=FALSE}knitr::kable(rf %>%filter(home %in% favorite_teams | away %in% favorite_teams) %>%select(home, home_rank, away, away_rank), aling ="l", digits =0,caption ="Qatar 2022 - Before Finals")knitr::kable(roundf %>%filter(home %in% favorite_teams | away %in% favorite_teams) %>%select(home:prob_away, home_rank, away_rank), aling ="l", digits =0,caption ="Qatar 2022 - After Finals")```# All match resultsBelow are the results of all the matches. You can indicate the name of a country in **Search** in order to visualize its performance in **Qatar 2022 World Cup**```{r echo=FALSE}# all match results# q22 <-rbind(round1, round2, round3, round18, round14, round12, roundf) %>%mutate(across(where(is.numeric), round, 0))# knitr::kable(q22, aling = "l", digits = 0,# caption = "Qatar 2022 - All match results")q22 %>% reactable::reactable(filterable =TRUE,searchable =TRUE)```