2
2
formally dene a random variable and distinguish it from the values which it takes
2.3 Introduction
A random variable is a mapping of the elementary outcomes in the sample space to
real numbers. This allows us to attach probabilities to the experimental outcomes.
Hence the concept of a random variable is that of a measurement which takes a
particular value for each possible trial (experiment). Frequently, this will be a numerical
value.
Example 2.1 Suppose we sample ve people and measure their heights, hence
height is the random variable and the ve (observed) values of this random variable
are the realised measurements for the heights of these ve people.
Example 2.2 Suppose a fair die is thrown four times and we observe two 6s, a 3
and a 1. The random variable is the score on the die, and for these four trials it
takes the values 6, 6, 3 and 1. (In this case, since we do not know the true order in
which the values occurred, we could also say that the results were 1, 6, 3 and 6, or 1,
3, 6 and 6, or .)
37
2. Discrete probability distributions
Discrete: Synonymous with count data, that is, as far as this course is
concerned, random variables which take non-negative integer values, such as
0, 1, 2, . For example, the number of heads in n coin tosses.
38
2.4. Probability distribution
Example 2.4 Let X = the score of a fair die. If the die results in a 3, then this is
written as x = 3.
The probability distribution of X is:
X=x 1 2 3 4 5 6
P (X = x) 1/6 1/6 1/6 1/6 1/6 1/6
2
When dealing with continuous random variables the analogous condition is integrating, rather than
summing, to 1. More of this in Chapter 3.
3
At school, uniforms are worn, i.e. all pupils wear the same clothes (possibly slight dierences across
genders), hence when the term uniform is applied to a probability distribution, we have the same
probability of occurrence for each sample space value.
39
2. Discrete probability distributions
1.0
0.8
0.6
Probability
0.4
0.2
0.0
1 2 3 4 5 6
Score
Figure 2.1: Probability distribution for the score on a fair die in Example 2.4.
Example 2.5 Let X = the number of heads when ve fair coins are tossed. The
probability distribution of X is:
X=x 0 1 2 3 4 5
P (X = x) 0.03 0.16 0.31 0.31 0.16 0.03
= (05)5 = 5 × (05)5 = 10 × (05)5 = 10 × (05)5 = 5 × (05)5 = (05)5
40
2.5. Binomial distribution
1.0
0.8
0.6
Probability
0.4
0.2
0.0
0 1 2 3 4 5
Number of heads
Figure 2.2: Probability distribution for the number of heads when ve fair coins are
tossed.
A Bernoulli trial has only two possible outcomes (i.e. it is dichotomous) which are
typically called success and failure – such as heads and tails. We usually code
a success as 1 and a failure as 0.
Bernoulli distribution
41
2. Discrete probability distributions
Example 2.6 Other potential examples of Bernoulli trials are: (i.) the sex of
new-born babies (male or female), (ii.) the classication of factory output (defective
or not defective), and (iii.) voters supporting a candidate (support or not support).
In fact, many sampling situations become Bernoulli trials if we are only interested in
classifying the result categorically in one of two ways – for example, heights of people if
we are only interested in whether or not each person is taller than 180 cm, say.
Extending this idea, if we have n successive Bernoulli trials, then we dene the binomial
distribution.
Binomial distribution
X ∼ Bin(n, π)
where the terms n and π are called parameters, since the values of these dene
which specic binomial distribution we have. Its probability function is:
{
n
x
π x (1 − π)n−x for x = 0, 1, 2, , n
P (X = x) = (2.1)
0 otherwise.
n is the number of Bernoulli trials, π is the (constant) probability of success for each
trial, P (X = x) is the probability that the number of successes in the n trials is equal
to x. That is, we are seeking to count the number of successes, and each P (X = x)
is the probability that the discrete (count) random variable X takes the value x.
(2.1) can be used to calculate probabilities for any binomial distribution, provided n
and π are both specied. Note that a binomial random variable can take n + 1 dierent
values, not n, since the variable measures the number of successes. The smallest number
of successes in n trials is zero (i.e. if all trials resulted in failure); the largest number of
successes is n (i.e. if all trials resulted in success); with the intervening number of
successes being 1, 2, , n − 1. Therefore, there are n + 1 dierent values in total.
Each trial has only two possible outcomes – success and failure.
4
Read ∼ as is distributed as.
42
2.6. Cumulative distribution functions
For discrete random variables taking non-negative integer values, the cumulative
distribution function (cdf) is:5
F (x) = P (X = 0) + P (X = 1) + P (X = 2) + · · · + P (X = x)
= p(0) + p(1) + p(2) + · · · + p(x)
It follows that we can easily nd the probability function from the cumulative
distribution function, or vice versa, using this relationship. Specically, note that:
P (X = x) = F (x) − F (x − 1)
Example 2.7 Consider ten test tubes of bacterial solution and let us suppose that
the probability of any single test tube showing bacterial growth is 0.2. Let X denote
the number of test tubes showing bacterial growth. Hence:
10
P (exactly 4 show growth) = P (X = 4) = × (02)4 × (08)6
4
and:
Note this technique also illustrates the advantage of computing the probability of an
event by calculating the probability of it not happening and subtracting this from 1.6
5
Note you can use either form of notation p(x) or P (X = x), whichever you prefer.
6
Recall P (A) = 1 − P (Ac ).
43
2. Discrete probability distributions
F (x) = P (X ≤ x)
Example 2.8 If X ∼ Bin(2, π), then each time x reaches an integer value in the
range [0, 2], the cdf jumps by P (X = x), until the sum of the P (X = x)s reaches 1.
This is shown in Figure 2.3.
F(x)
1
2
2π (1-π ) + (1-π )
2
(1-π )
0 1 2
x
Figure 2.3: Step function showing the cdf of X ∼ Bin(2, π) in Example 2.8.
The same pattern shown in Figure 2.3 applies to any version of Bin(n, π), or indeed to
any other distribution for which there is a largest possible integer value. For
distributions like the Poisson (discussed next) which count, but which do not have a
largest possible value, the pattern is similar, but the value 1 is never reached.
7
Technically speaking for n = 1, if π = 0 or 1 then P (X = π) = 1, but this means a success is
impossible or certain, respectively. Hence we no longer have two possible outcomes, but one certain
outcome, i.e. a failure or success, respectively.
8
Note that the argument x is not the same as the random variable X, nor is it the same as a realisation
or value of X. This is because X is not continuous, but takes only (selected) integer values. The x value
simply tells us the range of values in which we are interested.
44
2.7. Poisson distribution
In this situation the random variable X is the number of points in a particular unit of
the medium.
where λ is the average number of points per unit of the medium, and is known as
the rate parameter. Note that, unlike the binomial distribution, there is no upper
bound on the value of x.
Example 2.9 Examples of a Poisson process include (i) machine breakdowns per
unit of time, (ii) arrivals at an airport per unit of time, and (iii) aws along a rope
per unit of length.
Example 2.10 Consider a machine which breaks down, on average, 3.2 times per
week, hence λ = 32 per week. The probability that it will break down exactly once
next week is:
e−32 (32)1
P (X = 1) = = 01304
1!
The probability that it will break down exactly four times in the next two weeks
(hence λ is now 6.4) is:
e−64 (64)4
P (X = 4) = = 01162
4!
Note that if we know λ for one unit of time (here, per week) and we want to look at
k units of time (in this example, k = 2), then we need to proportionally change λ to
reect this, i.e. the revised rate parameter is k × λ (hence in this example the revised
λ for a two-week period is 2 × 32 = 64).
45
2. Discrete probability distributions
Example 2.11 Suppose we sample 100 items at random from a production line
which is providing, on average, 2% defective items. What is the probability of
exactly 3 defective items in our random sample?
First, we have to check that the relevant criteria for using the Poisson approximation
are satised. Indeed they are. n = 100 > 30, π = 002 is suciently small such that
nπ = 2 < 10 and x = 3 is small relative to n. Hence:
e−2 23
P (X = 3) = 100 C3 × (002)3 × (098)97 = 01823 ≈ = 01804
3!
true binomial probability
46
2.9. Expected value of a discrete random variable
It would be foolish to simply take the arithmetic average of all the values taken by the
random variable, as this would mean that very unlikely values (those with small
probabilities of occurrence) would receive the same weighting as very likely values
(those with large probabilities of occurrence). The obvious approach is to use the
probability-weighted average of the sample space values, known as the expected
value of X.
Note that the expected value is also referred to as the population mean, which can be
written as E(X) (in words the expectation of the random variable X), or µ (in words
the (population) mean of X). Also, note the distinction between the sample mean, x̄,
(introduced in ST104a Statistics 1) based on observed sample values, and the
population mean, µ, based on the theoretical probability distribution.
Why this reduces to nπ is beyond the scope of this course, but the fact that
E(X) = nπ for the binomial distribution is a useful result!
Again, why this reduces to λ is beyond the scope of this course, but again is a useful
result.
47
2. Discrete probability distributions
Above we have labelled the population mean as the expectation of the random
variable and introduced
the expectation operator, E(·). This operator, like the
summation operator , is a linear operator and hence this property can be used to nd
the expectation of a new random variable, be it a transformation of a single random
variable or a linear combination of two (or more) random variables.
Given random variables X and Y , and constants α and β (both non-zero), dene
T = αX ± βY . It follows that:
48
2.10. Variance of a discrete random variable
N
∑
E(ln(X)) = ln(xi ) pi for all xi > 0
i=1
N
∑
2
E(X ) = x2i pi
i=1
One very important average associated with a distribution is the expected value of the
square of the deviation11 of the random variable from its mean, µ. This can be seen to
be a measure – not the only one, but the most widely used by far – of the dispersion of
the distribution and is known as the (population) variance of the random variable.
The (positive) square root of the variance is known as the standard deviation and,
given the variance is typically denoted by σ 2 , is denoted by σ.
Example 2.18 Let X represent the value shown when a fair die is thrown once.
We now compute the mean and variance of X as follows.
X=x 1 2 3 4 5 6 Total
49
2. Discrete probability distributions
It helps to have (and to calculate) the Total column since, for example, if a
probability, P (X = x), has been miscalculated or miscopied then the row total
will not be 1 (recall axiom 2). Therefore, this would highlight an error so, with a
little work, could be identied.
In words, the (population) variance is equal to the mean of the square minus the square
of the mean. Rearranging gives:
E(X 2 ) = σ 2 + µ2
This representation is useful since we often want to know E(X 2 ), but start by knowing
the usual details of a distribution, i.e. µ and σ 2 .
X=x 1 2 3 4 5 6 Total
Hence µ = E(X) = 35, E(X 2 ) = 916, so the variance is 916 − (35)2 = 292, as
before. However, this method is usually easier.
50
2.11. Distributions related to the binomial distribution
If X ∼ Pois(λ), then:
Var(X) = λ
Note that for the Poisson distribution the mean and variance are equal.
As in the case of the expected value, we might want to look at linear combinations of
random variables.
Given random variables X and Y and non-zero constants α and β, by dening two
new random variables U = αX and T = αX ± βY , then:12
12
One way to remember this is to think of Var as a homogeneous function of degree 2, like the
Cobb–Douglas utility and production functions which crop up in economics.
13
We have already met independent events, but we do not yet know what it means for random variables
to be independent. This will be covered later.
51
2. Discrete probability distributions
If: {
(1 − π)x−1 π for x = 1, 2,
P (X = x) =
0 otherwise
then X has a geometric distribution, denoted X ∼ Geo(π). It can be shown that
for the geometric distribution E(X) = 1π and Var(X) = (1 − π)π 2 .
x−1
P (X = x) = Cr−1 π r−1 (1 − π)x−r π
P (r−1 Ss & x−r F s)
If: {
x−1
r−1
π r (1 − π)x−r for x = r, r + 1, r + 2,
P (X = x) =
0 otherwise
then X has a negative binomial distribution, denoted X ∼ Neg. Bin(r, π). It
can be shown that for the negative binomial distribution E(X) = rπ and
Var(X) = r(1 − π)π 2 .
52
2.12. Overview of chapter
53
2. Discrete probability distributions
2. Suppose that a particle starts at the origin of the real line and moves along the line
in jumps of one unit. For each jump, the probability is π (where 0 ≤ π ≤ 1) that
the particle will jump one unit to the left, and hence the probability is 1 − π that
the particle will jump one unit to the right. Find the expected value of the position
of the particle after n jumps.
2. Let Xi = 1 if the ith jump of the particle is one unit to the right, and let Xi = −1
if the ith jump is one unit to the left. Therefore, for i = 1, 2, , n, we have:
E(Xi ) = −1 × π + 1 × (1 − π) = 1 − 2π
3. We have that:
e−λ λ0 1
P (X = 0) = = e−λ = ⇒ λ ≈ 110
0! 3
Therefore:
e−110 (110)1 1
P (X ≥ 2) = 1 − P (X ≤ 1) = 1 − − = 03010
1! 3
54