Sunday, July 19, 2009

A probability exercise on the Bernoulli distribution

What is the probability, flipping a coin 8 times, to obtain the sequence HHTTTHTT? (H = head; T= tail)

The theory teaches us that to solve this question, we can simply use the following formula:

$$f(x)=P(X=x)=B(n,p)=\begin{pmatrix}n\\ x \end{pmatrix} \cdot p^x \cdot q^{n-x}=\frac{n!}{x!(n-x)!}$$

To solve a problem like this, we can use in R the function dbinom(x, n, p). The coin flipping follow a binomial distribution, in which every event can be H or T. Suppose that T is the number of successes x (in this case x = 5), while n is the number independet experiments (in this case n = 8). The probability of success is p = 0.5. Put these data into R and get the answer:


dbinom(5, 8, 0.5)
[1] 0.21875


The probability of obtaining that particular sequence is equal to 21,875%.
What probability we would have obtained if we had chosen H as the success (ie by imposing x = 3)?

2 comments:

  1. 2 questions:

    1- trying dbinom(3, 8, 0.5), gives the same result as dbinom(5, 8, 0.5), can you explain why??

    2- Isn't this the probability of any sequence with 5 tails at least in the 8 throws, rather than that specific sequence?

    Thanks

    ReplyDelete
    Replies
    1. answer for 2, yes, you are right. The article is wrong.
      answer for 1, because the prob. of having 5 tails is the same of having 5 heads (which is the case of 3 tails)

      Delete