Professional Documents
Culture Documents
3.1 Introduction
One of the main objectives of statistics is to help make “good” decisions under conditions
of uncertainty. Probability is one way to quantify outcomes that cannot be predicted with
certainty. For example, when throwing two dice, the outcome of the experiment cannot
be known before the dice are thrown. Random variables, as well as counting techniques,
will facilitate the analysis of problems such as the example of throwing two dice. This
chapter provides a brief introduction to counting techniques, axiomatic probability, random
variables, and moment generating functions.
Example 3.1 A computer store sells three brands of laptops. Each laptop is sold with a
carrying case and four di↵erent options for upgrading RAM. Suppose the store only carries
two styles of carrying cases. How many di↵erent combinations of laptop, carrying case, and
RAM are possible?
Copyright © 2015. CRC Press LLC. All rights reserved.
199
Ugarte, M. D., Militino, A. F., & Arnholt, A. T. (2015). Probability and statistics with r. CRC Press LLC.
Created from upnasp-ebooks on 2024-03-07 22:16:18.
200 Probability and Statistics with R, Second Edition
Example 3.2 How many di↵erent license plates can be made from four digits?
Solution: First, note that there is no restriction forbidding repeated digits. That is,
0001, 0002, 0003, . . . , 9999 are all permissible. In essence, this translates to sampling with
replacement. Since there are 10 choices for each of the four license plate digits, there are a
total of 10 ⇥ 10 ⇥ 10 ⇥ 10 = 104 = 10, 000 possible license plates.
Example 3.3 How many di↵erent ways can the first three places be decided in a race
with four runners?
Solution: The number of ways the first three places can be decided using the basic prin-
ciple of counting is by reasoning as follows:
Any one of the four runners might arrive in first place (four outcomes for the first ex-
periment). After the first runner crosses the finish line, there are three possible choices
for second place (three outcomes for the second experiment). Then, after second place is
decided, there are only two runners left (two outcomes for the third experiment). Conse-
quently, there are 4 · 3 · 2 = 24 possible ways to award the first three places. The problem
may also be solved by applying the permutation formula:
4! 4!
P3,4 = = = 4 · 3 · 2 = 24.
(4 3)! 1!
> factorial(4)/factorial(4 - 3)
[1] 24
Example 3.4 How many ways can seven students form a line?
Solution: First, note that once a student is selected for a place in line, the number of
Copyright © 2015. CRC Press LLC. All rights reserved.
students for subsequent orderings is diminished by one. That is, this is a problem where
sampling is done without replacement. A useful strategy for this type of problem is actually
to think through assigning the students to positions before using a formula (permutation
in this case). If seven slots are drawn, then the reasoning is as follows:
There are seven ways a student can be assigned to the first slot. Once the first slot has
been assigned, there are six possible ways to pick a student for the next slot. Continue
with this logic until all of the students have been assigned a slot. Appealing to the basic
principle of counting, it is seen that there are 7 ⇥ 6 ⇥ 5 ⇥ 4 ⇥ 3 ⇥ 2 ⇥ 1 = 7! = 5040 possible
ways to form a line with seven students. This is the same number calculated by considering
a permutation of seven things taken seven at a time P7,7 = (7 7!7)! = 7! 0! = 5040. Note that
0! = 1.
Ugarte, M. D., Militino, A. F., & Arnholt, A. T. (2015). Probability and statistics with r. CRC Press LLC.
Created from upnasp-ebooks on 2024-03-07 22:16:18.
Chapter 3: General Probability and Random Variables 201
> factorial(7)/factorial(7 - 7)
[1] 5040
Example 3.5 How many di↵erent letter arrangements can be formed using the letters
DATA?
Solution: Note that there are 4! permutations of the letters D1 A1 T1 A2 when the two A’s
are distinguished from each other. However, since the A’s are indistinguishable, there are
4!
only 2!·1!·1! = 12 possible permutations of the letters DATA.
> factorial(4)/(factorial(2) * factorial(1) * factorial(1))
[1] 12
3.2.3 Combinations
In many problems, selecting k objects from n total objects without regard to order is the
scenario of interest. For example, when selecting a committee, the order of the committee
is rarely important. That is, a committee consisting of John, Mary, and Paul is considered
the same committee if the members are listed as Mary, Paul, and John. An arrangement
of k objects taken from n objects without regard to order is called a combination. The
number of combinations of n distinct objects taken k at a time is denoted as Ck,n or nk
and is calculated as
✓ ◆
n n!
Ck,n = = .
k k!(n k)!
The R function to compute the number of combinations of n distinct objects taken k at a
time is choose(n, k).
Copyright © 2015. CRC Press LLC. All rights reserved.
Example 3.6 A committee of three people is to be formed from a group of eight people.
How many di↵erent committees are possible?
8 8!
Solution: There are C3,8 = 3 = 3!·(8 3)! = 56 possible committees.
> choose(n = 8, k = 3)
[1] 56
Example 3.7 How many di↵erent three-letter sequences can be formed from the letters
A, B, C, and D if
Ugarte, M. D., Militino, A. F., & Arnholt, A. T. (2015). Probability and statistics with r. CRC Press LLC.
Created from upnasp-ebooks on 2024-03-07 22:16:18.
202 Probability and Statistics with R, Second Edition
(b) Since letters may be used more than once, there are 43 = 64 possible sequences.
4
(c) Since order does not matter, there are C3,4 = 3 = 4 possible sequences.
Example 3.8 If nine people are to be assigned into three committees of sizes two, three,
and four, respectively, how many possible assignments exist?
Solution: There are 92 ways to pick the first committee. Once that committee is selected,
there are seven members left from which a committee of size three is selected. So, there are
7
3 ways to pick the second committee. Using the same logic, there are finally four members
left from which one committee of size four must be selected. There is only one way to select
the remaining committee, which is to select all of the remaining members to be on the
committee. Using the basic rule of multiplication, there are a total of 92 ⇥ 73 ⇥ 44 =
1260 ways to form the three committees. To compute the final answer, the R commands
choose(), factorial(), or a combination of the two can be used as shown in R Code 3.1.
Note that the following are all equivalent:
✓ ◆ ✓ ◆ ✓ ◆
9 7 4 9! 7! 4! 9! 9! 7!
⇥ ⇥ = ⇥ ⇥ = = ⇥ = 1260.
2 3 4 2!7! 3!4! 4! 2!3!4! 2!7! 3!4!
R Code 3.1
[1] 1260
[1] 1260
[1] 1260
Ugarte, M. D., Militino, A. F., & Arnholt, A. T. (2015). Probability and statistics with r. CRC Press LLC.
Created from upnasp-ebooks on 2024-03-07 22:16:18.
Chapter 3: General Probability and Random Variables 203
important topics such as how likely one is to be in an accident on any given day, probability
is how this likeliness is described. Definitions and axioms associated with probability will
formalize concepts associated with possible outcomes in any non-determinate situation.
1. Commutative laws
2. Associative laws
3. Distributive laws
Ugarte, M. D., Militino, A. F., & Arnholt, A. T. (2015). Probability and statistics with r. CRC Press LLC.
Created from upnasp-ebooks on 2024-03-07 22:16:18.
204 Probability and Statistics with R, Second Edition
• (E \ F ) [ G = (E [ G) \ (F [ G)
• (E [ F ) \ G = (E \ G) [ (F \ G)
4. DeMorgan’s laws
1
!c 1
[ \
• Ei = Eic
i=1 i=1
1
!c 1
\ [
• Ei = Eic
i=1 i=1
Suppose an experiment can be performed n times under the same conditions with sample
space ⌦. Let n(E) denote the number of times (in n experiments) that the event E occurs.
The relative frequency approach to probability defines the probability of the event E, written
P(E), as
Copyright © 2015. CRC Press LLC. All rights reserved.
n(E)
P(E) = lim .
n!1 n
Ugarte, M. D., Militino, A. F., & Arnholt, A. T. (2015). Probability and statistics with r. CRC Press LLC.
Created from upnasp-ebooks on 2024-03-07 22:16:18.
Chapter 3: General Probability and Random Variables 205
1. 0 P(E) 1
2. P(⌦) = 1
The following results are all easily derived using some combination of the three axioms
of probability:
1. P(E c ) = 1 P(E)
Proof: Note that E [ F can be represented as the union of two mutually exclusive
events, E and (E c \F ). That is, E [F = E [(E c \F ). Event F can also be represented
as the union of two mutually exclusive events, (E \ F ) and (E c \ F ). By probability
axiom 3, P(E [ F ) = P(E) + P(E c \ F ) as well as P(F ) = P(E \ F ) + P(E c \ F ).
By solving for P(E c \ F ) in the second equation and substituting the answer into the
first equation, the desired result of P(E [ F ) = P(E) + P(F ) P(E \ F ) is obtained.
3. P(;) = 0
Ugarte, M. D., Militino, A. F., & Arnholt, A. T. (2015). Probability and statistics with r. CRC Press LLC.
Created from upnasp-ebooks on 2024-03-07 22:16:18.
206 Probability and Statistics with R, Second Edition
Solution: Let the event E denote two or more students with the same birthday. In this
problem, it is easier to find E c , as there are a number of ways that E can take place. There
are a total of 365m possible outcomes in the sample space. E c can occur in 365 ⇥ 364 ⇥
· · · ⇥ (365 m + 1) ways. Consequently,
R Code 3.2
Students ProbAtL2SB
[1,] 10 0.1169482
[2,] 15 0.2529013
[3,] 20 0.4114384
[4,] 25 0.5686997
[5,] 30 0.7063162
[6,] 35 0.8143832
[7,] 40 0.8912318
[8,] 45 0.9409759
[9,] 50 0.9703736
R Code 3.3 can be used to create or modify a graph such as the one shown in Figure 3.1 on
the facing page that plots the probability of at least two students with the same birthday
versus the number of students in the room. The dashed horizontal line in Figure 3.1 on the
next page is drawn at 0.5 so that the reader can obtain an idea of the number of students
required for the probability to exceed 0.5, which is 23. A dashed vertical line is drawn at 23
so the reader can see that the probability of at least two students having the same birthday
is greater than 0.5 for m 23.
R Code 3.3
Copyright © 2015. CRC Press LLC. All rights reserved.
Ugarte, M. D., Militino, A. F., & Arnholt, A. T. (2015). Probability and statistics with r. CRC Press LLC.
Created from upnasp-ebooks on 2024-03-07 22:16:18.
Chapter 3: General Probability and Random Variables 207
1.0
P(at least 2 students with the same birthday)
0.8
0.6
0.4
0.2
0.0
0 10 20 30 40 50 60
m = Number of students in the room
FIGURE 3.1: Probability of two or more students having the same birthday
Table 3.1: Probability of two or more students having the same birthday
m P(E)
10 0.1169482
15 0.2529013
20 0.4114384
25 0.5686997
30 0.7063162
35 0.8143832
40 0.8912318
45 0.9409759
50 0.9703736
Example 3.10 In a class using this text, suppose that 30% of the students are taking a
Copyright © 2015. CRC Press LLC. All rights reserved.
computer science course, 45% of the students are taking a mathematics course, and 10%
are taking both a computer science and a mathematics course.
(a) What is the probability a randomly selected student is taking a computer science course
or a mathematics course?
(b) What is the probability a randomly selected student is taking a computer science course
but not a mathematics course?
(c) What is the probability a randomly selected student is taking a mathematics course
but not a computer science course?
Ugarte, M. D., Militino, A. F., & Arnholt, A. T. (2015). Probability and statistics with r. CRC Press LLC.
Created from upnasp-ebooks on 2024-03-07 22:16:18.
208 Probability and Statistics with R, Second Edition
(d) What is the probability a randomly selected student is taking neither a mathematics
course nor a computer science course?
Solution: Let the events M and C represent taking a mathematics and a computer science
course, respectively. Then, P(C) = 0.30, P(M ) = 0.45, and P(C \ M ) = 0.10.
(a) Since P(C [ M ) = P(C) + P(M ) P(C \ M ), P(C [ M ) = 0.3 + 0.45 0.10. Thus,
P(C [ M ) = 0.65.
(b) Since P(C \ M c ) = P(C) P(C \ M ), P(C \ M c ) = 0.3 0.10. Thus, P(C [ M c ) = 0.20.
(c) Since P(C c \M ) = P(M ) P(C \M ), P(C c \M ) = 0.45 0.10. Thus, P(C c [M ) = 0.35.
It is left as an exercise for the reader to verify that P(F |E) satisfies the three axioms of
probability.
Example 3.11 Suppose two fair dice are rolled where each of the 36 possible outcomes is
equally likely to occur. Knowing that the first die shows a 4, what is the probability that
the sum of the two dice equals 8?
Solution: The sample space for this experiment is given as ⌦= {(i, j), i = 1, 2, . . . , 6,
j = 1, 2, . . . , 6}, where each pair (i, j) has a probability 1/36 of occurring. Define “the
sum of the dice equals 8” to be event H and “a 4 on the first toss” to be event G. Since
H \ G corresponds to the outcome (4, 4) with probability P(H \ G) = 1/36 and there are
six outcomes with a 4 on the first toss, (4, 1), (4, 2), . . . , (4, 6), the probability of event H,
Copyright © 2015. CRC Press LLC. All rights reserved.
P(H \ G) 1/36 1
P(H|G) = = = .
P(G) 1/6 6
The R function expand.grid() is used to enumerate the possible outcomes in the sample
space, ⌦, which is stored in the R object Omega in R Code 3.4.
R Code 3.4
Ugarte, M. D., Militino, A. F., & Arnholt, A. T. (2015). Probability and statistics with r. CRC Press LLC.
Created from upnasp-ebooks on 2024-03-07 22:16:18.
Chapter 3: General Probability and Random Variables 209
roll1 roll2
12 6 2
17 5 3
22 4 4
27 3 5
32 2 6
roll1 roll2
4 4 1
10 4 2
16 4 3
22 4 4
28 4 5
34 4 6
[1] 1/6
roll1 roll2
22 4 4
[1] 1/36
[1] 1/6
Copyright © 2015. CRC Press LLC. All rights reserved.
It is often the case that it is easier to solve a conditional probability problem, P(H|G), by
enumerating the number of outcomes in the conditioning event G, then enumerating the
number of outcomes in H in the reduced sample space G. Consider R Code 3.5, which takes
this approach to solve P(H|G).
R Code 3.5
> library(MASS)
> Omega <- expand.grid(roll1 = 1:6, roll2 = 1:6)
> G <- subset(Omega, roll1 == 4) # event G
> G
Ugarte, M. D., Militino, A. F., & Arnholt, A. T. (2015). Probability and statistics with r. CRC Press LLC.
Created from upnasp-ebooks on 2024-03-07 22:16:18.
210 Probability and Statistics with R, Second Edition
roll1 roll2
4 4 1
10 4 2
16 4 3
22 4 4
28 4 5
34 4 6
roll1 roll2
22 4 4
roll1 roll2
22 4 4
roll1 roll2
22 4 4
[1] 1/6
Example 3.12 Suppose a box contains 50 defective light bulbs, 100 partially defective
light bulbs (last only 3 hours), and 250 good light bulbs. If one of the bulbs from the box is
used and it does not immediately go out, what is the probability the light bulb is actually
a good light bulb?
Solution: The conditional probability the light bulb is good given that the light bulb is
not defective is desired. Using (3.1), write
P(Good) 250/400 5
P(Good|Not Defective) = = = .
Copyright © 2015. CRC Press LLC. All rights reserved.
Ugarte, M. D., Militino, A. F., & Arnholt, A. T. (2015). Probability and statistics with r. CRC Press LLC.
Created from upnasp-ebooks on 2024-03-07 22:16:18.
Chapter 3: General Probability and Random Variables 211
In other situations, we are interested in computing P(Fj |E). When this happens, Bayes’
Rule is used, which is derived Sn using (3.1), to find the answer. Bayes’ Rule — Let
F1 , F2 , . . . , Fn be such that i=1 Fi = ⌦ and Fi \ Fj = ; for all i 6= j, with P(Fi ) >
0 for all i. Then,
P(E \ Fj ) P(E|Fj )P(Fj )
P(Fj |E) = = Pn . (3.3)
P(E) i=1 P(E|Fi )P(Fi )
A B
P(C \ B) = 0.018
P(C \ A) = 0.0275
Example 3.14 Suppose a student answers all of the questions on a multiple-choice test.
Let p be the probability the student actually knows the answer and 1 p be the probability
the student is guessing for a given question. Assume students that guess have a 1/a proba-
bility of getting the correct answer, where a represents the number of possible responses to
the question. What is the conditional probability a student knew the answer to a question
given that he answered correctly?
Ugarte, M. D., Militino, A. F., & Arnholt, A. T. (2015). Probability and statistics with r. CRC Press LLC.
Created from upnasp-ebooks on 2024-03-07 22:16:18.
212 Probability and Statistics with R, Second Edition
Solution: Let the events E, F1 , and F2 represent the events “question answered correctly,”
“student knew the correct answer,” and “student guessed,” respectively. Using (3.3), write
P(F1 \ E) P(F1 ) p
P(F1 |E) = = = .
P(E) P(E|F1 )P(F1 ) + P(E|F2 )P(F2 ) p + (1 p)/a
As a special case, if a = 4 and p = 1/2, then the probability a student actually knew the
answer given their response was correct is 4/5.
Example 3.15 ⇤ Bayes’ Rule: Choose a Door The television show Let’s Make a
Deal, hosted by Monty Hall, gave contestants the opportunity to choose one of three doors.
Contestants hoped to choose the one that concealed the grand prize. Behind the other two
doors were much less valuable prizes. After the contestant chose one of the doors, say Door
1, Monty opened one of the other two doors, say Door 3, containing a much less valuable
prize. The contestant was then asked whether he or she wished to stay with the original
choice (Door 1) or switch to the other closed door (Door 2). What should the contestant
do? Is it better to stay with the original choice or to switch to the other closed door? Or
does it really matter? The answer, of course, depends on whether contestants improve their
chances of winning by switching doors. In particular, what is the probability of winning
by switching doors when given the opportunity; and what is the probability of winning
by staying with the initial door selection? First, simulate the problem with R to provide
approximate probabilities for the various strategies. Following the simulation, show how
Bayes’ Rule can be used to solve the problem exactly.
Solution: To simulate the problem, generate a random vector named actual of size 10,000
containing the numbers 1, 2, and 3. In the vector actual, the numbers 1, 2, and 3 represent
the door behind which the grand prize is contained. Then, generate another vector named
aguess of size 10,000 containing the numbers 1, 2, and 3 to represent the contestant’s
initial guess. If the ith values of the vectors actual and aguess agree, the contestant wins
the grand prize by staying with his initial guess. On the other hand, if the ith values of
the vectors actual and aguess disagree, the contestant wins the grand prize by switching.
Consider R Code 3.6 and the results that suggest the contestant is twice as likely to win
the grand prize by switching doors.
R Code 3.6
To solve with Bayes’ Rule, start by assuming the contestant initially guesses Door 1 and
that Monty opens Door 3. Let the event Di = Door i conceals the prize and Oj = Monty
opens door j after the contestant selects Door 1. When a contestant initially selects a door,
Ugarte, M. D., Militino, A. F., & Arnholt, A. T. (2015). Probability and statistics with r. CRC Press LLC.
Created from upnasp-ebooks on 2024-03-07 22:16:18.
Chapter 3: General Probability and Random Variables 213
P(D1 ) = P(D2 ) = P(D3 ) = 1/3. (Similar reasoning works independent of the originally
selected door.) Once Monty shows the grand prize is not behind Door 3, the probability
of winning the grand prize is now one of P(D1 |O3 ) or P(D2 |O3 ). Note that P(D1 |O3 )
corresponds to the strategy of sticking with the initial guess and P(D2 |O3 ) corresponds
to the strategy of switching doors. Based on how the show is designed, the following are
known:
• P(O3 |D1 ) = 1/2 since Monty can open one of either Door 3 or Door 2 without revealing
the grand prize.
• P(O3 |D2 ) = 1 since the only door Monty can open without revealing the grand prize
is Door 3.
• P(O3 |D3 ) = 0 since Monty will not open Door 3 if it contains the grand prize.
P(Ei1 \ Ei2 \ · · · \ Eik ) = P(Ei1 ) · P(Ei2 ) · · · · · P(Eik ). It is important to point out that
events in any subset of the original independent events of size r, where r k, are also
independent. Further, if events E1 , . . . , En are independent, then so are E1c , . . . , Enc .
Ugarte, M. D., Militino, A. F., & Arnholt, A. T. (2015). Probability and statistics with r. CRC Press LLC.
Created from upnasp-ebooks on 2024-03-07 22:16:18.
214 Probability and Statistics with R, Second Edition
1j 2j
3j
Solution: Let Ai (i = 1, 2, 3) be the event the ith component works, and E the event the
entire system works. Consequently, event E = (A1 \A2 )[A3 , and P(E) = P[(A1 \A2 )[A3 ].
P(E) = P[(A1 \ A2 ) [ A3 ]
= P(A1 \ A2 ) + P(A3 ) P(A1 \ A2 \ A3 )
= P(A1 )P(A2 ) + P(A3 ) P(A1 )P(A2 )P(A3 )
= (0.9)(0.9) + 0.9 (0.9)(0.9)(0.9)
= 0.981.
3. Individual 40-kilometer cycling time trial. X = the time to complete the course.
Ugarte, M. D., Militino, A. F., & Arnholt, A. T. (2015). Probability and statistics with r. CRC Press LLC.
Created from upnasp-ebooks on 2024-03-07 22:16:18.
Chapter 3: General Probability and Random Variables 215
An estimate of f (x) = p(x) = P(X = x) is the number of sample points equal to x divided by
n, the sample size. This estimate is called the empirical probability density function,
epdf or the empirical probability mass function, epmf, and is defined as
n
X
fbn (t) = I {xi = t}/n. (3.4)
i=1
Here, I {xi = t} is the indicator function that returns a value of 1 when xi = t and 0 when
xi 6= t.
The cumulative distribution function, cdf, is defined as
X
F (x) = P(X x) = p(k).
kx
1. 0 F (x) 1.
2. If a < b, then F (a) F (b) for any real numbers a and b. In other words, F (x) is a
non-decreasing function of x.
3. lim F (x) = 1.
x!1
4. lim F (x) = 0.
x! 1
5. F (x) is a step function, and the height of the step at x is equal to f (x) = P(X = x).
An estimate of F (x) = P(X x) is the proportion of sample values that fall in the interval
( 1, x]. This estimate is called the empirical cumulative distribution function, ecdf,
and is defined as
Copyright © 2015. CRC Press LLC. All rights reserved.
n
X
Fbn (t) = I {xi t}/n. (3.5)
i=1
Here, I {xi t} is the indicator function that returns a value of 1 when xi t and 0 when
xi > t. The R function ecdf() will compute Fbn (t) when a numeric vector of sample values
is supplied to the argument x=. If the values supplied to x= are values of a discrete random
variable, one may use plot(ecdf(x)) to graph the cdf.
Example 3.17 Toss a fair coin three times and let the random variable X represent the
number of heads in the three tosses. Produce graphical representations of both the pdf and
cdf for the random variable X.
Ugarte, M. D., Militino, A. F., & Arnholt, A. T. (2015). Probability and statistics with r. CRC Press LLC.
Created from upnasp-ebooks on 2024-03-07 22:16:18.
216 Probability and Statistics with R, Second Edition
The random variable X can take on the values 0, 1, 2, and 3 with probabilities 18 , 38 , 38 , and
8 , respectively. Define the cdf for X, F (x) = P(X x) as follows:
1
8
>
> 0 if x < 0,
>
>
>
> 1/8 if 0 x < 1,
<
F (x) = 4/8 if 1 x < 2,
>
>
>
> 7/8 if 2 x < 3, and
>
>
:1 if x 3.
The code for producing a graph similar to Figure 3.4 on the next page with placement of
specific values along the axes for both the pdf and cdf using the function axis() is given in
R Code 3.7.
R Code 3.7
n.heads
0 1 2 3
1/8 3/8 3/8 1/8
> plot(T1, xlab = "x", ylab="P(X = x)", yaxt = "n", main = "PDF for X")
> axis(2, at = c(1/8, 3/8), labels = c("1/8", "3/8"), las = 1)
Ugarte, M. D., Militino, A. F., & Arnholt, A. T. (2015). Probability and statistics with r. CRC Press LLC.
Created from upnasp-ebooks on 2024-03-07 22:16:18.
Chapter 3: General Probability and Random Variables 217
> plot(ecdf(n.heads), main = "CDF for X", ylab = "F(x)", xlab = "x",
+ yaxt = "n")
> axis(2, at = c(1/8, 4/8, 7/8, 1), labels = c("1/8", "4/8", "7/8", "1"),
+ las = 1)
> segments(1, 1/8, 1, 4/8, lty = 2)
> text(2.6, 2.5/8, "P(X = 1) = F(1) - F(0)")
> par(opar)
F (x) 4
8
1
8 P(X = 1) = F (1) F (0)
1
8
0 1 2 3 -1 0 1 2 3 4
x x
FIGURE 3.4: The pdf and cdf for the random variable X, the number of heads in three
tosses of a fair coin
is considered, the modes are 1 and 2; and any value m between 1 and 2 inclusive satisfies
the definition for the median. The 25th percentile of the distribution of X is 1 because
P(X 1) = 48 100 and P(X
25
1) = 78 1 100 25
.
Ugarte, M. D., Militino, A. F., & Arnholt, A. T. (2015). Probability and statistics with r. CRC Press LLC.
Created from upnasp-ebooks on 2024-03-07 22:16:18.
218 Probability and Statistics with R, Second Edition
E[X] can also be denoted as µX , because E[X] is the mean of the random variable X. In
this definition, it is assumed the sum exists; otherwise, the expectation is undefined. It can
be helpful to think of E[X] as the fulcrum on a balanced beam as illustrated in Figure 3.5.
Example 3.18 A particular game is played where the contestant spins a wheel that can
land on the numbers 1, 5, or 30 with probabilities of 0.50, 0.45, and 0.05, respectively. The
contestant pays $5 to play the game and is awarded the amount of money indicated by the
number where the spinner lands. Is this a fair game?
Solution: By fair, it is meant that the contestant should have an expected return equal
to the price she pays to play the game. To answer the question, the expected (average)
winnings from playing the game need to be computed. Let the random variable X represent
the player’s winnings:
X
E[X] = x · p(x) = (1 ⇥ 0.50) + (5 ⇥ 0.45) + (30 ⇥ 0.05) = 4.25.
x
Therefore, this game is not fair, as the house makes an average of 75 cents each time the
game is played. Another interpretation of the expected value of the random variable X is
to view it as a weighted mean. Code to compute the expected value using (3.6) and using
the function weighted.mean() is illustrated in R Code 3.8.
R Code 3.8
Often, a random variable itself is not of interest, but rather some function of the random
variable X is important, say g(X). The expected value of a function g(X) of the random
variable X with pdf p(x) is
⇥ ⇤ X
E g(X) = g(x) · p(x). (3.7)
x
Ugarte, M. D., Militino, A. F., & Arnholt, A. T. (2015). Probability and statistics with r. CRC Press LLC.
Created from upnasp-ebooks on 2024-03-07 22:16:18.
Chapter 3: General Probability and Random Variables 219
Example 3.19 Consider Example 3.18, for which the random variable Y is defined to be
the player’s net return. That is, Y = X 5 since the player spends $5 to play the game.
What is the expected value of Y ?
Solution: The expected value of Y is
X
E[Y ] = (x 5) · p(x) = ( 4 ⇥ 0.50) + (0 ⇥ 0.45) + (25 ⇥ 0.05) = 0.75.
x
R Code 3.9 uses both (3.7) and the weighted.mean() function to compute the E[Y ].
R Code 3.9
Rules of Expected Value The function g(X) is often a linear function a + bX, where a
and b are constants. When this occurs, E[g(X)] is easily computed from E[X]. In Example
3.19, a and b were -5 and 1, respectively, for the linear function g(X). The following rules
for expected value, when working with a random variable X and constants a and b, are
true:
1. E[bX] = bE[X].
2. E[a + bX] = a + bE[X].
⇥ ⇤
Unfortunately, if g(X) is not a linear function of X, such as g(X) = X 2 , the E X 2 6=
2 ⇥ ⇤
(E[X]) . In general, E g(X) 6= g E[X] .
Though knowing the expected value of a random variable is important, the mean of the
distribution does not tell the whole story. Several distributions may have the same mean. In
this case, additional information, such as the spread of the distribution and the symmetry
of the distribution, is helpful in distinguishing among various distributions.
3.4.1.3 Moments
There exist special quantities that measure mean, spread, and symmetry, called mo-
ments. The r th moment about the ⇥ ⇤origin of a random variable X, denoted ↵r , is
defined as E [X r ] . Note that ↵1 = E X 1 is the mean of the distribution of X, which can
Copyright © 2015. CRC Press LLC. All rights reserved.
also be denoted µX or simply µ. The r th moment about the mean of a random variable
X, denoted µr , is the expected value of (X µ)r . (Note that this quantity does not always
exist.) For the rth moment about the origin of a discrete random variable to be well-defined,
P 1 r
i=1 |xi |P(X = xi ) must be less than 1.
Ugarte, M. D., Militino, A. F., & Arnholt, A. T. (2015). Probability and statistics with r. CRC Press LLC.
Created from upnasp-ebooks on 2024-03-07 22:16:18.
220 Probability and Statistics with R, Second Edition
Variance The second moment about the mean is called the variance of the distribution
of X, or simply the variance of X:
2
⇥ ⇤ ⇥ ⇤
Var[X] = X = E (X µ)2 = E X 2 µ2 . (3.9)
The positive square root of the variance is called the standard deviation and is denoted
X . The units of measurement for standard deviation are always the same as those for
the random variable X. One way to avoid this unit dependency is to use the coefficient
of variation, a unitless measure of variability. A unitless measure of variability is helpful
when comparing distributions measured on di↵erent scales. It is also useful when comparing
distributions with means that may be an order or more of magnitude di↵erent since the
coefficient of variation expresses the variability of a distribution in relation to the mean of
the distribution.
Definition 3.2: Coefficient of variation — When E[X] 6= 0,
X
CVX = . (3.10)
E[X]
When only a sample of data from a population of interest is available, the coefficient of
variation is estimated as
dX = S .
CV (3.11)
X
Rules of Variance If X is a random variable with mean µ and a and b are constants,
then
1. Var[b] = 0.
2. Var[aX] = a2 Var[X].
3. Var[aX + b] = a2 Var[X].
Note that once Var[aX + b] = a2 Var[X] is proved, Var[b] = 0 and Var[aX] = a2 Var[X]
have been implicitly shown.
Proof:
table marked PASS LINE and waits for the shooter (the person rolling the dice) to roll the
dice. The first roll the shooter takes is called the come out roll. If the come out roll (sum of
the two dice) is either a 7 or an 11, all bettors win the amount of money they have placed
in the PASS section of the table. If the come out roll is a 2, 3, or 12 (crapping out), all
bettors lose the amount of money they have placed in the PASS LINE section of the table
(see Figure 1.19 on page 77). If the come out roll is any other number (4, 5, 6, 8, 9, or 10),
then that number is called the shooter’s point, and the shooter rolls the dice repeatedly
until either a 7 or the shooter’s point is rolled again. If the shooter rolls a 7 before rolling
point, all bets in the PASS LINE are lost. If the shooter rolls point before rolling a 7, the
bank/casino pays all bets in the PASS LINE to the players. Compute the probability of
winning at craps.
Ugarte, M. D., Militino, A. F., & Arnholt, A. T. (2015). Probability and statistics with r. CRC Press LLC.
Created from upnasp-ebooks on 2024-03-07 22:16:18.
Chapter 3: General Probability and Random Variables 221
Solution: The probability of winning on a second roll when the come out roll was 4, 5,
6, 8, 9, or 10 is the probability that the first roll was one of those numbers multiplied by
the chance the second number matches the first. The probability of winning on a third roll
when the come out roll was 4, 5, 6, 8, 9, or 10 is the probability that the first roll was one of
those numbers multiplied by the chance the second number did not match the come out roll
OR equal a seven, which would mean a loss, multiplied by the chance the third roll matches
the come out roll. For fourth and following rolls, the failure to win is raised to one higher
a power than the roll before, still multiplying by the probability that the first roll was the
come out roll value and the last roll matches the come out roll. The contribution to win
probabilities are the results
Pof the sums of the infinite geometric series of win probabilities.
1
Recall from calculus that k=0 rk = (1 r) 1 , provided |r| < 1.
= 27 = = .
12 1 36 36 9 36
P (Win|5 as come out roll) = P (Win|9 as come out roll)
✓ ◆2 ✓ ◆ ✓ ◆2 ✓ ◆
1 1 4 36 2
= = = .
9 1 2636
36 10 45
P (Win|6 as come out roll) = P (Win|8 as come out roll)
✓ ◆2 ✓ ◆ ✓ ◆2 ✓ ◆
5 1 5 36 25
= = = .
36 1 25 36
36 11 396
Ugarte, M. D., Militino, A. F., & Arnholt, A. T. (2015). Probability and statistics with r. CRC Press LLC.
Created from upnasp-ebooks on 2024-03-07 22:16:18.
222 Probability and Statistics with R, Second Edition
Z1
2. f (x) dx = 1, and (3.12)
1
Zb
3. P(a X b) = f (x) dx.
a
Condition 3 from (3.12) for the definition of a pdf for a continuous random variable is
illustrated in Figure 3.6.
a b b a
Rb Rb Ra
a
f (x) dx 1
f (x) dx 1
f (x) dx
Ugarte, M. D., Militino, A. F., & Arnholt, A. T. (2015). Probability and statistics with r. CRC Press LLC.
Created from upnasp-ebooks on 2024-03-07 22:16:18.
Chapter 3: General Probability and Random Variables 223
Zx
F (x) = P(X x) = f (t) dt, 1 < x < 1. (3.13)
1
According to Definition 3.3, the cdf is derived from an existing pdf. Further, according
to the fundamental theorem of calculus, the pdf can also be derived from the cdf since
F 0 (x) = f (x) for all values of x for which the derivative F 0 (x) exists.
1. 0 F (x) 1.
4. lim F (x) = 0.
x! 1
(a) Find the constant k so that f (x) is a pdf of the random variable X.
(d) Graph the pdf and cdf of X using both base graphics and ggplot2.
Copyright © 2015. CRC Press LLC. All rights reserved.
Z1 Z1
1= f (x) dx = k(1 x2 ) dx
1 1
"✓ ◆ ✓ ◆#
1
x3 1 1
=k x =k 1 1
3 1 3 3
2 2 4 3
=k =k )k= .
3 3 3 4
Ugarte, M. D., Militino, A. F., & Arnholt, A. T. (2015). Probability and statistics with r. CRC Press LLC.
Created from upnasp-ebooks on 2024-03-07 22:16:18.
224 Probability and Statistics with R, Second Edition
(c) Using property 3 from (3.12) for the pdf of a continuous random variable, write
(d) R Code 3.10 can be used to create graphs similar to Figure 3.7 on the facing page, which
depicts the pdf and cdf of X.
R Code 3.10
To create graphs similar to Figure 3.7 on the next page with ggplot2 (Figure 3.8 on the
facing page), one might use code R Code 3.11 once the functions f and F from R Code 3.10
are created.
R Code 3.11
Ugarte, M. D., Militino, A. F., & Arnholt, A. T. (2015). Probability and statistics with r. CRC Press LLC.
Created from upnasp-ebooks on 2024-03-07 22:16:18.
Chapter 3: General Probability and Random Variables 225
PDF for X CDF for X
1.0
0.6
0.8
0.6
0.4
F (x)
f (x)
0.4
0.2
0.2
0.0
0.0
-2 -1 0 1 2 -2 -1 0 1 2
x x
0.6
0.75
F (x)
f (x)
0.4
0.50
0.2 0.25
0.0 0.00
-2 -1 0 1 2 -2 -1 0 1 2
x x
FIGURE 3.8: Illustration of pdf and cdf for Example 3.21 using ggplot2
a finite or infinite interval and estimates the absolute error in the approximation. To use
integrate(), the user must specify f(), the function; lower, the lower limit of integration;
and upper, the upper limit of integration. The function f() must be a real-valued R function
of the form f (x), where x is the variable of integration. In addition to using property
3 from (3.12) for the pdf of a continuous random variable to solve (c) of Example 3.21
on page 223, the problem could be solved directly by integrating the original probability
P( 0.5 X 1). That is,
Z1 1
3 3x x3 27
P( 0.5 X 1) = 1 x2 dx = = = 0.84375.
4 4 4 0.5 32
0.5
Ugarte, M. D., Militino, A. F., & Arnholt, A. T. (2015). Probability and statistics with r. CRC Press LLC.
Created from upnasp-ebooks on 2024-03-07 22:16:18.
226 Probability and Statistics with R, Second Edition
R Code 3.12
> ans <- integrate(fx, lower = -0.5, upper = 1)$value # just the value
> ans
[1] 0.84375
[1] 27/32
Zm Z1
1
f (x) dx = f (x) dx = .
2
1 m
Zxj
j
f (x) dx = .
100
1
2x
2e if x > 0
f (x) =
0 if x 0,
Ugarte, M. D., Militino, A. F., & Arnholt, A. T. (2015). Probability and statistics with r. CRC Press LLC.
Created from upnasp-ebooks on 2024-03-07 22:16:18.
Chapter 3: General Probability and Random Variables 227
Rm 2x
(a) The median is the value m such that 2e dx = 0.5, which implies
0
2x m
e 0
= 0.5
2m
e + 1 = 0.5
2m
e = 0.5 1
2m
ln(e ) = ln(0.5)
ln(0.5)
m= = 0.3466.
2
xR25
(b) The 25th percentile is the value x25 such that 2e 2x
dx = 0.25, which implies
0
2x x25
e 0
= 0.25
2x25
e + 1 = 0.25
2x25
e = 0.25 1
2x25
ln(e ) = ln(0.75)
ln(0.75)
x25 = = 0.1438.
2
xR60
(c) The 60th percentile is the value x60 such that 2e 2x
dx = 0.60, which implies
0
2x x60
e 0
= 0.60
2x60
e + 1 = 0.60
2x60
e = 0.60 1
2x60
ln(e ) = ln(0.40)
ln(0.40)
x60 = = 0.4581.
2
(c) Draw the pdf and add a dashed vertical line at the median of the distribution.
(a) The function 2 cos 2x does not have a maximum in the open interval (0, ⇡ /4) since the
derivative f 0 (x) = 4 sin 2x does not equal 0 in the open interval (0, ⇡ /4).
Ugarte, M. D., Militino, A. F., & Arnholt, A. T. (2015). Probability and statistics with r. CRC Press LLC.
Created from upnasp-ebooks on 2024-03-07 22:16:18.
228 Probability and Statistics with R, Second Edition
Zm
2 cos 2x dx = 0.5
0
+
m
sin 2x 0
= sin 2m = 0.5
2m = arcsin(0.5)
⇡
m= .
12
(c) R Code 3.13 can be used to create a graph similar to Figure 3.9. After the function f is
defined, the next two lines of R Code 3.13 produce the requested graph with base graphics.
The last three lines of R Code 3.13 produce the requested graph with ggplot2.
R Code 3.13
0.7
0.6
2cos(2x)
0.5
Copyright © 2015. CRC Press LLC. All rights reserved.
0.4
0.3
⇡
FIGURE 3.9: Graph of 2 cos(2x) from 0 to 4 with R
Ugarte, M. D., Militino, A. F., & Arnholt, A. T. (2015). Probability and statistics with r. CRC Press LLC.
Created from upnasp-ebooks on 2024-03-07 22:16:18.
Chapter 3: General Probability and Random Variables 229
When the integral in (3.15) does not exist, neither does the expectation of the random
variable X. The expected value of a function of X, say g(X), is
Z1
⇥ ⇤
E g(X) = g(x) · f (x) dx. (3.16)
1
Using the definitions for moments about 0 and µ given in (3.8), which relied strictly on
expectation in conjunction with (3.16), the variance of a continuous random variable X is
written as
Z1
2
⇥ ⇤
Var[X] = X = E (X µ)2 = (x µ)2 f (x) dx. (3.17)
1
f (x) = k, 1<x<1
(a) Find the value of k to make f (x) a pdf. Use this k for parts (c) and (d).
Z1
k dx = 1
1
1
kx 1
=1
1
2k = 1 ) k = .
2
(b) R Code 3.14 on the next page is used to create Figure 3.10 on the following page.
Ugarte, M. D., Militino, A. F., & Arnholt, A. T. (2015). Probability and statistics with r. CRC Press LLC.
Created from upnasp-ebooks on 2024-03-07 22:16:18.
230 Probability and Statistics with R, Second Edition
R Code 3.14
1.00
0.75
f (x)
0.50
0.25
0.00
-1.0 -0.5 0.0 0.5 1.0
x
Z1
1
E[X] = µX = x dx
2
1
1
x2
= =0
4 1
Z1
2
⇥ 2
⇤
Var[X] = X = E (X µ) = (x µ)2 f (x) dx
Copyright © 2015. CRC Press LLC. All rights reserved.
1
Z1
1
= (x 0)2 dx
2
1
1
x3 1
= =
6 1 3
Ugarte, M. D., Militino, A. F., & Arnholt, A. T. (2015). Probability and statistics with r. CRC Press LLC.
Created from upnasp-ebooks on 2024-03-07 22:16:18.
Chapter 3: General Probability and Random Variables 231
E[g(X)]
P g(X) K . (3.18)
K
Proof:
Step 2. Since g(X) 0 and I g(X) 1, when the first condition of I g(X) is divided by
K,
g(X)
I g(X) .
K
Step 3. Taking the expected value,
E[g(X)]
E[I(g(X))] .
K
Step 4. Clearly
⇥ ⇤ X
E I g(X) = I g(x) · p(x)
x
h ⇣ ⌘i h ⇣ ⌘i
= 1 · P I g(X) = 1 + 0 · P I g(X) = 0
⇥ ⇤ ⇥ ⇤
= 1 · P g(X) K + 0 · P g(X) < K
= P g(X) K .
Step 5. Rewriting,
E[g(X)]
P g(X)
, K
K
which is the inequality from (3.18) to be proven.
⇥ ⇤
E (X µ)2 2
1
P (X µ)2 k2 2
2 2
= 2 2
= 2. (3.19)
k k k
Working inside the probability on the left side of the inequality in (3.19), note that
⇣ ⌘ ⇣ p ⌘ ⇣ p ⌘
(X µ)2 k 2 2 ) X µ k 2 2 or X µ k2 2
⇣ p ⌘
) |X µ| k2 2
⇣ ⌘
) |X µ| k .
Ugarte, M. D., Militino, A. F., & Arnholt, A. T. (2015). Probability and statistics with r. CRC Press LLC.
Created from upnasp-ebooks on 2024-03-07 22:16:18.
232 Probability and Statistics with R, Second Edition
Example 3.25 Consider Example 3.17 on page 215, where X was defined to be the
number of heads in three tosses of a fair coin. Chebyshev’s Inequality guarantees at least
what fraction of the distribution of X is within k = 2 standard deviations from its mean?
What is the actual fraction of the distribution of X that is within k = 2 standard deviations
from its mean?
Solution: Using version (d) of Chebyshev’s Inequality, P(|X µ| < k ) 1 k12 , compute
the first answer to be 1 212 = 34 . To answer the second question, first find the mean and
variance of X:
X 1 3 3 1 3
E[X] = x p(x) = 0 ⇥ + 1 ⇥ + 2 ⇥ + 3 ⇥ = = 1.5,
x
8 8 8 8 2
⇥ ⇤ X 1 3 3 1 24
2
E X = x2 p(x) = 02 ⇥ + 12 ⇥ + 22 ⇥ + 32 ⇥ = = 3, and
Copyright © 2015. CRC Press LLC. All rights reserved.
x
8 8 8 8 8
⇥ ⇤ 2
Var[X] = E X 2 E[X] =3 1.52 = 0.75.
For this example,
p
P(|X µ| < k ) = P(|X 1.5| < 2 0.75)
= P(|X 1.5| < 1.732)
= P( 0.232 < X < 3.232) = 1.
Ugarte, M. D., Militino, A. F., & Arnholt, A. T. (2015). Probability and statistics with r. CRC Press LLC.
Created from upnasp-ebooks on 2024-03-07 22:16:18.
Chapter 3: General Probability and Random Variables 233
k = 2 standard deviations from the mean illustrates the conservative nature of Chebyshev’s
Inequality. R Code 3.15 computes the mean and variance of X as well as the interval
|X µ| < 2 .
R Code 3.15
E(X) V(X)
1.50 0.75
Proof: Consider the random variables X1 , . . . , Xn such that the mean of each one is µ and
the variance of each one is 2 . Since
Pn Pn 2
i=1 Xi i=1 Xi
Copyright © 2015. CRC Press LLC. All rights reserved.
E = µ and Var = ,
n n n
use version (a) of Chebyshev’s Inequality with k = ✏ to write
!
2
X 1 + · · · + Xn
P µ ✏ 2,
n n✏
Ugarte, M. D., Militino, A. F., & Arnholt, A. T. (2015). Probability and statistics with r. CRC Press LLC.
Created from upnasp-ebooks on 2024-03-07 22:16:18.
234 Probability and Statistics with R, Second Edition
3.4.5 Skewness
Earlier it was discussed that the second moment about the mean of a random variable
X is the same thing as the variance of X. Now, the third moment about the mean of a
random variable X is used in the definition of the skewness of X. To facilitate the notation
used with skewness, first define a standardized random variable X ⇤ to be:
X µ
X⇤ = ,
where µ is the mean of X and is the standard deviation of X. Using the standardized
form of X, it is easily shown that E[X ⇤ ] = 0 and Var[X ⇤ ] = 1. Define the skewness of a
random variable X, denoted 1 , to be the third moment about the origin of X ⇤ :
⇥ ⇤
⇥ ⇤ 3 ⇤ E (X µ)3
1 = E (X ) = 3
. (3.22)
Positive values for 1 indicate a distribution that is skewed to the right while negative values
for 1 indicate a distribution that is skewed to the left. If the distribution of X is symmetric
with respect to its mean, then its skewness is zero. That is, 1 = 0 for distributions that
are symmetric about their mean. Examples of distributions with various 1 coefficients are
shown in Figure 3.11.
FIGURE 3.11: Distributions with 1 (skewness) coefficients that are negative, zero, and
positive, respectively
E[(X µ)3 ]
1 = E[(X ⇤ )3 ] = 3
= 0.588
which means the distribution has a negative skew. R Code 3.16 on the facing page uses the
following facts to compute the answer:
1. µ = E[X].
p
2. = E[X 2 ] E[X]2 .
Ugarte, M. D., Militino, A. F., & Arnholt, A. T. (2015). Probability and statistics with r. CRC Press LLC.
Created from upnasp-ebooks on 2024-03-07 22:16:18.
Chapter 3: General Probability and Random Variables 235
X µ
3. X ⇤ = .
⇥ ⇤
4. 1 = E (X ⇤ )3 .
R Code 3.16
[1] -0.5879747
1 2 3 4 5
x
Ugarte, M. D., Militino, A. F., & Arnholt, A. T. (2015). Probability and statistics with r. CRC Press LLC.
Created from upnasp-ebooks on 2024-03-07 22:16:18.
236 Probability and Statistics with R, Second Edition
⇥ ⇤ Z1
tX
MX (t) = E e = etx f (x) dx, h < t < h, (3.23)
1
f (x) = k, 1<x<1
of the random variable X, find the mgf of the distribution using (3.23).
1
Solution: The reader may verify that a value of k = 2 produces a valid pdf. The mgf of
the distribution will then be
Z1
⇥ tX
⇤
MX (t) = E e = etx f (x) dx, h<t<h
1
Z1 1
1 etx
= etx dx =
2 2t 1
1
t t
e e
= , t 6= 0.
2t
⇥ ⇤ ⇥ ⇤
Note that if t = 0, then MX (t) = 1 since MX (t) = E etX = E e0 = 1. Therefore, the
mgf is written
8 t t
<e e
if t 6= 0 and
MX (t) = 2t
:1 if t = 0.
Copyright © 2015. CRC Press LLC. All rights reserved.
Theorem 3.2 If X has mgf MX (t), then the derivatives of MX (t) of all orders exist at
t = 0, and
dr
E[X r ] = MX (t)|t=0 .
dtr
A proof of the last theorem is beyond the scope of this text; however, assuming the
distribution is discrete and summation and di↵erentiation may be interchanged, note that
the rth moment about the origin, ↵r = E[X r ], is equal to the rth derivative of the moment
Ugarte, M. D., Militino, A. F., & Arnholt, A. T. (2015). Probability and statistics with r. CRC Press LLC.
Created from upnasp-ebooks on 2024-03-07 22:16:18.
Chapter 3: General Probability and Random Variables 237
x x
dr dr X tx X dr
E[X r ] = r MX (t)|t=0 = r e p(x)|t=0 = r
etx p(x)|t=0
dt dt x x
dt
X X
r tx
= x e p(x)|t=0 = x p(x) = ↵r = E[X r ].
r
x x
Var[X] = E[X ] 2
E[X] = M 00 (0)
2
[M 0 (0)]2 = n(n 1)⇡ 2 + n⇡ (n⇡)2 = n⇡(1 ⇡).
Ugarte, M. D., Militino, A. F., & Arnholt, A. T. (2015). Probability and statistics with r. CRC Press LLC.
Created from upnasp-ebooks on 2024-03-07 22:16:18.
238 Probability and Statistics with R, Second Edition
3.6 Problems
1. How many ways can a host randomly choose 8 people out of 90 in the audience to
participate in a TV game show?
2. How many di↵erent six-place license plates are possible if the first two places are letters
and the remaining places are numbers?
3. How many di↵erent six-place license plates are possible (first two places letters, remaining
places numbers) if repetition among letters and numbers is not permissible?
4. Susie has 25 books she would like to arrange on her desk. Of the 25 books, 7 are statistics
books, 6 are biology books, 5 are English books, 4 are history books, and 3 are psychology
books. If Susie arranges her books by subject, how many ways can she arrange her books?
5. A hat contains 20 consecutive numbers (1 to 20). If four numbers are drawn at random,
how many ways are there for the largest number to be a 16 and the smallest number to be
a 5?
6. A university committee of size 10, consisting of 2 faculty from the college of fine and
applied arts, 2 faculty from the college of business, 3 faculty from the college of arts and
sciences, and 3 administrators, is to be selected from 6 fine and applied arts faculty, 7 college
of business faculty, 10 college of arts and sciences faculty, and 5 administrators. How many
committees are possible?
7. How many di↵erent letter arrangements can be made from the letters BIOLOGY, PROB-
ABILITY, and STATISTICS, respectively?
8. A doll house must be painted and assembled before it can be given as a gift. If there are
12 equal-sized rooms in the doll house and there is enough white paint for 4 rooms, enough
pink paint for 3 rooms, and enough blue paint for 5 rooms, in how many ways can the 12
rooms be painted?
10. A multiple-choice test consists of 10 questions. Each question has 5 answers (only one
is correct). How many di↵erent ways can a student fill out the test?
Copyright © 2015. CRC Press LLC. All rights reserved.
11. How many ways can five politicians stand in line? In how many ways can they stand
in line if two of the politicians refuse to stand next to each other?
12. There are five di↵erent colored jerseys worn throughout the Tour de France. The yellow
jersey is worn by the rider with the least accumulated time; the green jersey is worn by the
best sprinter; the red and white polka dot jersey is worn by the best climber. The white
jersey is worn by the best youngest rider, and the red jersey is worn by the rider with the
most accumulated time still in the race. If 150 riders finish the Tour, how many di↵erent
ways can the yellow, green, and red and white polka dot jerseys be awarded if (a) a rider
can receive any number of jerseys and (b) each rider can receive at most one jersey?
Ugarte, M. D., Militino, A. F., & Arnholt, A. T. (2015). Probability and statistics with r. CRC Press LLC.
Created from upnasp-ebooks on 2024-03-07 22:16:18.
Chapter 3: General Probability and Random Variables 239
13. A president, treasurer, and secretary, all di↵erent, are to be chosen from among the 10
active members of a university club. How many di↵erent choices are possible if
14. On a multiple-choice exam with three possible answers for each of the five questions,
what is the probability that a student would get four or more correct answers just by
guessing?
15. Suppose four balls are chosen at random without replacement from an urn containing
six black balls and four red balls. What is the probability of selecting two balls of each
color?
16. What is the probability that a hand of five cards chosen randomly and without replace-
ment from a standard deck of 52 cards contains the ace of hearts, exactly one other ace,
and exactly two kings?
17. In the New York State lottery game, six of the numbers 1 through 54 are chosen by a
customer. Then, in a televised drawing, six of these numbers are selected. If all six of a
customer’s numbers are selected, then that customer wins a share of the first prize. If five
or four of the numbers are selected, the customer wins a share of the second or the third
prize. What is the probability that any customer will win a share of the first prize, the
second prize, and the third prize, respectively?
18. An office supply store is selling packages of 100 CDs at a very a↵ordable price. However,
roughly 10% of all packages are defective. If a package of 100 CDs containing exactly 10
defective CDs is purchased, find the probability that exactly 2 of the first 5 CDs used are
defective.
19. A box contains six marbles, two of which are black. Three are drawn with replacement.
What is the probability two of the three are black?
20. The ASU triathlon club consists of 11 women and 7 men. What is the probability of
selecting a committee of size four with exactly three women?
Copyright © 2015. CRC Press LLC. All rights reserved.
21. Four golf balls are to be placed in six di↵erent containers. One ball is red; one, green;
one, blue; and one, yellow.
(a) In how many ways can the four golf balls be placed into six di↵erent containers? Assume
that any container can contain any number of golf balls (as long as there are a total of
four golf balls).
(b) In how many ways can the golf balls be placed if container one remains empty?
(c) In how many ways can the golf balls be placed if no two golf balls can go into the same
container?
Ugarte, M. D., Militino, A. F., & Arnholt, A. T. (2015). Probability and statistics with r. CRC Press LLC.
Created from upnasp-ebooks on 2024-03-07 22:16:18.
240 Probability and Statistics with R, Second Edition
(d) What is the probability that no two golf balls are in the same container, assuming that
the balls are randomly tossed into the containers?
22. Three dice are thrown. What fraction of the time does a sum of 9 appear on the faces?
What percent of the time does a sum of 10 appear?
23. Assume that P(A) = 0.5, P(A \ C) = 0.2, P(C) = 0.4, P(B) = 0.4, P(A \ B \ C) = 0.1,
P(B \ C) = 0.2, and P(A \ B) = 0.2. Calculate the following probabilities:
(a) P(A [ B [ C)
24. In a 10k race where three runners, Susie, Mike, and Anna, enter the race with identical
personal best times, assume they all have an equal chance of winning today’s 10k. Consider
the events:
Is W independent of E1 , E2 , and E3 ?
25. Verify that P(F |E) satisfies the three axioms of probability.
26. If A and B are independent events, show that Ac and B c are also independent events.
27. Let A and B be events where 0 < P(A) < 1 and 0 < P(B) < 1. Is P(A|B)+P(Ac |B c ) = 1
true when A and B are
(b) independent?
Copyright © 2015. CRC Press LLC. All rights reserved.
If P(A|B) + P(Ac |B c ) = 1 is not true for either (a) or (b), provide a counterexample.
28. A family has three cars, all with electric windows. Car A’s windows always work. Car
B’s windows work 30% of the time, and Car C’s windows work 75% of the time. The family
uses Car A 23 of the time; Car B, 29 of the time; and Car C, the remaining fraction.
(a) On a particularly hot day, when the family wants to roll the windows down, compute
the probability the windows will work.
(b) If the electric windows work, find the probability the family is driving Car C.
Ugarte, M. D., Militino, A. F., & Arnholt, A. T. (2015). Probability and statistics with r. CRC Press LLC.
Created from upnasp-ebooks on 2024-03-07 22:16:18.
Chapter 3: General Probability and Random Variables 241
29. A new drug test being considered by the International Olympic Committee can detect
the presence of a banned substance when it has been taken by the subject in the last 90 days
98% of the time. However, the test also registers a “false positive” in 2% of the population
that has never taken the banned substance. If 2% of the athletes in question are taking the
banned substance, what is the probability a person that has a positive drug test is actually
taking the banned substance?
30. The products of an agricultural firm are delivered by four di↵erent transportation
companies, A, B, C, and D. Company A transports 40% of the products; company B, 30%;
company C, 20%; and, finally, company D, 10%. During transportation, 5%, 4%, 2%, and
1% of the products spoil with companies A, B, C, and D, respectively. If one product is
randomly selected,
(b) If the chosen product is spoiled, derive the probability that it has been transported by
company A.
31. Two lots of large glass beads are available (A and B). Lot A has four beads, two of
which are chipped; and lot B has five beads, two of which are chipped. Two beads are
chosen at random from lot A and passed to lot B. Then, one bead is randomly selected
from lot B. Find:
(b) The probability that the two beads selected from lot A were not chipped if the bead
selected from lot B is not chipped.
32. A box contains 5 defective bulbs, 10 partially defective (they start to fail after 10 hours
of use), and 25 perfect bulbs. If a bulb is tested and it does not fail immediately, find the
probability that the bulb is perfect.
33. A salesman in a department store receives household appliances from three suppliers:
I, II, and III. From previous experience, the salesman knows that 2%, 1%, and 3% of the
appliances from suppliers I, II, and III, respectively, are defective. The salesman sells 35%
of the appliances from supplier I, 25% from supplier II, and 40% from supplier III. If an
appliance randomly selected is defective, find the probability that it comes from supplier
III.
Copyright © 2015. CRC Press LLC. All rights reserved.
34. Last year, a new business purchased 25 tablets, 25 laptops, and 50 desktops, all with
three year warranties. The probability a tablet has had warranty work is four times the
probability a desktop has had warranty work. The probability a laptop has had warranty
work is twice the probability a desktop has had warranty work. Given that 10 computers
have used the warranty,
(a) If a computer is a laptop, what is the probability it has had warranty work?
(b) If a computer has had warranty work, what is the probability it was a laptop?
(c) If a computer has had warranty work, what is the probability it was a tablet?
Ugarte, M. D., Militino, A. F., & Arnholt, A. T. (2015). Probability and statistics with r. CRC Press LLC.
Created from upnasp-ebooks on 2024-03-07 22:16:18.
242 Probability and Statistics with R, Second Edition
35. An urn contains 14 balls; 6 of them are white, and the others are black. Another urn
contains 9 balls; 3 are white, and 6 are black. A ball is drawn at random from the first urn
and is placed in the second urn. Then, a ball is drawn at random from the second urn. If
this ball is white, find the probability that the ball drawn from the first urn was black.
36. Previous to the launching of a new flavor of yogurt, a company has conducted taste
tests with four new flavors: lemon, strawberry, peach, and cherry. It obtained the following
probabilities of a successful launch: P(lemon) = 102
, P(strawberry) = 103
, P(peach) = 104
,
and P(cherry) = 10 . Let X be the random variable “number of successful flavors launched.”
5
37. John and Peter play a game with a coin such that P(head) = p. The game consists of
tossing a coin twice. John wins if the same result is obtained in the two tosses, and Peter
wins if the two results are di↵erent.
(a) At what value of p is neither of them favored by the game?
(b) If p is di↵erent from your answer in (a), who is favored?
38. A bank is going to place a security camera in the ceiling of a circular hall of radius
r. What is the probability that the camera is placed nearer the center than the outside
circumference if the camera is placed at random?
39. Let the random variable X be the sum of the numbers on two fair dice. Find an upper
bound on P(|X 7| 4) using Chebyshev’s Inequality as well as the exact probability for
P(|X 7| 4).
40. Two colleagues, Terry and Kenneth, have flights that will debark between 11:00 a.m.
and 11:30 a.m. at the same terminal. They are aware of each others’ arrival times and
would like to meet in the terminal.
(a) Find the probability Terry and Kenneth will be able to meet in the terminal if neither
colleague can a↵ord to wait more than 10 minutes for the other colleague.
(b) Plot the probability Terry and Kenneth will meet within a time t versus the time one
has to spend waiting for the other to arrive if whoever arrives first will wait up to 30
minutes.
41. Two independently wealthy philatelists, Alvin and Bob, are interested in buying rare
stamps at a private auction. For each stamp up for auction, given that the previous bid did
not win, Alvin or Bob wins on their ith bid with probability p. Assume that Alvin always
makes the first bid.
Copyright © 2015. CRC Press LLC. All rights reserved.
(a) Find the probability that Alvin wins the first auction.
(b) If two stamps are actually auctioned, find the probability that they are purchased by
the same bidder.
P1 i 1
(Hint: i=0 r = 1 r if |r| < 1.)
42. Anthony and Mark make a bet at the beginning of the school year. If Anthony passes
one exam, Mark will pay him e 10, but if Anthony fails the exam, he will give e 10 to
Mark. If Anthony takes 10 exams and the probability of passing an exam is 0.5, find the
probability that
Ugarte, M. D., Militino, A. F., & Arnholt, A. T. (2015). Probability and statistics with r. CRC Press LLC.
Created from upnasp-ebooks on 2024-03-07 22:16:18.
Chapter 3: General Probability and Random Variables 243
43. Louis and Joseph have decided to play a beach volleyball match. Each of them put e
50 into a pot, so the winner will get e 100. The first one to reach 21 points wins. When
the score was 19 points for Louis and 18 for Joseph, the match was rained out, and they
decided to share the prize so that each one received winnings proportional to the probability
of winning the match given their current points. How much money did each receive?
44. Consider tossing three fair coins. The eight possible outcomes are
Define X as the random variable “number of heads showing when three coins are tossed.”
Obtain the mean and the variance of X. Simulate tossing three fair coins 10,000 times.
Compute the simulated mean and variance of X. Are the simulated values within 2% of
the theoretical answers?
45. Every month, a family must decide what to do on Sundays. If they do not stay at
home, they do one of two things with equal probability: have lunch in a restaurant, which
costs e 100, or go to the park, which is free. Assuming four weeks in a month, compute the
probability distribution of expenditures.
46. In a lottery game, one can win e 10,000 with probability 0.01 and e 1000 with proba-
bility 0.05. How much should one pay for a lottery ticket to make the game fair?
47. Ante e 100 to play a game and win e 100 each round with a probability of 12 . Suppose
a person plays the game until he loses once. Then, he leaves the game.
(a) Find the probability that he plays more than four rounds.
(b) Find the probability that he leaves the game having won exactly e 600.
48. Consider the random variable X, which takes the values 1, 2, 3, and 4 with probabilities
0.2, 0.3, 0.1, and 0.4, respectively. Calculate E[X], 1/E[X], E[1/X], E[X 2 ], and E[X]2 ,
and check empirically that E[X]2 6= E[X 2 ] and E[1/X] 6= 1/E[X].
49. Show that the following distribution is a probability function. Construct a plot of the
probability density function and obtain the cumulative distribution function.
Copyright © 2015. CRC Press LLC. All rights reserved.
50. Find the values of k such that the following functions are probability density functions:
Ugarte, M. D., Militino, A. F., & Arnholt, A. T. (2015). Probability and statistics with r. CRC Press LLC.
Created from upnasp-ebooks on 2024-03-07 22:16:18.
244 Probability and Statistics with R, Second Edition
Construct plots of these functions and their corresponding cumulative density functions.
52. Consider an experiment where two dice are rolled. Let the random variable X equal
the sum of the two dice and the random variable Y be the di↵erence of the two dice.
53. The number of hits on a faculty member’s homework solutions page has an average of
100 hits per day.
(a) Give an upper bound for the probability the faculty member’s homework solutions page
has more than 112 hits per day.
(b) Suppose the variance of the number of hits is known to be 36. Now, give an upper bound
for the probability the faculty member’s homework solutions page has more than 112
hits per day.
(c) The probability that the number of hits is between 88 and 112 must be at least what?
(d) How many days must visits to the site be recorded so that the average number of hits
is within 6 of 100 with a probability of at least 0.9?
derive the probability density function f (x). Calculate the median of the distribution.
Ugarte, M. D., Militino, A. F., & Arnholt, A. T. (2015). Probability and statistics with r. CRC Press LLC.
Created from upnasp-ebooks on 2024-03-07 22:16:18.
Chapter 3: General Probability and Random Variables 245
(e) Calculate P(X 8), P(X 6), and P(7 X 8) using the function integrate().
56. The number of bottles of milk that a dairy farm fills per day is a random variable with
mean 5000 and standard deviation 100. Assume the farm always has a sufficient number
of glass bottles to be used to store the milk. However, for a bottle of milk to be sent to
a grocery store, it must be hermetically sealed with a metal cap that is produced on site.
Calculate the minimum number of metal caps that must be produced on a daily basis so
that all filled milk bottles can be shipped to grocery stores with a probability of at least
0.9.
57. Define X as the space occupied by certain device in a 1 m3 container. The probability
density function of X is given by
630 4
f (x) = x 1 x4 , 0 < x < 1.
56
(a) Graph the probability density function.
(b) Calculate the mean of X by hand.
59. Suppose the random variable X can take on the values 3, 5, 7, and 8 such that the
probability of each value is twice its predecessor.
Ugarte, M. D., Militino, A. F., & Arnholt, A. T. (2015). Probability and statistics with r. CRC Press LLC.
Created from upnasp-ebooks on 2024-03-07 22:16:18.
246 Probability and Statistics with R, Second Edition
61. The time, in minutes, that a car is parked in a mall has the following density function:
(
1
e x/50 x > 0
f (x) = 50
0 x 0.
Using R,
(a) Find the probability that a car stays more than 1 hour.
(b) Let Y = 0.5 + 0.03X be the cost in dollars that the mall has to pay a security service
per parked car. Find the mean parking cost for 1000 cars.
(c) Find the variance and skewness coefficient of Y .
62. A high technology company manufactures circular mirrors used in certain satellites.
The radius of any mirror in inches is a random variable R with density function
(
24
(2r r2 ) 1 r 32
f (r) = 11
0 otherwise.
To place the mirrors in the satellites without any problems, the mirror area, given by ⇡R2 ,
cannot be greater than 6.5 inches2 . Using R,
R1
(a) Verify that 1 f (r) dr = 1.
(b) Find the mean area of the mirrors.
(c) Find the probability that a mirror’s area does not surpass 6.5 inches2 .
63. The time, in hours, a child practices his musical instrument on Saturdays has pdf
(
k(1 x) for 0 x 1
f (x) =
0 otherwise.
(b) Write the cdf and find the probability the child practices more than 48 minutes on a
Saturday.
64. Consider the equilateral triangle ABC with side l. Given a randomly chosen point R in
the triangle, calculate the cumulative and the probability density functions for the distance
Copyright © 2015. CRC Press LLC. All rights reserved.
Ugarte, M. D., Militino, A. F., & Arnholt, A. T. (2015). Probability and statistics with r. CRC Press LLC.
Created from upnasp-ebooks on 2024-03-07 22:16:18.
Chapter 3: General Probability and Random Variables 247
l l
R
M N
C B
l
Copyright © 2015. CRC Press LLC. All rights reserved.
Ugarte, M. D., Militino, A. F., & Arnholt, A. T. (2015). Probability and statistics with r. CRC Press LLC.
Created from upnasp-ebooks on 2024-03-07 22:16:18.
Copyright © 2015. CRC Press LLC. All rights reserved.
Ugarte, M. D., Militino, A. F., & Arnholt, A. T. (2015). Probability and statistics with r. CRC Press LLC.
Created from upnasp-ebooks on 2024-03-07 22:16:18.