1
$\begingroup$

Assume we have 10 coins, and each has its own probability of getting a head. We toss each coin a different number of times, say 10 times for the first coin, 15 times for the second coin, and so on. What is the probability of getting a head at least once in at least 5 different coins?

My thinking is that the probability for getting at least one head from a coin tossed $k$ times with a head probability of $p$ can be computed from the binomial distribution. Example R code:

sum(dbinom(1:k, k, p))

But I don't know how to generalize it to multiple coins mathematically or computationally.

$\endgroup$
  • $\begingroup$ Hint: The probability that coin $i$ getting a head at least one time in $k$ tosses is $1-0.5^k$ $\endgroup$ – callculus Jun 28 at 15:02
  • 1
    $\begingroup$ I have no guess as to what "and so on" might mean here. Does the number go up by $5$ each time? Something else? In any case, since the probabilities all differ you'll need to consider all possible selections of $5$ from the $10$ (assuming you mean "exactly $5$" and not "at least $5$"). $\endgroup$ – lulu Jun 28 at 15:03
  • 4
    $\begingroup$ Welcome to MSE. You'll get a lot more help, and fewer votes to close, if you show that you have made a real effort to solve the problem yourself. What are your thoughts? What have you tried? How far did you get? Where are you stuck? This question is likely to be closed if you don't add more context. Please respond by editing the question body. Many people browsing questions will vote to close without reading the comments. $\endgroup$ – saulspatz Jun 28 at 15:09
  • $\begingroup$ @callculus sorry if it was not clear. Each coin has a different probability of getting a head (not necessarily 0.5) $\endgroup$ – Amjad Jun 29 at 20:59
  • $\begingroup$ @lulu sorry for being unclear. It means that each coin was tossed different number of times (10 and 15 were just random examples) $\endgroup$ – Amjad Jun 29 at 21:00
2
$\begingroup$

Let the number of koins be $K$ and the probability to toss head with $i$-th coin be $p_i$, so that the corresponding probability to toss $N_i$ tails is $(1-p_i)^{N_i}\equiv Q_i$. Then assuming that $Q_i\ne0\ (\iff p_i\ne1)$ the probability that at least $k$ coins at least once showed up head is: $$ 1-\prod_i Q_i\sum_{S\in\mathbb P({\cal K})}^{|S|<k}\prod_{s\in S}\frac{1-Q_{s}}{Q_{s}}, $$ where the sum runs over all subsets $S=(s_1,s_2,\dots s_{|S|})$ of the set ${\cal K}=\{1,2\dots K\}$ with cardinality $|S|$ being less than $k$, and the inner product runs over all elements of the given subset.

$\endgroup$
  • $\begingroup$ Thank you very much. Would you be so kind and explain the solution in words or in code. I don't know what a sigma above sigma means. $\endgroup$ – Amjad Jun 29 at 23:35
  • $\begingroup$ Does this return the probability of getting at least N heads in N different coins, or N heads in a number of coins <N (some heads are from the same coin)? My question is about the former. $\endgroup$ – Amjad Jun 30 at 0:03
  • $\begingroup$ I'm trying to implement the solution but I am still struggling in understanding the outer sigma (excuse my bad math). So if we have 5 fair coins all were tossed 10 times, and we want to find the probability of getting at least 1 head in four out of five coins. What are the boundaries of the sigma in the first equation and second equation with those numbers? $\endgroup$ – Amjad Jul 1 at 8:51
  • $\begingroup$ Is it correct that first sigma will run from 1 to 4, and second sigma from 4 to 5? $\endgroup$ – Amjad Jul 1 at 8:57
  • $\begingroup$ I do not quite understand your problem. Do you mean each of the 5 coins being tossed 10 times? What does then mean "1 head in four out of five coins"? $\endgroup$ – user Jul 1 at 9:40
1
$\begingroup$

The answers in this post can be generalized to the case I am proposing here. The post discusses calculating probability of success in trials when the probabilities for each trial is different. In my case, the probability of trial is from binomial distribution instead of bernoulli.

In the following solution, I use the R implementation provided by @Zen. It was discussed in the post that when the number of coins is high, the solution will not be computationally efficient, but this is ok in my case.

library(purrr) 

number_coins <- 10 # number of coins
number_tosses <- c(10, 12, 12, 14, 15, 16, 20, 30, 25, 7) # tosses for each coin
number_heads <-  rep(1, number_coins) # the number of heads we need to get at least in each coin
prob_head <- seq(0.02, 0.1, length.out = number_coins) # coins are unfair. probability of getting a head for each coin
number_coins_with_head <- 6 # we need to find the probability of getting at least number_heads in at least number_coins_with_head

## function corresponding to @Zen solution
## p is a vector of probabilities
## k number of successes
binomial_different_prob <- function(p, k){
  n <- length(p)
  S <- seq(1, n)
  A <- combn(S, k)
  pr <- 0
  for (i in 1:choose(n, k)) {
    pr <- pr + exp(sum(log(p[A[,i]])) + sum(log(1 - p[setdiff(S, A[,i])])))
  }
  return(pr)
}

## first we caluclate the probability of getting at least number_heads in each coin
coins_probs <- pmap_dbl(list(prob_head, number_tosses, number_heads), function(x, y, z)sum(dbinom(z:y, y, x )))

## the probability of getting number_coins_with_head
p_number_coins_with_head <- binomial_different_prob(coins_probs, number_coins_with_head)

## the probability of getting at least number_coins_with_heads
p_at_least_number_coins_with_head <- sum(map_dbl(number_coins_with_head:number_coins, ~ binomial_different_prob(coins_probs, .x)))
p_at_least_number_coins_with_head
# 0.5616511

And here is the computationally efficient solution, taken from @whuber in this post

library(purrr) 

number_coins <- 100 # number of coins
number_tosses <- rep(c(10, 12, 12, 14, 15, 16, 20, 30, 25, 7),10) # tosses for each coin
number_heads <-  rep(1, number_coins) # the number of heads we need to get at least in each coin
prob_head <- seq(0.02, 0.1, length.out = number_coins) # coins are unfair. probability of getting a head for each coin
number_coins_with_head <- 60 # we need to find the probability of getting at least number_heads in at least number_coins_with_head


## function from @whuber
convolve.binomial <- function(p) {
  # p is a vector of probabilities of Bernoulli distributions.
  # The convolution of these distributions is returned as a vector
  # `z` where z[i] is the probability of i-1, i=1, 2, ..., length(p)+1.
  n <- length(p) + 1
  z <- c(1, rep(0, n-1))
  for (p in p) z <- (1-p)*z + p*c(0, z[-n])
  return(z)
}



## first we caluclate the probability of getting at least number_heads in each coin
coins_probs <- pmap_dbl(list(prob_head, number_tosses, number_heads), function(x, y, z)sum(dbinom(z:y, y, x )))

## the probability of getting number_coins_with_head
p_number_coins_with_head <- convolve.binomial(coins_probs)[number_coins_with_head+1]

## the probability of getting at least number_coins_with_heads
p_at_least_number_coins_with_head <- sum(convolve.binomial(coins_probs)[(number_coins_with_head+1):(number_coins+1)])

$\endgroup$

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.