If you’ve never coded before (or even if you have), type "Your Name"
in the interactive R chunk below and run it by hitting crtl+Enter
or cmd+Enter
for MAC users.
Throughout this tutorial you’ll be introduced to the notion of probability and will explore applications of probability and discrete random variables. In particular we will focus on binomial experiments and using the binomial distribution to find probabilities of prescribed outcomes.
Note: There are entire courses devoted to probability – we will only cover probability to the extent that it is necessary for use in this course. If you are interested in a more detailed treatment of probability, seek out one of the many great courses available.
Tutorial Objectives: After completing this tutorial you should be able to:
Definition of Probability (frequentist): For a given random process, the probability of an event \(A\) is the proportion of time we would observe outcome \(A\) if the random process were repeated an infinite number of times.
Example: Given a fair coin, the probability of a flip turning up heads is \(0.5\) (or 50%). Similarly, given a fair six-sided die, the probability of a roll resulting in a number greater than four is \(1/3\) (or about 33.3%) because there are two outcomes satifying the criteria (rolling a 5 or rolling a 6) out of the six total possible outcomes.
Try It! Now it is your turn. Try the next few problems. Be sure to note any questions you have as you work through them.
Good work on that last set of questions. In those problems you could find the probability by counting the number of ways the desired outcome could occur and then dividing that number by the total number of outcomes possible. In the last question, there were simply more ways to roll a five (four ways to do it) than to roll a two (just one way). What if we try doing something a bit more complicated? Say we wanted to know the probability of rolling at least a two on a single roll of a die and then flipping a “tails” on a single flip of a coin?
Probability and Independent Events: If \(A\) and \(B\) are independent events (that is, the probability that \(B\) occurs does not depend on whether or not \(A\) occured and vice-versa), then the probability of \(A\) and \(B\) occurring is the product of the probability of \(A\) occurring and the probability of \(B\) occurring. Mathematically, we write: \(\mathbb{P}\left[A~\text{and}~B\right] = \mathbb{P}\left[A\right]\cdot\mathbb{P}\left[B\right]\).
Good work so far. Let’s say you forgot to study for your chemistry quiz today. It is a four question multiple choice quiz with options \(a)\) - \(e)\). You decide that your best option is to guess randomly on each of the questions. Answer the following, using the empty code block below to carry out any necessary computations.
Binomial Experiments: A binomial experiment satisfies each of the following three criteria:
Binomial Distribution: Let \(X\) be the number of successes resulting from a binomial experiment with \(n\) trials. We can compute the following probabilities:
In the equations above, \(\binom{n}{k} = \frac{n!}{k!\left(n-k\right)!}\) counts the number of ways to arrange the \(k\) successes amongst the \(n\) trials. That being said, the R
functionality, dbinom()
and pbinom()
allow us to bypass the messy formulas – but you’ll still need to know what these functions do in order to use them correctly!
Tip: We need to use the binomial distribution to find probabilities associated with numbers of successful (or failing) outcomes in which we do not know for certain the trials on which the successes (or failures) occur.
The code block below is set up to find the probability of exactly two flips of a coin landing heads-up out of seven total flips. Edit the code block that that it finds the probability that you got exactly two of the four questions on your chemistry quiz from earlier correct. As a reminder, there were five answer options for each question and you were guessing randomly.
dbinom(2, 7, 0.5)
[1] 0.1640625
Good work. Now you’ll get to try a few more problems! As you work through the next set of questions, you may want to check out this example and solution. Note that in that document, I mention that drawing a simple picture for each problem will help you decide which function(s) you might use and whether you might need to make multiple computations. This is a really important strategy that will help you in developing a strategy to solve each problem.
Practice: For each of the following, consider a scenario in which a random sample of 18 students is asked (in private) whether they’ve failed to hand in at least one assignment this semester. We assume that about 34% of students fail to hand in at least one assignment.
Example: Find the probability that at most 15 of the 18 students have failed to hand in at least one assignment. That is,
\(\displaystyle{\mathbb{P}\left[X \leq 15\right] = \sum_{i=0}^{15}{\binom{18}{i}\cdot 0.34^{i}\left(1 - 0.34\right)^{18-i}} \approx \tt{pbinom(15, 18, 0.34)}})\)
pbinom(15, 18, 0.34)
## [1] 0.9999977
Example: Find the probability that at least 5 of the 18 students have failed to hand in at least one assignment. That is,
\(\displaystyle{\mathbb{P}\left[X \ge 5\right] = 1 - \mathbb{P}\left[X \le 4\right] = \tt{1 - pbinom(4, 18, 0.34)}}\)
1 - pbinom(4, 18, 0.34)
## [1] 0.7865908
Example: Find the probability that at least 10 and at most 15 students have failed to hand in at least one assignment. That is,
\(\displaystyle{\mathbb{P}\left[10 \le X \le 15\right] = \mathbb{P}\left[X \le 15\right]-\mathbb{P}\left[X \le 9\right] = \tt{pbinom(15, 18, 0.34) - pbinom(9, 18, 0.34)}}\)
pbinom(15, 18, 0.34) - pbinom(9, 18, 0.34)
## [1] 0.04942319
Be sure to write down what questions you had as you worked through these problems and to have a teacher, colleague, or tutor help clarify things for you.
Up to this point you’ve been exposed to basic probability, binomial experiments, and using the binomial distribution. Here’s a quick recap.