0% found this document useful (0 votes)
17 views20 pages

SlidesCourse 7 8 Oct

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views20 pages

SlidesCourse 7 8 Oct

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 20

UNIT 3: Random Variables (RV), CDF, pmf and pdf

also called Random Variates; very IMPORTANT !!!


Definition: random variable is a function from the sample space to the real numbers R
ie: each event is assigned a numeric value
==> for one random experiment and one sample space we can define
MANY DIFFERENT RANDOM VARIABLES !!!

EXAMPLE 1: Random experiment: Rolling of two dice:


Sample space S = { (1,1), (1,2), (1,3),…,(1,6),(2,1),(2,2),…,(2,6),(3,1),… ,(6,6)},
S has 36 outcomes (also called elementary events)
For this random experiments we can define many different random variates:
a) RV: X = “Sum of the two Results”; Y= “minimum of the two results”; …
How can we describe a RV like X or Y informally?
* Numeric result of a random experiment
or
* a (single, for now unknown) result (number) of a random experiment
After the random experiment X we know its results and therefore also the value of X.
we then write x … realisation of a random experiment:
Eg. we role the two dice and observe (3,2)  the realisation of X denoted x = 5

Definition: The set of all possible values of X is called its “domain”, or “range”
In practice we very often do NOT consider the
elementary events of a random experiment
the sample space and the probability function related to that sample space.
Instead we directly consider a random variate related to that random experiment.
HOW CAN WE DESCRIBE THE RANDOM “BEHAVIOUR” OF A RV?
we say: we describe the “DISTRIBUTION” of a RV ;
For discrete RVs the probability mass function (pmf) f(x) is very important:
Definition: pmf: f(x) = fX(x)= P(X=x) for x = 0, 1, 2, ...
For discrete RVs also the letter K is used for X. Then the pmf is dented by fK(k)
Example: We consider the RV “sum shown when rolling 2 dice”.
Find the domain and the pmf of X:
Solution: Domain: Clearly the sum of 2 dice can take the values (2,3,4,…,12)
f(2) = f(12) = 1/62
The above plot, the formula P=opportune/possible and counting helps to find all pmf
values: P(X=2) = 1/36, P(X=3) = 2/36, P(X=4) = 3/36,.., P(X=7) = 6/36,
P(X=8) = 5/36, P(X=9) = 4/36, P(X=10) = 3/36, P(X=11) = 2/36, P(X=12) = 1/36
Figure of the pmf of X fX(x) (also can be denoted fK(k))

This example makes obvious that knowing the pmf we know the exact random
behaviour (ie. the distribution) of the RV X.

What are the properties of the pmf: 1) 0 ≤ f(x) ≤ 1 2) sum_{x in domain} f(x) = 1
properties pmf f(x):=P(X=x): 1) 0 ≤ f(x) ≤ 1 as each f(x) is a probability
2) sum of all non-zero values = 1

Example 1b: A discrete RV Y has the pmf f(0) = 0.4, f(1)=0.4, f(2)=0.2
Check that f is a pmf and find the proability P( Y > 0.5 ).
Solution: P( Y > 0.5 ) = f(1) + ...
The most general approach to describe the behaviour of a RV is to use the

Cumulative Distribution Function (CDF) F(x)


CDF F(x) = FX(x)
Definition CDF of a RV X: F(x) = P(X ≤ x) !!!!!!!
The CDF fully defines the distribution of a RV.
We can easily calculate the probabilities of all possible outcomes using the CDF
e.g.: P(3<X≤ 5) = P(X≤5 AND (X< = 3)c ) = P(X≤5 AND Not(X< 3)) = F(5) – F(3)

What are the properties of all CDF


1) F is a function: R  [0,1]
2) F is a non-decreasing function
3) lim_{x to - infinity} = 0 and lim_{x to infinity} = 1
ie: in the “far left” it must “start from” 0 in the “far right” it must “end with” 1

Is a CDF (always) a continuous function ???


F(x) is “right continuous” but  it can have jumps

A RV X is called continuous if it has a continuous CDF

Example of a continuous RV:


0 for x <0
sqrt(x)/2 for 0≤x < 4
1 for x >=4
a) Make a plot of that function. Is it a CDF?
F<- function(xv){ ifelse(xv<0,0,ifelse(xv<4,sqrt(xv)/2,1))}
# ?ifelse
# ifelse(“condition”,”vector for condition T”,”vector for F” )
plot(xv<- seq(-1,5,1.e-3), F(xv), type= "l",main="F(x)")

b) Find the Prob(X>4.5), P(X≤0.5), P(X=0.5), P(0.2≤ X ≤0.5)


Prob(X>4.5) = P( (X≤4.5)^c) = 1 – F(4.5) = 1-1=0
P(X ≤ 0.5) = F(0.5)
for a < b
P(a < X ≤ b) = P(X ≤ b) – P(X≤a) = F(b) – F(a)
P(X =a) = P(a < X ≤ a) = P(X ≤ a) – P(X< a) = 0 !!! IMPORTANT
continuous RV: P(X=c) = P(c<X≤c) = F(c) – F(c) = 0 for any real number c
F(0.5)=0
P(0.2<X ≤0.5) = P(0.2<X <0.5) = P(0.2=<X =<0.5) = F(0.5) – F(0.2)

CDF of the Discrete RV X with the CDF defined by:

CDF <- function(x){


ifelse(x<0,0,
ifelse(x<1,0.1,
ifelse(x<2,0.3,
ifelse(x<3,0.9,1))))
}
plot(xv<- seq(-0.5,3.5,0.001),CDF(xv),type= "l"))
points(0:3,c(0.1,0.3,0.9,1))
P(0.5< X ≤ 0.7) = F(0.7) –F(0.5) = 0.1-0.1=0
P(2<X≤3) = F(3) – F(2) = 1 – 0.9 = 0.1 much easier = f(3) (see below)
P(2≤X≤3) = F(3) – F(1) = 1 – 0.3 = 0.7 = much easier = f(2) + f(3) (see below)
P(X=1) = F(1) – F(0.99999999) = F(1)-F(0) = 0.3-0.1 = 0.2 = “height of the jump”= f(2)
What are possible values; only for x= jump point we have non-zero probabilities
What is the domain of X ? {0,1,2,3}
DEFINITION: Probability Mass Function (pmf) (repeated from above)
define for discrete RVs define the “probability mass function”: pmf (discrete pdf)
f(x) = P(X=x) f(0) = P(X=0) =P(-0.0001≤X≤0) = F(0) – F(-0.0001) = 0.1 – 0 = 0.1
instead of F(-0.0001) the exact notation is
left-limit_{x-->0} F(x) = 0 not equal to F(0) thus we know: F(x) not continuous in 0
f(0) = “height of the jump at 0”
f(x) = “no jump” = 0 for 0 < x <1
f(1) = “height of the jump at 1” = F(1)-F(0.9999) = F(1) –F(0) = 0.3-0.1 = 0.2
f(2) = F(2) –F(1) = 0.9-0.3 = 0.6
f(3) = F(3) –F(2) = 1-0.9 = 0.1
table format of CDF and pmf of a DISCRETE distribution:
x 0 1 2 3
F(x) 0.1 0.3 0.9 1
f(x) 0.1 0.2 0.6 0.1 sum_{x =0,1,2,3} f(x) = 1
P(X >1) = f(2) + f(3) = 0.7
P(2≤X < 3) = f(2) = 0.6
P(0< X <3) = f(1)+f(2) = 0.2+0.6 = 0.8

********************************
Continous RV: Definition Probability density function (pdf) or density
X has a continuous CDF and Prob(X=c) = 0 for all c in R

Probability density function: (pdf): f(x) = F’(x) = dF(x)/dx


pdf f(x) is the derivative of the CDF
1) integral_(-infinity to infinity) f(x) dx = 1
2) f(x) non-negative
Note: f(x) > 1 is possible for a pdf (continuous X).

Example A: X continuous RV with a linear CDF on (0,0.5)


0 for x <0
F(x) = 2x for 0≤x<0.5
1 for 0.5≤x
Is F(x) continuous? Find the density.

Is this CDF F(x) continuous: YES as left and right limit at 0 and 0.5 are the same
Find the density:
I) CDF is continuous
II) pdf: f(x) = F’(x) = 2 for 0 ≤ x < 0.5 constant 2 on (0,0.5) and 0 elsewhere
0 else

f(0.2) = 2 ???? can f() be larger than 1? YES!!!!!!


The pdf (density) f(x) has the property:
P(a< X ≤b) = integral_(a to b) f(x) dx
F(x) = P(X≤x) = integral_(-infinity to x) f(t) dt
WRONG IS the statement: F(x) = integral f(x) dx WRONG !!!!!
BUT
F(x) is the anti-derivative of f(x) with correctly selected integration constant !!!
UNIT 3: Examples CDF pdf etc..
F(x) = P(X≤x) ...CDF
Example A0
0 x<0
F(x) = floor(x)/5 0 ≤ x < 5
1 5≤x

a) Find P(X=2), P(X=2.5), is X discrete or continuous or a mixture?


b) Show that F(x) is a CDF
Solution: a)
P(X=2) = F(2) - F(1.9999) = 2/5 - 1/5 = 1/5
P(X=2.5) = F(2.5) - F(2.4999) = 2/5 – 2/5 = 0
Is X discrete or continuous?
Discrete as F(x) is a step function, every constant, only jumps at 1, 2, 3, 4, 5
b) To show that F(x) is a CDF

1) as floor(x) is non decreasing and


F(0) = floor(0)/5 = 0 constant at0 and
at x=5 F(5) from left is floor(5)/5=1 from right it is 1 ==> constant
F(x) is not-decreasing
2) limit_(x --> - infinity) F(x) = 0, limit_(x --> infinity) F(x) = 1
3) non-decreasing and limits show that 0 ≤ F(x) ≤ 1
4) F(x) is right continuous: ok as floor() is right continuous also true for F(x)
lim_(n --> infinity) floor(1 + 1/n) = floor(1) = 1 ==> right continuous in 1
lim_(n --> infinity) floor(1 - 1/n) = 0 not equal floor(1) ==> NOT left continuous in 1
Definition of continuous at x=5 using sequences:
xn with limit_(n --> infinity) xn = 5

f is continuous ≤=> lim_(n --> infinity) f(xn) = f(5)


left –continuous for xn < than limit
right-continuous for xn > than limit

note that ceiling() is NOT right continuous (but left-continuous)

plot(c(-0.5,5.5),c(-1,5.5),pch="",main="floor()")
lines(c(-0.5,0),c(-1,-1))
lines(0:1,rep(0,2))
lines(1:2,rep(1,2))
lines(2:3,rep(2,2))
lines(3:4,rep(3,2))
lines(4:5,rep(4,2))
lines(5:6,rep(5,2))
points(0:5,0:5)

windows();plot(c(-0.5,5.5),c(-1,5.5),pch="",main="ceiling()")
lines(c(-0.5,0),c(-1,-1))
lines(0:1,rep(0,2))
lines(1:2,rep(1,2))
lines(2:3,rep(2,2))
lines(3:4,rep(3,2))
lines(4:5,rep(4,2))
lines(5:6,rep(5,2))
points(0:5,(0:5)-1)
Example A0 continued:
0 x<0
F(x) = floor(x)/5 0 ≤ x < 5
1 5≤x pmf: (discrete pdf) f(x) = P(X=x)
b) Find the table representation of the pmf and the CDF.
note that for X a discrete random variate with domain subset of the
integers we can calcuate: f(x) = F(x)-F(x-0.0001) x = 0,1,2,3
x 0 1 2 3 4 5 6
F(x) 0 0 1/5 2/5 3/5 4/5 1 1
f(x) 0 0 1/5 1/5 1/5 1/5 1/5 0
We can see that X has the discrete uniform distributio with
domain 1,2,3,4,5
c) Calculate probabilities like P(3≤X≤6)
c) answer: P(3≤X≤6) =f(3)+f(4)+f(5)+f(6) =3/5+0=0.6
NOTE: it is easiest to use the pmf; we can also use F(6) – F(2) = 0.6
Example B0:
f(x) = -c x for -1 ≤ x < 0
0 else
a) Select the value c such that f is a density.
b) Find the CDF. c) Check that the CDF you found is really a CDF.
d) Check if the CDF you found is continuous.
Example B0:
f(x) = -c x for -1 ≤ x < 0
0 else
a) Select the value c such that f is a density.
b) Find the CDF.
c) Check that the CDF you found is really a CDF.
d) Check if the CDF you found is continuous.
a) integral_(-1 to 0) -c x dx = -c integral_(from-1 to 0) x dx = -c (x2/2)_(from-1 to 0) =
= -c(-1/2)=c/2
a density must have integral 1 so we have to select c = 2.
b) Way 1: F(x) = integral_(from-1,x) -2y dy = -2 (y2/2)_(from-1,x) =
= -2(x2/2-1/2) = - x2 + 1 for -1< x ≤ 0
Way 2: F(x) = integral -2x dx = - 2 x2/2 = - x2 + const for -1< x ≤ 0
We know that F(0) = 1; so const must fulfill F(0) = - 02 + const = 1 and const =1
F(x) = - x2 + const = - x2 + 1 for -1< x ≤ 0
Final Result for b):
F(x) = 0 for x < -1
1 - x2 for -1≤ x < 0
1 for 0 ≤ x
c) limit x to –infinity “=F(-9999999)” = 0 limit x to –infinity “= F(9999999)”=1
F(x) is non-decreasing so F is a CDF
d) F(-1) =0 from left and right F(0) = 1 from left and right thus F(x) is continuous
Example B:
c(1+x) for -1 ≤ x < 0
f(x) = c(1-x)^2 for 0 ≤ x < 1
0 else
X discrete or continuous? answer: X continuous as f(x) is non zero for whole (-1,1)
a) Find c that f(x) is a density. b) Find the CDF.

Solution: a) integral_(-1,1) f(x)dx =


c integral_(-1,0)1+x dx + c integral_(,1)(1-x)^2 dx =
= c 1/2 + c 1/3 = c 5/6 c 5/6 =1 ==> c=6/5 = 1.2
b) “Way 1 to find CDF”: Definition of the CDF
for x < 0:
F(x) = P(X≤x) = 1.2 integral_(-1,x)1+t dt = 1.2 [t+t^2/2]_(-1,x)=
1.2(x+x^2/2-(-1+1/2))
==> F(x) = 1.2(x+x^2/2+1/2) for -1 ≤ x < 0
for x > 0: F(x) = P(X ≤ x) = integral_(-infinity,x) f(t) dt =
1.2 (integral_(-1,0)1+t dt + integral_(0,x)(1-t)^2 dt ) =
1.2( 0.5 + [-(1-t)^3/3]_(0,x)) =
1.2( 0.5 + [-(1-x)^3/3 +1/3 ] = 6/5(5/6-(1-x)^3/3)
==> F(x) = 1 - 0.4(1-x)^3 for 0 ≤ x < 1
F(x) = 0 for x < -1
= 1.2(x+x^2/2+1/2) for -1 ≤ x < 0
= 1 - 0.4(1-x)^3 for 0 ≤ x < 1
= 1 for 1 ≤ x
To check if F(x) is continuous we check
1.F(-1)= 1.2(-1+1/2+1/2)= 0 ok
2.left F(0) = 1.2/2 = 0.6; right F(0) = 1 – 0.4*1 = 0.6
3.left F(1) = 1 – 0.4*0 =1
b) Way 2 to find CDF: use the anti-derivative of f(x) and find the
integration const
f(x)= 1.2(1+x) -1 ≤ x < 0 F(x) = 1.2(x+x^2/2) + c1
we use F(-1) =0 to find c1: F(-1) = 1.2(-1+1/2) + c1 = -0.6 + c1 =0 ==>
c1=0.6
1.2(1-x)^2 0 ≤ x < 1 F(x) = -1.2(1-x)^3/3 + c2
we use F(1) =1 to find c2: F(1)= -1.2(1-x)^3/3 + c2 = 0+c2 =1 ==> c2=1
F(x) = 0 for x < -1
1.2(x+x^2/2) + 0.6 for -1 ≤ x < 0
-0.4(1-x)^3 + 1 for 0 ≤ x < 1
1 for 1≤ x

Example C0: We consider the random variate X with cdf:


F(x) = 0 for x < 0
0.5 + 0.5 x2 for 0 ≤ x < 1
1 for 1 ≤ x
a) Make an approximate plot of F(x) and of the density f(x) or describe the density.
b) Find out if F is continuous. If not find all x where there is a point mass.
c) Find the probabilities: P(X=1), P(X=0), P(0.5<X<1.5), P(-1<X<0.5)
d) How can we describe the distribution of X as a mixture distribution.
Answers both: a and b) For 0 < x < 1 the CDF is differentiable: f(x) = dF(x)/dx = 0.5 ( 2 x) = x
for x < 0 and for x > 1 the derivative of F(x) = 0.
* for x=0 the left limit of F(x) = and the right limit is 0.5. Thus F is not continuous at 0.
At x=0 there is a mass point with mass = “right limit”-“left limit” = 0.5-0 = 0.5.
so f(0) is not defined, we could alsosay it is infinity
* for x = 1 the left and right limit are both equal to 1. Thus there is NO point mass at 1 !!
but for x=1 the left derivative of F(x) is 1 and the right derivative is 0
==> F is not differentiable in x=1; not important for probability as it is an isolated point
c) The above discussion implies directly: F(0)=0.5, F(1)=0
P(0.5<X<1.5) as there is no point mass in both endpoints we can use the standard formula
P(0.5<X<1.5) = F(1.5)-F(0.5) = 1- (1/2 + 1/8) = 3/8
P(-1<X<0.5) as there is no point mass in both endpoints we can use the standard formula
P(-1<X<0.5) = F(0.5) – F(-1) = F(0.5) = 5/8
d) This is a mixture of a point mass of 0.5 at 0 and a continuous distribution with linear
increasing density on (0,1). Both parts of the mixtur have probability 0.5.

Example C: We consider the random variate X with cdf:


F(x) = 0 for x < 0
= 0.2 x for 0 ≤ x < 1
= 0.5 x^(1/2) for 1 ≤ x < 4
=1 for 4 ≤ x
a0) Make an approximate plot of F(x) and the density and the describe the distribution.
a) Find the P(X=0.5), P(X=1), P(X=1.5) Is this a continuous or discrete distribution?
b) Find P(0.5 < X ≤ 1.21) and P(0.5 ≤ X ≤ 1.21)
c) Find P(1 < X ≤ 1.21) and P(1 ≤ X ≤ 1.21)
Answer a) without R: P(X=0.5) = 0 as CDF is continuous at x=0.5
P(X=1)=?: F(1)=0.5 “left limit of F(1)”=F(0.9999999) is 0.2
==> F(1)-0.2 = 0.3
P(X=1.5) = 0 as CDF is continuous at 1.5
P(X=0) = 0 as F continuous and P(X=4) = 0 as F is continuous.
X is mixture of continuous and discrete distribution:
X it has a “point mass” of weight 0.3 at x=1
answer a0) X is the mixture of a point mass at x=0 with weight 0.3,
a continuous uniform distribution on (0,1) with weight 0.2,
and a continous distribution on (1,4) with weight 0.5 and with decreasing density.
Checking our Answer a) with R:
CDF<- function(x){
res<- ifelse(x < 0, 0,
ifelse(x < 1, 0.2*x,
ifelse(x < 4, 0.5*sqrt(x),
1)))
return(res)}
plot(xv<-seq(-1,5,1.e-3),CDF(xv),type="l",main="CDF Ex. C")
P(X=2)= F(2)-F(1.9999999) = 0
P(X=1)= F(1)-F(1.9999999) = 0.5-0.2 = 0.3

For answering b)and c)below we use the formula for probabilities calculated using the CDF
F(x) correct for discrete, continuous and mixed distributions:
General Formula: P(a<X≤b) = F(b)-F(a)
b) Find P(0.5 < X ≤ 1.21) and P(0.5 ≤ X ≤ 1.21)
Find P(0.5 < X ≤ 1.21)= F(1.21) – F(0.5) = 0.5 – 0.1 = 0.45
P(0.5 ≤ X ≤ 1.21) = 0.45 as P(X=0.5) is 0.
c) Find P(1 < X ≤ 1.21) and P(1 ≤ X ≤ 1.21)
P(1 < X ≤ 1.21) = F(1.21) – F(1) = 0.55 – 0.5 = 0.05
P(1 ≤ X ≤ 1.21) = F(1.21) – F(1) + P(X=1) = 0.55 – 0.5 + 0.3 = 0.35
How can we describe the distribution of Example C?
1) continuous uniform distribution for X < 1 with P(X<1) = 0.2
2) P(X=1) = 0.3 ... point mass at 1.
3) continuous distribution for X >1 with density proportional to
1/sqrt(x) for 1 < x < 4; P(X>1)= 1-F(1) = 0.5.
Note that this mixture of a discrete and a continuous distribution can be
only described by the CDF.
This non-continuous CDF has no pdf and no pmf.
When we try to find a pdf we could use (as some authors) f(1) = infinity
but this notation does not exactly describe the distribution as the weigth
of the point mass is not given.

#######################################################
Homework Questions:
Q 3.6: We consider the random variate X with the properties:
P(X=0)=0.5 and all points in the interval (0,2) have the same
probability (and no points outside of [0,2) ).
Hint for Question 3.6:

1. P(X=0) = 0.5
2. all points in (0,2) have the same probability
add: 3. Prob(X<0 or X>=2)=0
UNIT 4: Part 1
Expectation and Variance
X discrete RV with pmf: f(0)=0.2;f(1)=0.6;f(2)=0.1;f(3)=0.1
How can we generate realisations of X ?
y<- sample(x=0:3,size=1.e6,replace=T,prob=c(0.2,0.6,0.1,0.1))
length(y) [1] 1000000
table(y)
Y
0 1 2 3
199575 599888 100349 100188
How can we describe 2 main properties of a RVs ?

Expectation E(X) … average outcome of the RV if we repeat it often


mean(y)# 1.1000125
formula for E(X), formula for the average result of the random experiment:
E(X) = 0*0.2 + 1*0.6+ 2*0.1 +3*0.1 = 1.1
E(X) = sum( x . f(x)) …. Formula for expectation for discrete RV
Y pmf: f(0) = 0.2; f(1) = 0.6; f(2) = 0.2 E(X)=1
E X = typical value of the RV X
Expectation need not be a possible value of the random experiment

Variance: Var(X) = V(X) … measure for the average distance to the mean value
Var(X) = E( (X-E(X))^2) = sum( (x-E(X))^2 f(x) ) = sum( x^2 f(x)) – E(X)^2
The variance is the average squared distance from the expectation

Question: RV with E(2.5) and Variance 0. Find its domain and pmf !
Answer: domain = {2.5} pmf: f(x) = 1 for x= 2.5
0 else
This is called a deterministic experiment.
Example A: X discrete RV with pmf: f(0) = 0.2; f(1) = 0.6; f(2) = 0.1; f(3)=0.1
a) Guess if the expectation is 1, > 1 or < 1
Due to the simulation we guess that E(X) > 1
b) Write R-code to generate from X and check if your guess was correct!
y<- sample(x=0:3,size=1.e6,replace=T,prob=c(0.2,0.6,0.1,0.1))
mean(y) 1.100125
c) Calculate the expectation E(X) and compare it with the result of b).
0*0.2 + 1*0.6+ 2*0.1 +3*0.1 = 1.1
We write a function that calculates expectation and variance
of discrete RVs:
meanVarRV <- function(x=0:3,prob=c(0.2,0.6,0.1,0.1)){
# calculates the mean and the variance of a discrete RV
fx <- prob
EX <- sum(x*fx) # Expectation
VX <- sum((x-EX)^2*fx) # Variance
return( c(EX=EX,VarX=VX))
}
meanVarRV(x=0:3,prob=c(0.2,0.6,0.1,0.1))
# EX VarX
# 1.10 0.69
d) Calculate the Variance.
Var(X) = sum( x^2 f(x)) – E(X)^2 = 0 * 0.2 + 1*0.6+ 4*0.1 + 9 *0.1 - 1.1^2 = 0.69

Definition: Expectation of the function of a RV


E(g(X)) = sum( g(x) . f(x) )

Example B: X discrete RV with pmf: f(0) = 0.2; f(1) = 0.6; f(2) = 0.1; f(3)=0.1
Consider a game with a final payment of X^2. How much must be payed
for such a game that it is a fair game.
a) What is the expected payment of this game?
E(payment(X)) = E(X^2) = 0*0.2+ 1^2 *0.6 + 2^2 *0.1+ 3^2 *0.1 =1.9
b) What has to be the payment the gamer has to pay that it is a fair game?
payment has to be 1.9:
Win = -1.9 + X^2
E(Win) = -1.9 + E(X^2) = -1.9 +1.9 = 0 …. Fair game.

Use simulation to check your results of Example A and B .


Example A
X<-sample(x=0:3,size=1.e6,replace=T,prob=c(0.2,0.6,0.1,0.1)) m
mean(X) # simulated value of E(X)
#[1] 1.09993
var(y) # simulated value of V(X)
#[1] 0.6896607

# Example B
X<- sample(x=0:3,size=1.e6,replace=T,prob=c(0.2,0.6,0.1,0.1))
mean(X^2)# expected payment in the game
#[1] 1.895456
mean(-1.9+X^2)# expectation of fair game
#[1] -0.004544

Two important formulas


E( 3+5.X) = 3 + 5 . E(X)
V ( 3+X) = V(X)
clear by the fact that the variance is the average squared distance from the mean
V ( 3+5 X) = 5^2 V(X)
Example C: The continuous RV X has the CDF:
f(x) = x + 1 for -1 < x < 0
1 for 0 <= x < 0.5
0 else
pdf<- function(x){
res <- ifelse(x< -1,0,
ifelse(x<0, x+1,
ifelse(x< 0.5, 1,0)))
return(res)
}
plot(xv<- seq(-2,2,0.001), pdf(xv),type= "l ")
a) Guess if the expectation is 1, > 1 or < 1
b) calculate the expectation.
c) calculate the variance
d) For Z = 5 + 4 X calculate the expectation and the variance
f(x) = x + 1 for -1 < x < 0
1 for 0 <= x < 0.5
0 else
Solution:
a) my guess: E(X) a bit smaller than 0

b)
E(X) = integral_(-inf, inf) x f(x) dx =
= integral_(-1,0) x (x+1) dx + integral_(0,0.5) x dx =
= integral_(-1,0) x^2 +x dx + x^2/2_(0,0.5) =
= (x^3/3 +x^2/2) _(-1,0) + (x^2/2)_(0,0.5) =
= (0 – (-1/3+1/2)) + 0.25/2-0 = -1/6 + 1/8 = -0.04166667
c)
E(X^2) = integral_(-inf, inf) x^2 f(x) dx =
= integral_(-1,0) x^2 (x+1) dx + integral_(0,0.5) x^2 dx =
= integral_(-1,0) x^3 +x^2 dx + x^3/3_(0,0.5) =
= (x^4/4 +x^3/3) _(-1,0) + (x^3/3)_(0,0.5) =
= (0 – (1/4-1/3)) + 0.125/3-0 = 1/12 + 1/24 = 3/24 = 1/8
V(X) = E(X^2) – (E(X))^2 = 1/8 - (-0.04166667)^2 = 0.1232639
d) E(Z) = E(5 + 4 X) = 5 + 4 E(X) = …
V(Z) = V(5 + 4 X) = 4^2 V(X) = …

Example B: RV X with E(X) = 3 and Var(X) = 4


a) Find the second moment of X = E(X^2)
Var(X) = E(X^2) – (E(X))^2  E(X^2) = Var(X) + (E(X))^2 = 4 +3^2= 13
b) Find E(2+3X+ X^2)
E(2+3X+ X^2) = 2+3E(X)+ E(X^2) = 2 + 3*3+13 =24
c) Find E( (X-3)^2 )
E( (X-3)^2 ) = E( X^2 -6X+9) = E(X^2) – 6E(X)+9 = 4
E(X^2) NOT EQUAL (E(X))^2 Why??
We can write the expectation only “inside” of linear transforms !!!

Example: We consider two urns with 3 balls numbered (0, 1, 2) and (1, 2, 3).
U1, U2 ... number obtained from randomly drawing from urn 1 and urn 2 respectively
Find the exact value of E(U1 . U2) and Var(U1 . U2).

Solution: We define: Y = U1 . U2
we find first the pmf of Y
f_Y(0) = P(Y=0) =P(U1=0) = 1/3;
f_Y(1) = P(U1=1 and U2=1)= 1/9
f_Y(2) = P((1, 2) or (2,1))= 2/9
f_Y(3) = P((1,3) )= 1/9
f_Y(4) = P((2, 2))= 1/9
f_Y(6) = P((2, 3))= 1/9
pmf <- c(3,1,2,1,1,0,1)/9
Y <- 0:6
sum(pmf*Y) # E(X) [1] 2
> sum(pmf*Y^2)- sum(pmf*Y)^2 # Var(X)
[1] 3.777778
E(Y) = sum(x . f(x)) = (0*3 + 1*1+2*2+3*1+4*1+6*1)/9 = 2
E(Y^2) = sum(x . f(x)) = (0*3 + 1*1+4*2+9*1+16*1+36*1)/9 = 70/9 = 7.77778
Var(Y) = 70/9 – 2^2 = 34/9 = 3.77778
comparing the results of simulation and the exact formula show the they are correct

You might also like