Week4 PDF
Week4 PDF
CVEN2002/2702
Week 4
This lecture
4. Random variables
4.1 Introduction
4.2 Random variables
4.3 Discrete Random Variables
4.4 Continuous Random Variables
4.5 Expectation of a random variable
4.6 Variance of a random variable
4.7 Jointly distributed Random Variables
CVEN2002/2702 (Statistics)
Dr Justin Wishart
2 / 50
4. Random variables
4. Random variables
CVEN2002/2702 (Statistics)
Dr Justin Wishart
3 / 50
4. Random variables
4.1 Introduction
Introduction
Often, we are not interested in all of the details of an experiment but
only in the value of some numerical quantity determined by the
outcome
Dr Justin Wishart
4 / 50
4. Random variables
SX = {2, 3, 4, . . . , 12}
SX = {0, 1, 2}
CVEN2002/2702 (Statistics)
Dr Justin Wishart
5 / 50
4. Random variables
(X x) = { S : X () x}
they are events !
Dr Justin Wishart
6 / 50
4. Random variables
Notes
Note 1
It is important not to confuse:
X , the name of the random variable
X (), the numerical value taken by the random variable at some
sample point
x, a generic numerical value
Note 2
Most interesting problems can be stated, often naturally, in terms of
random variables
many inessential details about the sample space can be left
unspecified, and one can still solve the problem
often more helpful to think of random variables simply as variables
whose values are likely to lie within certain ranges of the real
number line
CVEN2002/2702 (Statistics)
Dr Justin Wishart
7 / 50
4. Random variables
Definition
The cdf of the random variable X is defined for any real number x, by
F (x) = P(X x)
All probability questions about X can be answered in terms of its
distribution. We will denote X F (read X follows the distribution F )
Some properties:
for any a b, P(a < X b) = F (b) F (a)
F is a nondecreasing function
limx+ F (x) = F (+) = 1
limx F (x) = F () = 0
CVEN2002/2702 (Statistics)
Dr Justin Wishart
8 / 50
4. Random variables
0.8
0.8
0.8
1.0
1.0
1.0
0.6
FX(x)
0.6
0.4
FX(x)
x
Continuous distribution
continuous r.v.
0.2
0.0
0.2
0.0
0.4
0.2
0.0
0.4
FX(x)
0.6
Discrete distribution
discrete r.v.
Hybrid distribution
hybrid r.v.
CVEN2002/2702 (Statistics)
Dr Justin Wishart
9 / 50
4. Random variables
Definition
The probability mass function (pmf) of a discrete random variable X is
defined for any real number x, by
p(x) = P(X = x)
pX (x) > 0 for x = x1 , x2 , . . ., and pX (x) = 0 for any other value of x
Obviously:
P(X SX ) = P((X = x1 ) (X = x2 ) . . .) =
CVEN2002/2702 (Statistics)
Dr Justin Wishart
p(x) = 1
xSX
Session 2, 2012 - Week 4
10 / 50
4. Random variables
0.8
1.0
pX(x)
0.6
0.4
spikes at x1 , x2 , . . .
0.2
0.0
1.0
0.8
FX(x)
0.6
0.4
step function
0.2
0.0
jumps at x1 , x2 , . . .
magnitude of jump at xi = p(xi )
CVEN2002/2702 (Statistics)
x
Dr Justin Wishart
11 / 50
4. Random variables
1.0
0.20
pmf
0.15
0.8
F(x)
0.10
0.2
0.05
0.4
p(x)
0.6
0.0
0.00
CVEN2002/2702 (Statistics)
8
x
10
12
14
Dr Justin Wishart
8
x
10
12
14
12 / 50
4. Random variables
CVEN2002/2702 (Statistics)
Dr Justin Wishart
13 / 50
4. Random variables
0.8
0.8
0.8
1.0
1.0
1.0
0.6
FX(x)
0.6
0.4
FX(x)
x
Continuous distribution
continuous r.v.
CVEN2002/2702 (Statistics)
0.2
0.0
0.2
0.0
0.4
0.2
0.0
0.4
FX(x)
0.6
Discrete distribution
discrete r.v.
Dr Justin Wishart
Hybrid distribution
hybrid r.v.
14 / 50
4. Random variables
Definition
A random variable X is said to be continuous if there exists a
nonnegative function f (x) defined for all real x R such that for any
set B of real numbers,
#
P(X B) =
f (x)dx
B
Dr Justin Wishart
15 / 50
4. Random variables
Dr Justin Wishart
16 / 50
4. Random variables
f (y )dy , that is
f (x) =
dF (x)
dx
= F (x)
(wherever F is differentiable)
f (x) 0
x R
(F (x) is nondecreasing)
# b
P(a X b) =
f (x)dx = F (b) F (a)
a
f (x)dx = 1
x+/2
x/2
f (y )dy f (x)
SX = {x R : f (x) > 0}
Note: as P(X = x) = 0, P(X < x) = P(X x) (for a continuous r.v.)
CVEN2002/2702 (Statistics)
Dr Justin Wishart
17 / 50
4. Random variables
Example
Let X denote the current measured in a thin copper wire (in mA). Assume
$
that the pdf of X is
C(4x 2x 2 ) if 0 < x < 2
f (x) =
0
otherwise
What is the value of C ? Find P(X > 1.8)
%2
% +
We must have f (x) dx = 1, so C 0 (4x 2x 2 ) dx = C 83 = 1, that is
C = 3/8
% +
%2
Then, P(X > 1.8) = 1.8 f (x) dx = 3/8 1.8 (4x 2x 2 ) dx = 0.028
CVEN2002/2702 (Statistics)
Dr Justin Wishart
18 / 50
4. Random variables
CVEN2002/2702 (Statistics)
Dr Justin Wishart
19 / 50
4. Random variables
Continuous r.v.
Domain of variation
SX = {x1 , x2 , . . .}
SX = [, ] R
useless: p(x) 0
Note the similarity between the conditions for pmf and pdf
CVEN2002/2702 (Statistics)
Dr Justin Wishart
20 / 50
4. Random variables
Parameters of a distribution
Fact
Some quantities characterise a random variable more usefully
(although incompletely) than the whole cumulative distribution function
The focus is on certain general properties of the distribution of the
r.v.
The two most important such quantities are:
the expectation (or mean) and
the variance
of a random variable
Often, we talk about the expectation or the variance of a distribution,
understood as the expectation or the variance of a random variable
having that distribution
CVEN2002/2702 (Statistics)
Dr Justin Wishart
21 / 50
4. Random variables
Expectation
The expectation or the mean of a random variable X , denoted E(X )
or , is defined by
Discrete r.v.
= E(X ) =
Continuous r.v.
!
x p(x)
= E(X ) =
xSX
x f (x)dx
SX
CVEN2002/2702 (Statistics)
Dr Justin Wishart
22 / 50
4. Random variables
Expectation
Expectation = expected value, mean value, average value of X
= central value, around which X is distributed
= centre of gravity of the distribution
In the discrete case:
localisation parameter
CVEN2002/2702 (Statistics)
Dr Justin Wishart
23 / 50
4. Random variables
Expectation: examples
Example 1
What is the expectation of the outcome when a fair die is rolled?
X = outcome, SX = {1, 2, 3, 4, 5, 6} with p(x) = 1/6 for any x SX
CVEN2002/2702 (Statistics)
Dr Justin Wishart
24 / 50
4. Random variables
Example 2
What is the expected sum when two fair dice are rolled?
X = sum of the two dice,
SX = {2, 3, . . . , 12} with
p(x) = (6 |7 x|)/36 for any x SX
= E(X ) = 2 1/36 + 3 2/36 + . . . + 12 1/36 = 7
CVEN2002/2702 (Statistics)
Dr Justin Wishart
25 / 50
4. Random variables
Expectation: examples
Example 4
Find the mean value of the copper current measurement X for Example on
Slide 18, that is, with
$ 3
2
8 (4x 2x ) if 0 < x < 2
f (x) =
0
otherwise
The density is
0.4
# 2
3
=
8
=1
0.0
0.2
f(x)
0.6
0.0
0.5
1.0
1.5
2.0
x (4x 2x 2 ) dx
CVEN2002/2702 (Statistics)
Dr Justin Wishart
26 / 50
4. Random variables
If X is a discrete r.v.
E(g(X )) =
If X is a continuous r.v.
g(x) p(x)
E(g(X )) =
xSX
g(x) f (x) dx
SX
Linear transformation
E(aX + b) = aE(X ) + b
Proof: . . .
With a = 0 E(b) = b
CVEN2002/2702 (Statistics)
27 / 50
4. Random variables
If X is a discrete r.v.
2 = Var(X ) =
xSX
If X is a continuous r.v.
(x )2 p(x)
2 = Var(X ) =
(x)2 f (x)dx
SX
Dr Justin Wishart
28 / 50
4. Random variables
Variance: illustration
Two random variables X1 and X2 , with E(X1 ) = E(X2 )
0.6
0.8
1.0
pdf of X2
variability of X2
fX(x)
fX(x)
0.6
0.8
1.0
pdf of X1
0.4
0.2
0.2
0.4
variability of X1
E(X2) = 0
0.0
0.0
E(X1) = 0
1
Dr Justin Wishart
29 / 50
4. Random variables
Variance: notes
Note 1
An alternative formula for Var(X ) is the following:
2 = Var(X ) = E(X 2 ) (E(X ))2 = E(X 2 ) 2
Proof: . . .
in practice, this is often the easiest way to compute Var(X ), using
#
!
2
2
2
E(X ) =
x p(x) or E(X ) =
x 2 f (x)dx
SX
xSX
Note 2
The variance 2 is not in the same units as X , which may make
interpretation difficult
often, we adjust for this by taking the square root of 2
(
This is called the standard deviation of X : = 2 = Var(X )
CVEN2002/2702 (Statistics)
Dr Justin Wishart
30 / 50
4. Random variables
Linear transformation
Var(aX + b) = a2 Var(X )
Proof: . . .
Take a = 1, it follows that for any b, Var(X + b) = Var(X )
variance not affected by translation
Take a = 0, if follows that for any b, Var(b) = 0
(degenerate random variable)
CVEN2002/2702 (Statistics)
Dr Justin Wishart
31 / 50
4. Random variables
Variance : examples
Example 1
What is the variance of the number of points shown when a fair die is rolled?
X = outcome, SX = {1, 2, 3, 4, 5, 6} with p(x) = 1/6 for any x SX
Example 2
What is the variance of the sum of the points when 2 fair dice are rolled ?
(Exercise) Check that 2 5.83, 2.41
CVEN2002/2702 (Statistics)
Dr Justin Wishart
32 / 50
4. Random variables
Variance: examples
Example 3
What is the variance of a Bernoulli r.v.?
E(X 2 ) = 02 (1 ) + 12 = = E(X )
Example 4
What is the variance of the copper current measurement X for Example on
Slide 18, that is, with
$ 3
2
8 (4x 2x ) if 0 < x < 2
f (x) =
0
otherwise
We have E(X 2 ) =
% +
x 2 f (x) dx =
3
8
%2
0
x 2 (4x 2x 2 ) dx = 1.2
Dr Justin Wishart
33 / 50
4. Random variables
Standardisation
Standardisation is a very useful linear transformation
Suppose you have a random variable X with mean and variance 2 .
Then, the associated standardised random variable, often denoted Z ,
is given by
X
Z =
,
E(X ) = = 0
2
1
Var(X
)
=
=1
2
2
a standardised random variable has always mean 0 and variance 1
Var(Z ) =
Dr Justin Wishart
34 / 50
4. Random variables
Definition
The joint cumulative distribution function of X and Y is given by
FXY (x, y ) = P(X x, Y y )
(x, y ) R R
Dr Justin Wishart
35 / 50
4. Random variables
y SY
CVEN2002/2702 (Statistics)
Dr Justin Wishart
36 / 50
4. Random variables
Thus,
fX (x) =
and fY (y ) =
SY
CVEN2002/2702 (Statistics)
Dr Justin Wishart
37 / 50
4. Random variables
E(g(X , Y )) =
discrete case
x SX y SY
CVEN2002/2702 (Statistics)
SX
continuous case
SY
Dr Justin Wishart
38 / 50
4. Random variables
SY
= aE(X ) + bE(Y )
Example
What is the expected sum obtained when two fair dice are rolled?
Let X be the sum and Xi the value shown on the ith die. Then, X = X1 + X2 ,
and
E(X ) = E(X1 ) + E(X2 ) = 2 3.5 = 7
CVEN2002/2702 (Statistics)
Dr Justin Wishart
39 / 50
4. Random variables
which reduces to
or
Dr Justin Wishart
40 / 50
4. Random variables
E(h(X )g(Y )) =
##
SX
SX
SY
= E(h(X )) E(g(Y ))
CVEN2002/2702 (Statistics)
Dr Justin Wishart
41 / 50
4. Random variables
Dr Justin Wishart
42 / 50
4. Random variables
Covariance: interpretation
Suppose X and Y are two Bernoulli random variables
Then, XY is also a Bernoulli random variable which takes the value 1 if
and only if X = 1 and Y = 1. It follows:
Cov(X , Y ) = E(XY )E(X )E(Y ) = P(X = 1, Y = 1)P(X = 1)P(Y = 1)
Then,
Cov(X , Y ) > 0 P(X = 1, Y = 1) > P(X = 1)P(Y = 1)
P(X = 1, Y = 1)
> P(Y = 1)
P(X = 1)
P(Y = 1|X = 1) > P(Y = 1)
the outcome X = 1 makes it more likely that Y = 1
Y tends to increase when X does, and vice-versa
This result holds for any r.v. X and Y (not only Bernoulli r.v.)
CVEN2002/2702 (Statistics)
Dr Justin Wishart
43 / 50
4. Random variables
Covariance: interpretation
Cov(X , Y ) > 0 X and Y
tend to increase or decrease
together
Cov(X , Y ) = 0 no linear
association between X and Y
(doesnt mean there is no
association!)
(X(), Y())
Fact
X and Y independent Cov(X , Y ) = 0
CVEN2002/2702 (Statistics)
Dr Justin Wishart
44 / 50
4. Random variables
Covariance: examples
Example
Let the pmf of a r.v. X be pX (1) = pX (1) = 1/2 and Y = X 2 . Find Cov(X , Y )
We have Cov(X , Y ) = E(XY ) E(X )E(Y ) = E(X 3 ) E(X )E(X 2 ), but as X
only takes values 1 and 1, X 3 = X . It remains
Cov(X , Y ) = E(X )(1 E(X 2 ))
Also, E(X ) = (1) 1/2 + 1 1/2 = 0, so that
Cov(X , Y ) = 0
However, there is a direct functional dependence between X and Y
CVEN2002/2702 (Statistics)
Dr Justin Wishart
45 / 50
4. Random variables
Dr Justin Wishart
46 / 50
4. Random variables
Example
Example
We have two scales for measuring small weights in a laboratory. Assume the
true weight of an item is 2g. Both scales give readings which have mean 2g
and variance 0.05g2 . Compare using only one scale and using both scales
then averaging the two measures in terms of the accuracy.
The first measure X has E(X ) = 2 and Var(X ) = 0.05. Now, denote the
second measure Y , independent of X , with E(Y ) = 2 and Var(Y ) = 0.05.
Then, take W = X +Y
2 . We have
E(W ) =
1
1
2 2
E(X ) + E(Y ) = + = 2 (g)
2
2
2 2
and
Var(W ) =
1
1
(Var(X ) + Var(Y )) = (0.05 + 0.05) = 0.025 (g2 )
4
4
Dr Justin Wishart
47 / 50
4. Random variables
Correlation
The covariance of two r.v. is important as an indicator of the
relationship between them
However, it heavily depends on units of X and Y (difficult
interpretation, not scale-invariant)
the correlation coefficient is often used instead
It is the covariance between the standardised versions of X and Y , or,
explicitly,
Cov(X , Y )
= (
Var(X ) Var(Y )
Properties:
is dimensionless (no unit)
always has a value between 1 and 1 (Cauchy-Schwarz ineq.)
positive (resp. negative) means positive (resp. negative) linear
relationship between X and Y
the closer || is to 1, the stronger is the linear relationship
CVEN2002/2702 (Statistics)
Dr Justin Wishart
48 / 50
4. Random variables
Correlation examples
CVEN2002/2702 (Statistics)
Dr Justin Wishart
49 / 50
4. Random variables
Objectives
Objectives
Now you should be able to:
understand the differences between discrete and continuous r.v.
for discrete r.v., determine probabilities from pmf and the reverse
for continuous r.v., determine probabilities from pdf and the reverse
for discrete r.v., determine probabilities from cdf and cdf from pmf and
the reverse
for continuous r.v., determine probabilities from cdf and cdf from pdf and
the reverse
calculate means and variances for both discrete and continuous random
variables
use joint pmf and joint pdf to calculate probabilities
calculate and interpret covariances and correlations between two
random variables
Recommended exercises Q25 p.220, Q27 p.221, Q29&30 p.221, Q69
p.57, Q40&43 p.152, Q42 p.152, Q41 p.223, Q65 p.239
CVEN2002/2702 (Statistics)
Dr Justin Wishart
50 / 50