Chapter 4: Random Variables and Probability Distributions
Introduction
In many probability experiments, the outcomes are not always directly useful until they
are represented numerically. For example, when a coin is tossed several times, we may be
interested in the number of heads obtained, rather than the exact sequence of heads and
tails.
A random variable is therefore introduced to assign numerical values to outcomes of
random experiments. This allows probability problems to be analyzed using
mathematical tools, graphs, and statistical techniques.
Random variables play an important role in: computer network reliability, machine
learning algorithms’ cryptography, communication systems and performance analysis of
computer systems
I-Random Variables
I-1 Definition: A random variable is a function that assigns a real numbe
r to each outcome in the sample space of a random experiment.
If the sample space is S, then a random variable X is defined as:
X: S → R
This means every outcome in the sample space is mapped to a real number.
Random variables are usually represented using capital letters, such as: X, Y, Z
Example 1: Tossing Two Coins
Sample space, S = {HH, HT, TH, TT}
Define random variable, X = number of heads
Outcome X
HH 2
HT 1
TH 1
Possible values of X, X ∈ {0,1,2}
TT 0
Example 2: Number of Defective Bulbs
Suppose a box contains 3 bulbs and we inspect them.
Let X = number of defective bulbs
Possible values, X = 0,1,2,3
Example 3: Sum of Two Dice
If two dice are rolled
Possible values, X ∈ {2,3,4,5,6,7,8,9,10,11,12}
X = sum of the two dice
Exercises
1. A coin is tossed three times. Define X as the number of heads.
List all possible values of X.
2. A die is rolled once. Define X as the square of the number obtained.
List possible values of X.
3. Two dice are rolled. Define X as the difference between the numbers obtained.
I.2 Types of Random Variables
Random variables are classified into two types: Discrete random variables and
continuous random variables
I.2.1 Discrete Random Variables
A discrete random variable takes finite or countably infinite values. Examples include;
Number of defective items, number of students in a class number of network failures in a
system, number of heads in coin tosses
Example 1:Two coins are tossed.
X = number of heads
Possible values; X = 0,1,2
Thus X is discrete
Example 2: A machine produces electronic chips.
Let, X = number of defective chips in a batch of 5
Possible values, X = 0,1,2,3,4,5 hence X is discrete
I.2.2 Continuous Random Variables
A continuous random variable takes any value within a given interval. Examples include:
height of students, temperature time required to process data, voltage in a circuit lifetime
of electronic components
Example 1
Let X = height of students
Possible values 150 ≤ X ≤ 200 cm hence X is continuous
Example 2
Let X = lifetime of a battery
Possible values 0 < X < ∞ hence X is continuous
Exercise: classify the following variables X given that X is;
1. the number of customers arriving in a shop in one hour.
2. the number obtained when a die is rolled
3. the number of emails received in a day
4. the weight of a laptop. Classify the variable.
5. the number of students in a classroom.
6. the temperature in a room.
I.3 Probability Mass Function (PMF)
The PMF describes probabilities for discrete random variables.
Definition
P(X=x) = p(x)
Properties
1. p(x) ≥ 0
2. ∑ p(x)=1
Example 1: Given the PMF below
x 0 1 2
P(X=x) 0.2 0.5 0.3
Check
0.2+0.5+0.3=1 hence valid PMF.
Find P(X≤1)
Solution
P(X≤1)=P(0)+P(1)=0.2+0.5=0.7
Example 2: Given the PMF below
x 1 2 3 4
P(X=x) 0.1 0.3 0.4 0.2
Find P(X>2)
Solution
P(X>2)=P(3)+P(4)=0.4+0.2=0.6
Exercise
Given
x 0 1 2 3
P(X=x) 0.1 0.2 0.4 0.3
Find: a) P(X≤2) b) P(X>1)
I.4 Probability Density Function (PDF)
A PDF describes probabilities of continuous random variables.
Definition: for a continuous random variable, X, the PDF is a function f(x) that satisfies
the conditions;
1. f(x) ≥ 0 (non-negativity). That is, the function must be zero or positive for all
values of x
2. The total area under the entire curve must be equal to 1 (representing 100%
probability)
∞
∫ f ( x ) dx =1
−∞
3. Probability as area: the probability that X falls between two values a and b is the
integral of the PDF over the range:
b
P(a ≤ X ≤ b) =∫ f ( x ) dx
a
Example 1
Given that f is a PDF f(x)=2x, 0≤x≤1, Find P(0.2≤X≤0.5)
Solution
0.5
P(0.2≤X≤0.5)= ∫ 2 xdx= x 2 ¿ ¿ 0.5
0.2= 0.25 − 0.04= 0.21
0.2
Example 2
Given that f is a PDF such that f(x)=kx, 0≤x≤3. Find k.
Solution
3
∫ kxdx=1
0
2 3
x
k[ ] =1
2 0
k(9/2) = 1
k = 2/9
Exercise
If f(x)=3x², 0≤x≤1 is a probability density function, find P(0.2≤X≤0.6)
I.5 Cumulative Distribution Function (CDF)
The CDF is defined as F(x)=P(X≤x)
Properties
1. 0 ≤ F(x) ≤ 1
2. F(x) is non-decreasing. That is F(x) cannot be decreasing as x is increasing
3. lim x →−∞ F (x)=0
4. lim x → ∞ F (x)=1
Example: given the PMF on the table below
x 1 2 3
P(X=x) 0.2 0.5 0.3
The CDF table is as follows
x F(x)
1 0.2
2 0.7
3 1
Exercise: Construct the CDF for;
x 0 1 2
P(X=x) 0.3 0.4 0.3
I.6 Expectation (Mean)
The expectation represents the average value of a random variable in the long run.
For discrete variables the expectation or mean is calculated as;
E(X)=∑ xP(x)
Example : find the mean of the PMF below
x 0 1 2
P(X=x) 0.2 0.5 0.3
Solution
E(X)=∑ xP(x)
E(X)=0(0.2)+1(0.5)+2(0.3) = 0+0.5+0.6 = 1.1
Exercise: Compute the mean for
x 1 2 3
P(X=x) 0.3 0.4 0.3
I.7 Variance
Variance measures spread of values around the mean and is calculated as
Var(X)=E(X²) −[E(X)] ²
Example: find the mean of the PMF below
x 0 1 2
P(X=x) 0.2 0.5 0.3
solution
First E(X)=1.1 (from the previous example)
E(X²)=0²(0.2)+1²(0.5)+2²(0.3)=0+0.5+1.2=1.7
Var(X)=E(X²) −[E(X)] ²=1.7−(1.1)²=0.49
I.8 Properties of Expectation
1. expectation of a constant is a constant. That is, E(c)=c
2. E(cX)=cE(X) where c is a constant
3. summation: E(X+Y)=E(X)+E(Y)
4. E(aX+b)=aE(X)+b where a and b are constants
Example
If E(X)=5. Find E(4X+3)
Solution
E(4X+3)=4E(X)+3=4(5)+3=23
Tutorial questions
1. A random variable has distribution
x 0 1 2 3
P(X=x) 0.1 0.2 0.4 0.3
Find a) E(X) b) Var(X)
2. The PDF is f(x)=kx, 0≤x≤4
Find a) k b) P(2≤X≤4)
3. The number of network failures per day has PMF
x 0 1 2 3
P(X=x) 0.4 0.3 0.2 0.1
Find a) E(X) b) Var(X)
4. Explain the difference between a) PMF b) PDF c) CDF
5. Let X represent the lifetime of a component with
f(x)=2 e−2 x , x>0 Find P(X>1)
6.A random variable takes values 1,2,3,4 with probabilities 0.2, 0.3, 0.1 and k.
a) Find k. b) Find P(X > 2). c) Find P(1 ≤ X ≤ 3).
7. A discrete random variable X has probability mass function defined by
{
k (x−1)
, forx=2, 3 , 4 ,5 , 6 , 7
f ( x )= 6
13−x
, for x=8 , 9 ,10 , 11, 12
36
Calculate
a) The value of the constant k
b) E(X) and Var(X)
c) P(6 ≤ X ≤ 9)
Another random variable Y is connected to X by the relationship
Y = (5X + 3). Calculate d) E(X + Y) e) Var(X + Y) (HND 2024)
II-Joint Distributions and Their Properties
II.1 Definition: When two or more random variables are considered simultaneously,
their probabilities are described by a joint probability distribution.
Let X and Y be two random variables. The joint probability distribution gives the
probability that both variables take specific values at the same time. For discrete random
variables P(X = x, Y = y) and for continuous random variables f(x, y)
II.2 Joint Probability Mass Function (Joint PMF)
For discrete variables, the joint PMF is defined as p(x, y) = P(X = x, Y = y) with
properties;
1.p(x, y) ≥ 0
2.Σ Σ p(x, y) = 1
Example
Suppose the joint distribution of X and Y is given as follows:
X\Y 0 1
0 0.10 0.20
1 0.30 0.40
Check whether this is a valid joint probability distribution and find
a) P(X = 1, Y = 0) b) P(X + Y = 1)
Solution
0.10 + 0.20 + 0.30 + 0.40 = 1. Therefore, the distribution is valid.
a) From the table P(X = 1, Y = 0) = 0.30
b) Possible combinations
X Y
0 1
1 0
P(X + Y = 1) = P(X = 0, Y = 1) + P(X = 1, Y = 0) = 0.20 + 0.30 = 0.50
Exercises
1. Consider the distribution
X\Y 1 2
1 0.2 0.3
2 0.1 0.4
Find
a) P(X = 2, Y = 2) b) P(X = 1, Y = 2) c) P(X + Y = 3)
2. Given
X\Y 0 1
0 0.15 0.35
1 0.25 0.25
Find a) P(X = 0 , Y = 1) b) P(X = 1 , Y = 0) c) P(X + Y = 1)
II.3 Marginal Distributions
The marginal distribution of a random variable is obtained by summing the joint
probabilities across rows or columns.
For discrete variables
The marginal distribution of X is P( X=x)=∑ P(X =x , Y = y)
y
And the marginal distribution of Y is P(Y = y)=∑ P(X =x , Y = y)
x
Example 1 Given the joint distribution below find write down the marginal distributions
X\Y 0 1
0 0.10 0.20
1 0.30 0.40
Solution
Marginal distribution of X
X Calculation P(X)
0 0.10 + 0.20 0.30
1 0.30 + 0.40 0.70
Marginal distribution of Y
Y Calculation P(Y)
0 0.10 + 0.30 0.40
1 0.20 + 0.40 0.60
Example 2 Find marginal distributions for the joint distributions below
X\Y 1 2
1 0.2 0.3
2 0.1 0.4
Solution
Marginal of X
X P(X)
1 0.5
2 0.5
Marginal of Y
Y P(Y)
1 0.3
2 0.7
Exercises
1. Find marginal distributions of X and Y
X\Y 0 1 2
0 0.1 0.1 0.1
1 0.2 0.2 0.3
2. Given
X\Y 1 2 3
1 0.1 0.2 0.1
2 0.1 0.3 0.2
Find a) P(X = 1) b) P(X = 2) c) P(Y = 3)
II.4 Conditional Distributions
Conditional probability for joint distributions is defined as
P(X = x | Y = y) = P(X = x, Y = y) / P(Y = y)
Similarly
P(Y = y | X = x) = P(X = x, Y = y) / P(X = x)
Example: given the joint distribution below, find
a) P(X = 1 | Y = 1) b) Find P(Y = 0 | X = 1)
X\Y 0 1
0 0.1 0.2
1 0.3 0.4
Solution
a) P(Y = 1) = 0.2 + 0.4 = 0.6
P(X = 1 | Y = 1) == P(X = 1, Y = 1) / P(Y = 1)= 0.4 / 0.6 = 0.667
b) P(X = 1) = 0.3 + 0.4 = 0.7
P(Y = 0 | X = 1) = P(X = 1, Y = 0) / P(X = 1)= 0.3 / 0.7 = 0.429
Exercises
1. Using
X\Y 0 1
0 0.2 0.3
1 0.1 0.4
Find a) P(X = 0 | Y = 1) b) P(Y = 0 | X = 1)
II.5 Independence of Random Variables
Two random variables X and Y are independent if
P(X = x, Y = y) = P(X = x) P(Y = y)
Example 1 consider the joint distribution below
X\Y 0 1
0 0.1 0.2
1 0.3 0.4
Compute
P(X = 0) = 0.3
P(Y = 0) = 0.4
P(X = 0) P(Y = 0) = 0.12
But P(X = 0, Y = 0) = 0.10
Since they are not equal, the variables are not independent.
Example 2 consider the joint distribution below
X\Y 0 1
0 0.25 0.25
1 0.25 0.25
Marginals
P(X = 0) = 0.5
P(Y = 0) = 0.5
P(X = 0) P(Y = 0) = 0.25
And P(X = 0, Y = 0) = 0.25
Therefore X and Y are independent.
Tutorial Questions
1. The joint distribution of X and Y is
X\Y 0 1 2
0 0.1 0.1 0.1
1 0.2 0.2 0.3
Find a) marginal distribution of X b) marginal distribution of Y c) P(X = 1 | Y = 2)
d) Determine whether X and Y are independent.
2. A joint PMF is as follows
X\Y 1 2
1 0.3 0.2
2 0.1 0.4
Find a) P(X = 1) b) P(Y = 2) c) P(X = 1 | Y = 2)
3. Suppose f (x , y )=kxy for 0 ≤ x ≤ 1, 0 ≤ y ≤ 1
Find a) k b) P(X < 0.5, Y < 0.5)
4. A computer network records the number of failures X and repairs Y
X\Y 0 1 2
0 0.1 0.2 0.1
1 0.2 0.1 0.3
Find a) P(X = 1, Y = 2) b) marginal distribution of X c) P(Y = 2 | X = 1)