Eec 161 ch03
Eec 161 ch03
Discrete Random
Variables
Section 3.1
Definitions
Discrete Random Variables
• In this chapter and for most of the remainder of this book, we examine probability
models that assign numbers to the outcomes in the sample space.
• In our notation, the name of a random variable is always a capital letter, for example,
X.
• Since we often consider more than one random variable at a time, we denote the
range of a random variable by the letter S with a subscript that is the name of the
random variable.
The experiment is to test six integrated circuits and after each test ob-
serve whether the circuit is accepted (a) or rejected (r). Each observation
is a sequence of six letters where each letter is either a or r. For example,
s8 = aaraaa. The sample space S consists of the 64 possible sequences.
A random variable related to this experiment is N , the number of ac-
cepted circuits. For outcome s8, N = 5 circuits are accepted. The range
of N is SN = {0, 1, . . . , 6}.
Example 3.3
In Example 3.2, the net revenue R obtained for a batch of six integrated
circuits is $5 for each circuit accepted minus $7 for each circuit rejected.
(This is because for each bad circuit that goes out of the factory, it will
cost the company $7 to deal with the customer’s complaint and supply a
good replacement circuit.) When N circuits are accepted, 6 − N circuits
are rejected so that the net revenue R is related to N by the function
SX = {x1, x2, . . .} .
Quiz 3.1
A student takes two courses. In each course, the student will earn either
a B or a C. To calculate a grade point average (GPA), a B is worth 3
points and a C is worth 2 points. The student’s GPA G2 is the sum of the
points earned for each course divided by 2. Make a table of the sample
space of the experiment and the corresponding values of the GPA, G2.
Quiz 3.1 Solution
The sample space, probabilities and corresponding grades for the experi-
ment are
Outcomes BB BC CB CC
G2 3.0 2.5 2.5 2.0
Section 3.2
PX (x) = P [X = x]
Example 3.5 Problem
When the basketball player Wilt Chamberlain shot two free throws, each
shot was equally likely either to be good (g) or bad (b). Each shot that
was good was worth 1 point. What is the PMF of X, the number of
points that he scored?
Example 3.5 Solution
There are four outcomes of this experiment: gg, gb, bg, and bb. A simple
tree diagram indicates that each outcome has probability 1/4. The sample
space and probabilities of the experiment and the corresponding values
of X are given in the table:
Outcomes bb bg gb gg
P[·] 1/4 1/4 1/4 1/4
X 0 1 1 2
The random variable X has three possible values corresponding to three
events:
Each PMF display format has its uses. The function definition (3.8) is
best when PX(x) is given in terms of algebraic functions of x for various
subsets of SX . The bar plot is best for visualizing the probability masses.
The table can be a convenient compact representation when the PMF is
a long list of sample values and corresponding probabilities.
Theorem 3.1
(b) P[N = 1]
(c) P[N ≥ 2]
• In each family, the probability mass functions of all the random variables have the
same mathematical form.
• Depending on the family, the PMF formula contains one or two parameters.
• Our nomenclature for a family consists of the family name followed by one or two
parameters in parentheses.
• For example, binomial (n, p) refers in general to the family of binomial random
variables.
• Binomial (7, 0.1) refers to the binomial random variable with parameters n = 7 and
p = 0.1.
Example 3.6
Consider the following experiments:
• Flip a coin and let it land on a table. Observe whether the side facing up is heads
or tails. Let X be the number of heads observed.
• Select a student at random and find out her telephone number. Let X = 0 if the
last digit is even. Otherwise, let X = 1.
• Observe one bit transmitted by a modem that is downloading a file from the Inter-
net. Let X be the value of the bit (0 or 1).
Test one circuit and observe X, the number of rejects. What is PX(x)
the PMF of random variable X?
Example 3.7 Solution
Because there are only two outcomes in the sample space, X = 1 with
probability p and X = 0 with probability 1 − p,
1 − p x = 0,
PX (x) = p x = 1, (1)
0 otherwise.
Therefore, the number of circuits rejected in one test is a Bernoulli (p)
random variable.
Example 3.8
The events A and B are independent since the outcome of attempt l is not affected by
the previous l − 1 attempts. Note that P[A] is the binomial probability of k − 1 successes
(i.e., rejects) in l − 1 trials so that
l − 1
P [A] = pk−1 (1 − p)l−1−(k−1)
. (2)
k−1
Finally, since P[B] = p,
l − 1
PL (l) = P [A] P [B] = pk (1 − p)l−k (3)
k−1
L is an example of a Pascal random variable.
Definition 3.7 Pascal (k, p) Random Variable
0
0 20 40 l
Example 3.15
Roll a fair die. The random variable N is the number of spots on the side
facing up. Therefore, N is a discrete uniform (1, 6) random variable with
PMF
0.2
PN(n) 1/6 n = 1, 2, 3, 4, 5, 6,
0.1 PN (n) =
0 otherwise.
(1)
0
0 5 n
Definition 3.9 Poisson (α) Random Variable
Poisson models are often used to model occurrence (called arrival) of phenomenon of
interest. In these applications, we specify an average rate: λ arrivals per second and a time
interval T. In this time interval, α = λT
Example 3.17 Problem
0
0 2 4 h
The probability of no hits is
P [H = 0] = PH (0) = (0.5)0 e−0.5 /0! = 0.607. (1)
In an interval of 1 second, α = λT = (2 hits/s) × (1 s) = 2 hits. Letting J denote the
number of hits in one second, the PMF of J is
PJ(j) 0.2
2j e−2 /j!
j = 0, 1, 2, . . .
0.1 PJ (j) =
0 otherwise.
0
0 2 4 6 8 j
[Continued]
Example 3.17 Solution (Continued 2)
{J ≤ 2} = {J = 0} ∪ {J = 1} ∪ {J = 2} (1)
is the union of three mutually exclusive events. Therefore,
P [J ≤ 2] = P [J = 0] + P [J = 1] + P [J = 2]
= PJ (0) + PJ (1) + PJ (2)
= e−2 + 21e−2/1! + 22e−2/2! = 0.677. (2)
Example 3.18 Problem
The PMF of K is
0.2
PK(k)
0.1 5k e−5/k! k = 0, 1, 2, . . .
PK (k) =
0 otherwise.
0
0 5 10 15 k
Therefore, P[K = 0] = PK(0) = e−5 = 0.0067. To answer the question
about the 2-second interval, we note in the problem definition that α = 5
queries = λT with T = 10 seconds. Therefore, λ = 0.5 queries per
second. If N is the number of queries processed in a 2-second interval,
α = 2λ = 1 and N is the Poisson (1) random variable with PMF
e−1/n! n = 0, 1, 2, . . .
PN (n) = (1)
0 otherwise.
Therefore,
0
0 5 10 15 j
Quiz 3.3
Each time a modem transmits one bit, the receiving modem analyzes the
signal that arrives and decides whether the transmitted bit is 0 or 1. It
makes an error with probability p, independent of whether any other bit
is received correctly.
(a) If the transmission continues until the receiving modem makes its first
error, what is the PMF of X, the number of bits transmitted?
(b) If p = 0.1, what is the probability that X = 10? What is the probability
that X ≥ 10?
(c) If the modem transmits 100 bits, what is the PMF of Y , the number
of errors?
(d) If p = 0.01 and the modem transmits 100 bits, what is the probability
of Y = 2 errors at the receiver? What is the probability that Y ≤ 2?
(e) If the transmission continues until the receiving modem makes three
errors, what is the PMF of Z, the number of bits transmitted?
(f) If p = 0.25, what is the probability of Z = 12 bits transmitted until
the modem makes three errors?
Quiz 3.3 Solution
Decoding each transmitted bit is an independent trial where we call a bit error a “suc-
cess.” Each bit is in error, that is, the trial is a success, with probability p. Now we can
interpret each experiment in the generic context of independent trials.
(a) The random variable X is the number of trials up to and including the first success.
Similar to Example 3.9, X has the geometric PMF
p(1 − p)x−1 x = 1, 2, . . .
PX(x) =
0 otherwise.
(b) If p = 0.1, then the probability exactly 10 bits are sent is
PX (10) = (0.1)(0.9)9 = 0.0387. (1)
The probability that at least 10 bits are sent is
∞
X
P [X ≥ 10] = PX (x) . (2)
x=10
This sum is not too hard to calculate. However, its even easier to observe that
X ≥ 10 if the first 10 bits are transmitted correctly. That is,
P [X ≥ 10] = P [first 10 bits correct] = (1 − p)10 . (3)
For p = 0.1,
P [X ≥ 10] = 0.910 = 0.3487. (4)
(c) The random variable Y is the number of successes in 100 independent trials. Just
as in Example 3.11, Y has the binomial PMF
100
PY (y) = py (1 − p)100−y . (5)
y
Quiz 3.3 Solution (Continued 2)
If p = 0.01, the probability of exactly 2 errors is
100
PY (2) = (0.01)2 (0.99)98 = 0.1849. (6)
2
(d) The probability of no more than 2 errors is
P [Y ≤ 2] = PY (0) + PY (1) + PY (2)
100
100 99
= (0.99) + 100(0.01)(0.99) + (0.01)2 (0.99)98
2
= 0.9207. (7)
(e) Random variable Z is the number of trials up to and including the third success.
Thus Z has the Pascal PMF (see Example 3.13)
z − 1
PZ (z) = p3 (1 − p)z−3 . (8)
2
Note that PZ(z) > 0 for z = 3, 4, 5, . . ..
(f) If p = 0.25, the probability that the third error occurs on bit 12 is
11
PZ (12) = (0.25)3 (0.75)9 = 0.0645. (9)
2
Section 3.4
FX (x) = P [X ≤ x] .
PMF: PX(x)=P[X=x]
Theorem 3.2
For any discrete random variable X with range SX = {x1, x2, . . .} satisfying
x1 ≤ x2 ≤ . . .,
(a) Going from left to right on the x-axis, FX(x) starts at zero and ends
at one.
(d) Between jumps, the graph of the CDF of the discrete random variable
X is a horizontal line.
Theorem 3.3
For all b ≥ a,
In Example 3.9, let the probability that a circuit is rejected equal p = 1/4.
The PMF of Y , the number of tests up to and including the first reject,
is the geometric (1/4) random variable with PMF
(1/4)(3/4)y−1 y = 1, 2, . . .
PY (y ) = (1)
0 otherwise.
What is the CDF of Y ?
Example 3.22 Solution
Random variable Y has nonzero probabilities for all positive integers. For
any integer n ≥ 1, the CDF is
n n
1 3 j−1
X X
FY (n) = P Y (j ) = . (1)
j=1 j=1 4 4
The geometric (p) random variable X has expected value E[X] = 1/p.
Proof: Theorem 3.5
The Poisson (α) random variable in Definition 3.9 has expected value
E[X] = α.
Proof: Theorem 3.6
∞ ∞
X X αx −α
E [X] = xPX (x) = x e . (1)
x=0 x=0
x!
We observe that x/x! = 1/(x − 1)! and also that the x = 0 term in the sum is zero. In
addition, we substitute αx = α · αx−1 to factor α from the sum to obtain
∞
X αx−1 −α
E [X] = α e . (2)
x=1
(x − 1)!
Next we substitute l = x − 1, with the result
∞
X αl
E [X] = α e−α = α. (3)
l!
l=0
| {z }
1
We can
P∞conclude that the sum in this formula equals 1 either by referring to the identity
α l
e = l=0 α /l! or by applying Theorem 3.1(b) to the fact that the sum is the sum of
the PMF of a Poisson random variable L over all values in SL and P[SL ] = 1.
Theorem 3.7
E [X ] = np.
E [X ] = k/p.
(c) For the discrete uniform (k, l) random variable X of Definition 3.8,
E [X ] = (k + l)/2.
Quiz 3.5
(c) The probability that the subscriber receives four texts before sending
a text.
(d) The expected number of texts received by the subscriber before the
subscriber sends a text.
Quiz 3.5 Solution
(a) With probability 1/3, the subscriber sends a text and the cost is C = 10 cents.
Otherwise, with probability 2/3, the subscriber receives a text and the cost is
C = 5 cents. This corresponds to the PMF
2/3 c = 5,
PC (c) = 1/3 c = 10, (1)
0 otherwise.
(b) The expected value of C is
E [C] = (2/3)(5) + (1/3)(10) = 6.67 cents. (2)
(c) For the next two parts we think of each text as a Bernoulli trial such that the trial
is a “success” if the subscriber sends a text. The success probability is p = 1/3.
Let R denote the number of texts received before sending a text. In terms of
Bernoulli trials, R is the number of failures before the first success. R is similar to
a geometric random variable except R = 0 is possible if the first text is sent rather
than received. In general R = r if the first r trials are failures (i.e. the first r texts
are received) and trial r + 1 is a success. Thus R has PMF
(1 − p)r p r = 0, 1, 2 . . .
PR (r) = (3)
0 otherwise.
[Continued]
Quiz 3.5 Solution (Continued 2)
The probability of receiving four texts before sending a text is
PR (4) = (1 − p)4 p. (4)
(d) The expected number of texts received before sending a text is
∞
X ∞
X
E [R] = rPR (r) = r(1 − p)r p. (5)
r=0 r=0
A parcel shipping company offers a charging plan: $1.00 for the first
pound, $0.90 for the second pound, etc., down to $0.60 for the fifth
pound, with rounding up for a fraction of a pound. For all packages
between 6 and 10 pounds, the shipper will charge $5.00 per package. (It
will not accept shipments over 10 pounds.) Find a function Y = g(X)
for the charge in cents for sending one package.
Example 3.25 Solution
X=1
Y =100
.15
.15
X=2
Y =190
.15
X=3
Y =270
.15 X=4
X
H X
ZHXXX
@ Y =340
ZHH XXX
@Z H XXX
@Z HH
@Z
.10
H
X
X=5 Y =400
@ZZ HHH
.10
@ Z H
X=6XXXXX
.10
@ Z XX
@ ZZ XXX
.10@ Z X=7
X
X
Y =500
@
X=8
@@
PY (y) 0.2 1/7 y = 0,
P Y (y ) = 2/7 y = 0.5, 2, 4.5, (1)
0
0 otherwise.
0 1 2 3 4 5 y
Quiz 3.6
N =0 •M =900
0.4
N =1 •M =1050
0.2
XXX
H
HHXXX
H XXX
HH XX
H 0.2 XXX N =2 •M =1200
HH
H
0.2HHH
H N =3 •M =1350
Given a random variable X with PMF PX(x) and the derived random
variable Y = g(X), the expected value of Y is
X
E [Y ] = µY = g(x)PX (x) .
x∈SX
Proof: Theorem 3.10
In Example 3.26,
1/4 x = 1, 2, 3, 4,
PX (x) =
0 otherwise,
105X − 5X 2 1 ≤ X ≤ 5,
Y = g(X) =
500 6 ≤ X ≤ 10.
What is E[Y ]?
Example 3.29 Solution
E [X − µX ] = 0.
Proof: Theorem 3.11
E [aX + b] = a E [X ] + b.
Example 3.30 Problem
h i h i
2
Var [X ] = E X − µX = E X − (E [X ])2 .
2 2
Proof: Theorem 3.14
x2PX(x) − µ2
X X X
Var[X] = 2µX xPX(x) + X PX(x)
x∈SX x∈SX x∈SX
= E[X 2] − 2µX xPX(x) + µ2
X X
X PX(x)
x∈SX x∈SX
= E[X 2] − 2µ2
X + µ 2.
X (1)
Definition 3.17 Moments
Continuing Examples 3.5, 3.24, and 3.30, we recall that X has PMF
0.5
1/4 x = 0,
PX(x)
1/2
x = 1,
PX (x) = (1)
1/4 x = 2,
0 0
otherwise,
−1 0 1 2 3 x
and expected value E[X] = 1. What is the variance of X?
Example 3.32 Solution
In order of increasing simplicity, we present three ways to compute Var[X].
• From Definition 3.15, define
W = (X − µX )2 = (X − 1)2 . (1)
We observe that W = 0 if and only if X = 1; otherwise, if X = 0 or X = 2, then
W = 1. Thus P[W = 0] = PX(1) = 1/2 and P[W = 1] = PX(0) + PX(2) = 1/2. The
PMF of W is
1/2 w = 0, 1,
PW (w) = (2)
0 otherwise.
Then
Var [X] = E [W ] = (1/2)(0) + (1/2)(1) = 1/2. (3)
• Recall that Theorem 3.10 produces the same result without requiring the derivation
of PW(w).
Var[X] = E (X − µX )2
µ2
Y = a2 µ2 + 2abµ + b2 .
X x (2)
Because Var[Y ] = E[Y 2] − µ2
Y , Equations (3.85) and (3.86) imply that
h i h i
2
Var [Y ] = a E X − a µX = a (E X − µ2
2 2 2 2 2
X ) = a2 Var X .
[ ] (3)
Example 3.33 Problem
Note that U = 1000V . To use Theorem 3.15, we first find the variance
of V . The expected value of the amplitude is
Matlab
Matlab: Finite Random Variables
• In Matlab, we
h representi0 SX , the sample space of X, by the column
vector s = s1 · · · sn and the corresponding probabilities by the
h i0
vector p = p 1 · · · p n .∗
h i0
• The output is y = y1 · · · ym where yi = PX(xi).
• That is, for each requested xi, finitepmf returns the value PX(xi).
∗ Although
column vectors are supposed to appear as columns, we generally write a
0
column vector x in the form of a transposed row vector x1 · · · xm to save space.
Example 3.35 Problem
px= ((alpha^x)*exp(-alpha*x))/factorial(x)
This will yield the right answer as long as the argument x for the factorial function is
not too large. In Matlab version 6, factorial(171) causes an overflow. In addition,
for a > 1, calculating the ratio ax /x! for large x can cause numerical problems because
both ax and x! will be very large numbers, possibly with a small quotient. Another
shortcoming of the direct calculation is apparent if you want to calculate PX(x) for
the set of possible values x = [0, 1, . . . , n]. Calculating factorials is a lot of work for
a computer and the direct approach fails to exploit the fact that if we have already
calculated (x − 1)!, we can easily compute x! = x · (x − 1)!. [Continued]
Example 3.37 Solution (Continued 2)
A more efficient calculation makes use of the observation
ax e−a a
PX (x) = = PX (x − 1) . (1)
x! x
The poissonpmf.m function uses Equation (3.94) to calculate PX(x). Even this code is
not perfect because Matlab has limited range.
Let M equal the number of hits in one minute (60 seconds). Note that
M is a Poisson (α) random variable with α = 2 × 60 = 120 hits. The
PMF of M is
(120)me−120/m! m = 0, 1, 2, . . .
PM (m) = (1)
0 otherwise.
Rel. Freq.
Rel. Freq.
PY(y)
0 0 0
0 1 2 3 4 5 0 1 2 3 4 5 0 1 2 3 4 5
y y y
PMF PY (y) Sample Run 1 Sample Run 2
The PMF of Y and the relative frequencies found in two sample runs of
voltpower(100). Note that in each run, the relative frequencies are close
to (but not exactly equal to) the corresponding PMF.
Example 3.41 Problem
>> shipcostrv(9)’
ans =
270 190 500 270 500 190 190 100 500
Quiz 3.9
function M=samplemean(k);
K=(1:k)’;
M=zeros(k,5);
for i=1:5,
X=duniformrv(0,10,k);
M(:,i)=cumsum(X)./K;
end;
plot(K,M);
10 10
8 8
6 6
4 4
2 2
0 0
0 50 100 0 500 1000