1. The binomial distribution
It's time to further expand your toolbox of distributions. In this video, you'll learn about the binomial distribution.
2. Coin flipping
We'll start by flipping a coin, which has two possible outcomes, heads or tails, each with a probability of 50%.
3. Binary outcomes
This is just one example of a binary outcome, or an outcome with two possible values. We could also represent these outcomes as a 1 and a 0, a success or a failure, and a win or a loss.
4. A single flip
In R, we can simulate this using the rbinom function, which takes in the number of trials, or times we want to flip, the number of coins we want to flip, and the probability of heads or success. This will return a 1, which we'll count as a head, or a 0, which we'll count as tails.
We can use rbinom 1, 1, 0-point-5 to flip 1 coin 1 time with a 50% probability of heads.
5. One flip many times
To perform eight coin flips, we can change the first argument to an 8, which will give us eight flips of 1 coin with a 50% chance of heads.
This gives us a set of 8 ones and zeros.
6. Many flips one time
If we swap the first two arguments, we simulate one flip of eight coins. This gives us one number, which is the total number of heads or successes.
7. Many flips many times
Similarly, we can pass 10 and 3 into rbinom to simulate 10 flips of 3 coins. This returns 10 numbers, each representing the total number of heads from each set of flips.
8. Other probabilities
We could also have a coin that's heavier on one side than the other, so the probability of getting heads is only 25%. To simulate flips with this coin, we'll adjust the third argument of rbinom to 0-point-25.
The result has lower numbers, since getting multiple heads isn't as likely with the new coin.
9. Binomial distribution
The binomial distribution describes the probability of the number of successes in a sequence of independent trials. In other words, it can tell us the probability of getting some number of heads in a sequence of coin flips. Note that this is a discrete distribution since we're working with a countable outcome.
The binomial distribution can be described using two parameters, n and p. n represents the total number of trials being performed. n and p are also the second and third arguments of rbinom.
Here's what the distribution looks like for 10 coins. We have the biggest chance of getting 5 heads total, and a much smaller chance of getting 0 heads or 10 heads.
10. What's the probability of 7 heads?
To get the probability of getting 7 heads out of 10 coins, we can use dbinom. The first argument is the number of heads or successes. The second argument is the number of trials, n, and the third is the probability of success, p.
If we flip 10 coins, there's about a 12% chance that 7 of them will be heads.
11. What's the probability of 7 or fewer heads?
pbinom gives the probability of getting a number of successes less than or equal to the first argument. The probability of getting 7 or fewer heads out of 10 coins is about 95%.
12. What's the probability of more than 7 heads?
We can use the lower-dot-tail argument to get the probability of a number of successes greater than the first argument. Note that this is the same as 1 minus the same pbinom call from the previous slide.
13. Expected value
The expected value of the binomial distribution can be calculated by multiplying n times p. The expected number of heads we'll get from flipping 10 coins is 10 times 0-point-5, which is 5.
14. Independence
It's important to remember that in order for the binomial distribution to apply, each trial must be independent, so the outcome of one trial shouldn't have an effect on the next.
For example, if we're picking randomly from these cards with zeros and ones, we have a 50-50 chance of getting a 0 or a 1.
15. Independence
But since we're sampling without replacement, the probabilities for the second trial are different due to the outcome of the first trial. Since these trials aren't independent, we can't calculate accurate probabilities for this situation using the binomial distribution.
16. Let's practice!
Time to explore binary outcomes using the binomial distribution.