A random variable \(X\) is a discrete random variable if the range of \(X\) is finite or an infinite sequence of values. A discrete random variable can be characterized by a function called a probability mass function (pmf) which specifies the probability for each possible numerical value of the random variable.
\[ p(x) = \operatorname{P}(X = x) \] This function can be specified with a formula or in a table of probabilities. Given the pmf we can calculate the probability any event by adding the probabilities for all of the these values in the event.
Example 1. Toss a fair coin 5 times. Let \(X\) = number of heads produced.
This example is an instance of an important kind of discrete random variabl called a binomial random variable. Binomial random variables arise in situations which have the following properties.
Such a variable is dennoted by \(X \sim {\sf Binom}(n, p)\).
There is a handy formula for the pmf of a \({\sf Binom}(n, p)\) random variable:
\[ p(x) = \operatorname{P}(X = x) = \binom{n}{x} p^x (1-p)^{n-x} \]
where \(\binom{n}{x} = \frac{n!}{x! (n-x)!}\). \(\binom{n}{x}\) is read “n choose x” and counts the number of ways to pick a set of \(x\) items from a collection of size \(n\). This can be computed in R using the choose()
function.
choose(5, 2)
## [1] 10
factorial(5) / (factorial(2) * factorial(3))
## [1] 10
Example 2. If we roll a fair die 10 times, what is the probability of getting 2 or more sixes?
Example 3. Two cards are dealt from an ordinary deck of playing cards. Let \(X\) = number of aces dealt.
Example 4. A fair coin is tossed until a head is produced. Let \(X\) = number of tosses.
A continuous random variable is a random variable whose range is an interval of real numbers.
Examples
Randomly select an adult male: Let \(X\) = (exact) height in inches
Randomly select a washer produced by a particular machine. Let X = (exact) diameter in mm.
Randomly select a battery and use it to power a device. Let \(X\) = (exact) time until battery can no longer power device.
Let’s consider the heights of the adult children in the Galton
data set. Here is a density histogram.
gf_dhistogram( ~ height, data = Galton)
The density scale is chosen so that ___________________________________________.
Now let’s look at a density plot.
gf_dhistogram( ~ height, data = Galton) %>%
gf_dens( ~ height, data = Galton, size = 1.2)
This provides a “smooth” version of the histogram and also has the property that
A continuous random variable is described by a probability density function (pdf). The plot of a pdf will look just like curve in a density plot.
Probability density functions always have two important properties:
We determine probabilities from a pdf but taking the area under the curve over the region corresponding to our event (ie, by integration).
\[ \operatorname{P}( a \le X \le b) = \int_a^b f(x) \; dx \]
Example 5. Let \(X\) be a number randomly chosen from the interval \([0, 2]\) in such a way that all numbers are equally likely. We call \([0, 2]\) the support of \(X\) is [0,2].
Since no value of \(X\) is more likely to be selected than any other value, the density function \(f(x)\) must be a constant on [0,2].
What is the constant value?
What is \(\operatorname{P}(X = 1)\)?
What is \(\operatorname{P}(0 \le X \le 1)\)?
Waht is \(\operatorname{P}(1 \le X \le 3/2)\)?
What is \(\operatorname{P}(1 \le X \le 3)\)?
A random variable \(X\) whose pdf is constant (where it is non-zero) is said to have a uniform distribution. We will denote this as \(X \sim {\sf Unif}(a, b)\), where \(a\) and \(b\) are the upper and lower limits of the support.
Example 6. Let \(f(x) = x/2\) for \(x \in (0,2)\) (and 0 elsewhere). We can write this as \(f(x) = x/2 \cdot [\![x \in (0,2) ]\!]\) or \(f(x) = x/2\) on \((0,2)\).
Verify that \(f(x)\) is a probability density function.
Compute \(\operatorname{P}(1 \le X \le 3/2)\).
Compute \(\operatorname{P}(1 \le X \le 4)\).
The cdf for \(X\) is defined by
\[ F(x) = \operatorname{P}(X \le x) \]
Example 7. Let \(X\) have a uniform distribution on \([0,4]\).
Example 8. Let \(X\) be the random variable whose pdf is \(f(x) = x/2 \cdot [\![ x \in (0,2) ]\!]\). Find the cdf for \(X\).
If \(F(x)\) is the cdf for the random variable \(X\), then \(\operatorname{P}(a \le X \le b) =\) ________________________
Example 9. Let \(F(x)= x^2\) on \([0,1]\)
What is \(F(x)\) when \(x < 0\)?
What is \(F(x)\) when \(x > 0\)?
What is \(P(X \le 1/2)\)?
What is \(P(1/2 \le X \le 3/4)\)?
What is \(P(-2 \le X \le 1/2)\)?
What is the pdf for \(X\)?
Example 10. Let \(f(x) = e^{-x}\) on \((0,\infty)\) (and 0 elsewhere).
1. Parts coming off an assembly line have a 1% chance of being defective. If 3 parts are randomly chosen from this line and X is the number of defective parts.
Compute the probability function p(x) for X.
What is the probability that at least one of the three is defective?
2. Parts coming off an assembly line have a 1% chance of being defective. All of the parts coming off the line are inspected. Let \(X\) be the number parts inspected up to and including the first defective part.
Is \(X\) continuous or discrete?
What is the support of \(X\)?
Find the probability mass function \(p(x)\) for \(X\).
What is the probability that the first defective part is the 100th part?
3. A biased coin has a 40% chance of producing a head. If it is tossed 10 times,
What is the probability of getting exactly 3 heads?
What is the probability of getting 3 or more heads. (This can be calculated in two different ways. The easier way uses the complement rule.)
4. a. Find the value of \(C\) for which the function \(f(x) = C x^2 \cdot [\![ x \in (0,2) [\!]\) is a pdf.
Use the pdf to find \(\operatorname{P}(0 \le X \le 1)\) and \(\operatorname{P}(1 \le X \le 5)\).
Use the pdf to compute the cumulative distribution function \(F(x)\).
5. a. Find the value of \(C\) for which the function \(f(x) = \frac{C}{x^2} \cdot [\![ x \ge 1 ]\!]\) is a pdf.
What is \(\operatorname{P}(X \le 2)\)?
What is \(\operatorname{P}(X > 3)\)?
Find the cumulative distribution function \(F(x)\).
Use the cumulative distribution function to find \(\operatorname{P}(2 \le X \le 5)\).