# Example code for finding binomial probabilities in R # The command qbinom computes _cumulative_ binomial probabilities # To get the cumulative probability, the syntax is: qbinom(x, n, p) # where p, n, and x are values that you fill in # Suppose our random variable X is binomial with n=20 and p=0.65 # Let's answer the following questions # 1. What is the probability of 13 or fewer successes? P(X <= 13) pbinom(13, 20, 0.65) # 2. What is the probability of 6 or fewer successes? P(X <= 6) pbinom(6, 20, 0.65) # 3. What is the probability of EXACTLY 13 successes? P(X = 13) pbinom(13, 20, 0.65) - pbinom(12, 20, 0.65) # or more simply: dbinom(13, 20, 0.65) # 4. What is the probability of more than 13 successes? P(X > 13) 1 - pbinom(13, 20, 0.65) # 5. What is the probability of 13 or more successes? P(X >= 13) 1 - pbinom(12, 20, 0.65) # 6. What is the probability of 8, 9, or 10 successes? P(8 <= X <= 10) pbinom(10, 20, 0.65) - pbinom(7, 20, 0.65) # Notice how the commands mirror the examples we did in class using the tables # The difference is: R can do these for any n and p, whereas the table only # gives probabilities for certain n and p choices.