2
$\begingroup$

I have this problem where there are two teams: a and b. They play a series of 5 games that are each independent of the other. The winner of each game is given a certain number of points. Whichever team has the most points at the end wins the series. Each game is played and there are no ties, either a or b wins. I am given the chances for each team to win for each game and the number of points each game is worth.

DATA

GAME A B PTS 1 33.5 65.8 1 2 76.2 23.0 2 3 46.8 53.2 3 4 12.2 75.4 4 5 65.3 8.40 5

I am trying to simulate a winner for each game, then based on who wins add up their scores for each game to give a winner of the series. This would be simulated for 100 5-game series. The part I am not sure about is how to simulate a winner for an individual game based on their chance of winning. I found this link on stat.exchange about simulating head to data. This post pointed to using BradleyTerry2 R package. I read through the article and example 3.3 looks similar to what I am trying to do though I am not really sure how to implement it or how it predicts a winner. If this is not the approach to take I am open for pointers.

Here is my code so far

    install.packages("BradleyTerry2")
    library("BradleyTerry2")

    a <- c(33.5,76.2,46.8,12.2,65.3)
    b <- c(65.8,23,53.2,75.4,8.4)
    pts <- c(1,2,3,4,5)

    # simulate 100 5-game series
    for (x in 1:100)
    {
      a_pts <- 0
      b_pts <- 0

      # loop through each game to predict winner
      for (g in 1:5)
      {
        # predict winner of game
          # this is where i need help

        # give winning team pts
        if(a[g]==1)
        {
          a_pts <- a_pts + pts[g]
        }
        if(b[g]==1)
        {
          b_pts <- b_pts + pts[g]
        }
      }

      # tally up series won by a
      if(a_pts > b_pts)
      {
        a_games[x] <- 1
      }
      if(a_pts < b_pts)
      {
        a_games[x] <- 0
      }
    }

    # probability of a winning series
    sum(a_games==1)/100

At this point I am just trying to figure out how to simulate the winner of an individual game based on their chance of winning. I will fix the checks to add points to the winner based on code/variables for predicting a winner. I am fairly new to both stats and R so any suggestions for generating a simulation either in R (preferable) or using statics equations I am open to hear.

$\endgroup$
  • 1
    $\begingroup$ Are the probabilities of each team winning given in column A and column B? If so, and the columns represent percentages, shouldn't the sum of column A and column B for each game be 100 given there are no ties? $\endgroup$ – Wes Mar 25 '17 at 20:30
  • 1
    $\begingroup$ Do these teams cross paths in game number 3? $\endgroup$ – Antoni Parellada Mar 25 '17 at 20:37
  • $\begingroup$ @Wes yes columns a and b are the probabilities each team winning. I agree with you that they should equal a 100. Technically there was a third team which accounts for the missing percent, but through the course of the problem that was given me the third team was dropped and it was only looking at 2 teams. If it makes creating a simulation easier then the percent total for A and B can be made to equal a hundred. I am trying to understand how to do the simulation based on the probability of each team winning. $\endgroup$ – soccergal_66 Mar 25 '17 at 20:45
  • $\begingroup$ @AntoniParellada A and B compete against each other in each game $\endgroup$ – soccergal_66 Mar 25 '17 at 20:46
  • 1
    $\begingroup$ As perhaps an overly naive approach, you could use the rbinom() function and the probability of success for a given team? This would give you a vector indicating successes and losses for that given game... and should be OK given each game is independent. Something along the lines of a<-rbinom(100,1,0.335) for game 1, with values of 1 indicating a win for team A. Just focusing on that as you say that is the part you are having difficulties with $\endgroup$ – Wes Mar 25 '17 at 20:55
2
$\begingroup$

Here is the code solution I came up with based on @Wes suggestion of using rbinom. I modified and cleaned up my code. This will loop through each game using rbinom to generate a 0 or 1 for N number of simulations using the probability P of winning the game. It will then loop through each game and assign the corresponding points for the games in the 5 game series if the value is 1

    a <- c(33.5,76.2,46.8,12.2,65.3)
    b <- c(65.8,23,53.2,75.4,8.4)
    pts <- c(1,2,3,4,5)
    N <- 100
    a_pts <- rep(0,N)

    # loop through each game to predict winner
    for (g in 1:5)
    {
      # predict winner of game
      P <- a[g]/100
      a_games <- rbinom(N,1,P)

      # loop through each game and assign corresponding points
      for (x in 1:N)
      {
        if(a_games[x]==1)
        {
          a_pts[x] <- a_pts[x] + pts[g]
        }
      }
    }

    # probability of a winning series
    sum(a_pts>=8)/N
$\endgroup$
  • $\begingroup$ A word of caution, using the values a as the probability for the rbinom() function does not correspond to the probabilities defined in b (see my comment on sum of probabilities above). Defining b and b_pts is essentially redundant in this code. $\endgroup$ – Wes Mar 25 '17 at 23:26
  • $\begingroup$ @Wes I agree. thanks. I removed the line. I thought I had removed all the references to b when I had cleaned up the code. $\endgroup$ – soccergal_66 Mar 26 '17 at 0:12
0
$\begingroup$

I don't know R but i would solve the problem like this :

While (!stop) { If (Rnd ()<=a [g]/100) a wins stop=true; If (Rnd ()<=b [g]/100) b wins stop=true; }

Rnd () is the random generator giving a real number between 0 and 1

However i don't understand your check for winner :

If (a [g]==1)

You should use another variable to store who won a particular game if you want to reuse the lists a [] and b []

$\endgroup$
  • 2
    $\begingroup$ I don't think this answer is very helpful. I think the problem is with the lack of clarity if the question. $\endgroup$ – Michael Chernick Mar 25 '17 at 20:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.