# Probability of a team making the finals

#### listmanager

##### New Member
Hi,

I am trying to find how to calculate the probability of "x" number of events happening within "y" opportunities. However each opportunity has a different probability.

For example to calculate the probability of "TEAM WOW" winning 0, 1, 2, 3, or 4 games out of the 4 games they play. Assuming there is always a winner in each game.
Game 1: Probability of Winning: 58%
Game 2: Probability of Winning: 34%
Game 3: Probability of Winning: 76%
Game 4: Probability of Winning: 41%

How would I calculate the probability of for each outcome being winning 0, 1, 2, 3, or all 4 games?

Appreciate any help with this.

#### Dason

In a situation like this you just have to brute force it. There are only 16 possibilities so it's not so bad.

For instance to find the probability of
Win, Win, Win, Win = .58 * .34 * .76 * .41 (4 wins)
To find the probability of
Win, Win, Win, Lose = .58 * .34 * .76 * .59 (3 wins)

Find the probability for each of the 16 possible sequences. Then to find the probability of (2 wins) (just for example) you look at all the sequences that have 2 wins and you add all of those probabilities together.

#### listmanager

##### New Member
Thanks Dason. Appreciate the help.

So in the event I have 18 Teams and hence 17 games there is a significant amount of work.

Is there any formula that can be used or anything you could recommend as far as making it as easy and efficient as possible.

#### Dason

Well 2^17 = 131072 so it wouldn't be impossible to brute force. With larger numbers though it might be easiest to simulate the results to get an approximation to the true distribution.

#### listmanager

##### New Member
How would I go about Simulating the Results? As far as are their online sites you can use for this or is there something better?

Sorry if this is basic stuff as I am your average hack off the street and have just taught myself up to this point.

#### Dason

I got bored so I made a function in R to do this. It could be more efficient but it gets the job done for n = 17 fairly quickly.

Code:
buildDist <- function(probs, normalize = TRUE){
## If asked to normalize make sure the probabilities sum to 1
if(normalize){
probs <- probs/sum(probs)
}else{
# Else check that they sum to 1 or give an error
if(abs(sum(probs) - 1) >= .Machine\$double.eps){
stop("probs don't sum to 1")
}
}

n <- length(probs)

# Create a matrix to store the possible sequences
j <- matrix(NA, nrow = 2^n, ncol = n)
for(i in 1:n){
j[,i] <- rep(rep(c(0,1), each = 2^(i-1)), 2^(n-i))
}

# Calculates the probability of a given sequence occuring
fun <- function(row){
tmp <- row*probs + (1-row)*(1-probs)
return(prod(tmp))
}

# Calculate the probabilities for each sequence
ps <- apply(j, 1, fun)
# Calculate how many wins are in each sequence
wins <- rowSums(j)
# Calculate the sum of the probabilies for each
# number of wins
return(tapply(ps, wins, sum))
}

# Testing with 17 random uniform
probs <- runif(17)
probs <- probs/sum(probs)

buildDist(probs)

#### listmanager

##### New Member
Do I put this in a macro in Excel? and if so what cells do the data go into?