Open Side Menu Go to the Top
Register
Generalized Formula for Probability of Combination of Unequal Probabilities Generalized Formula for Probability of Combination of Unequal Probabilities

04-23-2017 , 09:29 PM
Thread title probably not clear, but this is what I'm looking for:

I have 7 coins to flip, each weighted differently:

Coin: pHeads (and pTails simply 1-pHeads)

A: .54
B: .59
C: .66
D: .50
E: .49
F: .48
G: 45

What is the chance of getting 4 heads? 5 heads? etc.?

I can figure this out through (a lot) of multiplication of all the possible combinations, but is there any way to simplify this and generalize the formula for any number of coins, and any set of probabilities?

Thanks for any insight.
Generalized Formula for Probability of Combination of Unequal Probabilities Quote
04-23-2017 , 10:46 PM
I semi-solved this using a ton of rand() functions in Excel and just counting the results. Simple enough to get a close answer after 1MM trials.

Still interested in a better math-based answer, however.

Thanks.
Generalized Formula for Probability of Combination of Unequal Probabilities Quote
04-24-2017 , 10:20 AM
You asked a similar question some time ago. Actually, it's basically the same thing. You had events with multiple outcomes, while now you have just two outcomes for each event. In any case, you want the sum of them.

As BruceZ showed, this is a convolution problem. Luckily, R supports convolution and your problem can be solved defining a one-liner function:

Code:
genUnProb<-function(ph) {
    setNames(Reduce(function(x,y) convolve(x,rev(y),type="open"),Map(c,1-ph,ph)),0:length(ph))
}
where the argument ph is a vector with the heads probabilities. Also a one-liner for a simulation:
Code:
genUnProbSim<-function(ph,nsim=100000) {
   setNames(tabulate(colSums(matrix(rbinom(nsim*length(ph),1,ph),ncol=nsim))+1)/nsim,0:length(ph))
}
Now we get the results with your values:

Code:
ph<-c(.54,.59,.66,.50,.49,.48,.45)
convResult<-genUnProb(ph)
simResult<-genUnProbSim(ph)
cbind(convResult,simResult)
#    convResult simResult
#0 0.004676563   0.00445
#1 0.038610441   0.03924
#2 0.134457040   0.13646
#3 0.256406970   0.25401
#4 0.289556183   0.29007
#5 0.193854783   0.19301
#6 0.071310213   0.07168
#7 0.011127806   0.01108
As you can see, there is a good agreement between the convolution and the simulation results (if you run the code, you'll have slightly different values for simulation result of course).
Generalized Formula for Probability of Combination of Unequal Probabilities Quote

      
m