# Generate 10 separate random flips with probability .3
rbinom(10, 1, p = 0.3)
[1] 0 0 1 0 1 0 0 0 1 0
February 5, 2023
In these exercises, you’ll practice using the rbinom() function, which generates random “flips” that are either 1 (“heads”) or 0 (“tails”).
In the last exercise, you simulated 10 separate coin flips, each with a 30% chance of heads. Thus, with rbinom(10, 1, .3) you ended up with 10 outcomes that were either 0 (“tails”) or 1 (“heads”).
But by changing the second argument of rbinom() (currently 1), you can flip multiple coins within each draw. Thus, each outcome will end up being a number between 0 and 10, showing the number of flips that were heads in that trial.
[1] 2 4 4 5 3 1 5 4 4 1 6 6 4 2 2 0 3 6 1 1 4 1 3 1 3 4 7 3 0 4 0 3 5 1 4 3 2
[38] 3 5 1 2 1 2 2 7 3 2 3 1 4 2 3 4 2 1 2 4 3 1 3 1 3 3 4 2 2 1 1 3 1 2 3 2 3
[75] 1 2 2 0 6 1 2 2 4 5 2 3 5 3 4 4 3 4 3 1 4 3 3 3 2 3
If you flip 10 coins each with a 30% probability of coming up heads, what is the probability exactly 2 of them are heads?
If you flip ten coins that each have a 30% probability of heads, what is the probability at least five are heads?
Answer the above question using the pbinom() function. (Note that you can compute the probability that the number of heads is less than or equal to 4, then take 1 - that probability).
Confirm your answer with a simulation of 10,000 trials by finding the number of trials that result in 5 or more heads.
In the last exercise you tried flipping ten coins with a 30% probability of heads to find the probability at least five are heads. You found that the exact answer was 1 - pbinom(4, 10, .3) = 0.1502683, then confirmed with 10,000 simulated trials.
[1] 0.1515
[1] 0.18
[1] 0.154
[1] 0.1523
[1] 0.14892