Hello. I am trying to perform a Poisson distribution experiment with football scores. I know how to simulate one game with dpois but I want to know how to do the same for an entire football (soccer) season. Please help. Thanks
I would:
- Make a vector with the team names
- Loop through the combinations of team vs team - calculate the score
Something like this.
teams <- LETTERS[1:10] # some team names
# loop through matches
set.seed(123)
points <- setNames(rep(0, length(teams)), teams)
for (team1 in teams){
for (team2 in setdiff(teams, team1)){
team1score <- rpois(1, 1)
team2score <- rpois(1, 1)
points[[team1]] <- points[[team1]] + ifelse(team1score > team2score, 3, ifelse(team1score == team2score, 1, 0))
points[[team2]] <- points[[team2]] + ifelse(team2score > team1score, 3, ifelse(team2score == team1score, 1, 0))
}
}
print(sort(points, decreasing = TRUE))
#> I D B E J C F G H A
#> 35 32 26 24 24 23 23 22 19 17
Created on 2020-11-11 by the reprex package (v0.3.0)
1 Like
This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.
If you have a query related to it or one of the replies, start a new topic and refer back with a link.