SlidesCourse 04.05 November
SlidesCourse 04.05 November
Using the definition of the pmf and of the conditional probability we get the
conditional pmf: f(x|X>=s) = P(X=x|X>=s) = P(X=x and X>=s)/P(X>=s) = P(X=x)/P(X>=s) =
= P(X=x)/(1-F(s-1)) for x >= s
f(x|X>=s) = P(X=x|X>=s) = 0 for x < s
Thus E(X|X>=s) = sum_(x=s,…,infinity) x . f(x|X>=s) =
sum_(x=s,…,infinity) x . P(X=x)/P(X>=s)
Simple example: X~Poisson(lam=20)
E(X|X>=20) = sum( (20:200)*dpois(20:200,lam=20)/sum(dpois(20:200,lam=20)) )
sum((20:100)*dpois(20:100,lam=20)/sum(dpois(20:100,lam=20)))
#[1] 23.3539 # E(X|X>=20)
?dgeom
dgeom(1,p=0.2)#[1] 0.16
dgeom(0,p=0.2)#[1] 0.2 # R counts the number of trials BEFORE the first
success
as our definition of the geometric distribution counts the number of trials TILL the first success
its domain is 1,2,3,...
To calculate the conditional expectations for our definition using CondExp() we have to add a
probability value 0 to the pmf vector. The next command shows that for s=1 we get 5 = 1/p which is
the
correct value for the geometric distribution.
CondExp(s=1,pmf=c(0,dgeom(0:150,p=0.2)))#[1] 5
CondExp(s=5,pmf=c(0,dgeom(0:150,p=0.2)))#[1] 9
CondExp(s=6,pmf=c(0,dgeom(0:150,p=0.2)))#[1] 10
CondExp(s=7,pmf=c(0,dgeom(0:150,p=0.2))) #[1] 11
For modelling inter event times the value E(X|s) – s is of interest
as it is the expected remaining waiting time till the next event given that no event occured till time s.
Example 6.C
The calls arriving in a call centre are assumed to follow a Poisson Process with rate 10
per hour. The operator sometimes takes a break for smoking 5min and cannot answer
arriving calls.
For each arriving call not answered he has to pay a fine of 2 $. If he takes 5 smoke
breaks a day calculate the probability that in a month with 22 working days he has to
pay a fine of more than 50 dollar. Calculate also the mean and the variance of the fine.
Example 6.D
A fisherman has the experience that the number of large fish L he will catch in one
night follows a certain distribution. We assume Poisson distribution with mean 30.
On the day before he can sell the right to obtain a “guaranteed quantity” of m fish at a
price of 15$ per piece; if he has caught more he can sell the rest on the free market for
10$. But if he cannot deliver m fish in the morning he has to pay a penalty of 100$ and
can sell his fish only at 10$ per piece.
a) Find the formula of the expected revenue for general m.
Note that (m is the decision variable).
b) Implement the formula and plot the expected revenue versus m = 1,2,...,40
Find the value of m that maximizes the expected revenue.
c) Use simulation and the formula of a) to find the expectation and the variance of the
revenue for m 15, 20, 25 and for the optimal value found in b). Compare the results
with those of c.
d) Find the formula also for the variance of the revenue.
a) Solution:
R … revenue: R(L) = 15m + 10(L-m) = 5m + 10L for L >= m
= 10L – 100 for L < m
How can we find E(R) = E(R(L)) = Sum_i (R(i)f_L(i))
E(R) = Sum_(i=0 to m-1) f_L(i) (10 i - 100) + Sum_(i=m to Inf) f_L(i) (5m + 10i)
c(which.max(Rv),Rv[which.max(Rv)])
#[1] 22.0000 398.5669
c) Solution:
simul <- function(n=1.e4,m=10,rL=rpois,...){
# simulates n different values of the revenue for given m
# rL ... random – variate generation function to generate L
# ... parameters to the function rL
L <-rL(n,...)
R <- ifelse(L<m,10*L-100,5*m+10*L)
mean(R)
}
simul(n=1.e4,m=10,rL=rpois,lam=30)
calcER(mv=c(10,15,20,22),Lv=0:200,pmf=dpois(0:200,lam=30))
#[1] 349.9989 374.8389 395.6253 398.5669
simul(n=1.e4,m=10,rL=rpois,lam=30)#[1] 350.604
simul(n=1.e4,m=20,rL=rpois,lam=30)#[1] 395.803
simul(n=1.e4,m=22,rL=rpois,lam=30)#[1] 398.184
simul(n=1.e4,m=22,rL=rpois,lam=30)#[1] 399.176
simul(n=1.e4,m=22,rL=rpois,lam=30)#[1] 399.46
d) Solution:
E(R) = Sum_(i=0 to M-1) f_L(i) (10 i - 100) + Sum_(i=M to Inf) f_L(i) (5M + 10i)
E(R^2) = Sum_(i=0 to M-1) f_L(i) (10 i - 100)^2 + Sum_(i=M to Inf) f_L(i) (5M + 10i)^2
Var(R) = E(R^2)-E(R)^2 …
Unit 7: Discrete and Continuous Joint Distributions
########################################################
JOINT PMF of two discrete RVs (X,Y)
Definition of joint pmf:
f(x,y) = P(X=x ∩ Y=y) = “other notations” = P(X=x and Y=y) = P(X=x, Y=y)
P((X,Y) ϵ B) = sum_((x,y) ϵ B) f(x,y) ... how to calculate the probability of events
ϵ ... \in
Example 7.A: Pair of two discrete RVs (X,Y)
Table representation of the joint pmf: f(x,y)
x
1 2 3 Sum
4 0.3 0.2 0.1 0.6
y 2 0 0.1 a 0.1+a
0 0 0 0.1 0.1
Sum 0.3 0.3 0.2+a 1
a) Select a such that f(x,y) is a joint pmf
Solution: Sum of all pmf values must be equal to 1; Sum f(x,y) = 0.8+a =1
a = 0.2
x
1 2 3
4 0.3 0.2 0.1
y 2 0 0.1 0.2
0 0 0 0.1
Sum 0.3 0.3 0.4 sum of probabilities = 1, it is a pmf
We can use the joint pmf (X,Y) to find the distribution (ie. the pmf) of X
“(marginal) pmf of X” fX(x) = f_X(x) = P(X=x) = sum_(all pairs with X=x) f(x,y)
It is often called MARGINAL pmf but it is the same as the pdf of X
Of course also for Y: marginal pmf of Y: fY(y) = f_Y(y) = P(Y=y)
f) Can we find the joint distribution of a pair of RVs (A,B) that have the same marginal
distributions as X,Y (ie. A the same pmf as X and B the same pmf as Y)
AND A and B are independent?
A
1 2 3 Sum
4 0.18 0.18 0.24 0.6
B 2 0.09 0.09 0.12 0.3
0 0.03 0.03 0.04 0.1
Sum 0.3 0.3 0.4 1
g) Is that joint distribution of A,B unique, or does there exist another pmf with the same
properties; A,B independent and pmf of A and B same as for X and Y?
YES !!!!
h) Is the behaviour of X,Y and A,B very similar???
Example 7.B: For the random pairs X,Y with joint pmf:
x
1 2 3 f_y(y)
4 0.3 0.2 0.1 0.6
y 2 0 0.1 0.2 0.3
0 0 0 0.1 0.2
0.3 0.3 0.4 …. f_X(x)
a) find the conditional pmf of X given that Y= 2:
answer: f(x|Y=2): f(1|Y=2) = f(1,2)/fY(2) = 0 / 0.3 = 0
f(2|Y=2) = f(2,2)/fY(2) = 0.1 / 0.3 = 1/3
f(3|Y=2) = f(3,2)/fY(2) = 0.2 / 0.3 = 2/3
b) Is the conditional pmf of X equal to the marginal pmf of X? NO!!!!!
X and Y are DEPENDENT
Informal observation:
Cov and Cor > 0 means that for x1 < x2 also E(Y|X=x1) < E(Y|X=x2)
Cov and Cor < 0 means that the opposite is correct
b) Find Cov(X,Y) and Cor(X,Y) (first guess if they are negative or positive)
E(X.Y) = sum(x.y.f(x,y)) =
= 4*1*0.3+4*2*0.2+4*3*0.1 +2*2*0.1+2*3*0.2 + 0*3*0.1 = 5.6
Cov(X,Y) = E(X.Y) – E(X).E(Y) = 5.6 – 2.1*3 = - 0.7
Var(X) = E(X^2) - E(X)^2 = 1*0.3+4*0.3+9*0.4 – 2.1^2 = 0.69
Var(Y) = E(Y^2) - E(Y)^2 = 4*0.3+16*0.6 – 3^2 = 1.8
Cor(X,Y) = Cov(X,Y)/sqrt(Var(X) Var(Y)) = -0.7 /sqrt(0.69*1.8) = - 0.62811
########################################################
Multinomial distribution:
very important in practice:
most popular discrete multivariate distribution
Continuous RV:
joint density f(x,y) must have integral_R^2 = 1
density is defined by:
f(x,y) = P( (X,Y) \in A) = integral_A f(x,y) dx dy
Example: for the joint density f(x,y) we know f(1,2) = 1.5.
What does this tell us about the probability close to (1,2) ???
P(1<X<1.1 and 2<Y<2.1) =approx. = 0.01 . f(1,2) = 0.015
Example 7.C: Continuous RVs X,Y:
f(x,y) = c x y for 0 < y < x < 1
0 else
a) Find c that f(x,y) is a density.
b) Find the densities of the marginal distribution of X and Y.
c) Find the conditional pdf of X given Y=0.5.
d) Find the conditional pdf of Y given X=0.5.
e) P(Y < 1-X)
Solutions:
b) f_X(x) = ???
domain is subset of (0,1)^2 = (0,1) x (0,1); domain is the triangular (0,0) (1,0) (1,1)
f_X(x) = integral(-inf to inf) f(x,y) dy = integrate(0 to x) c x y dy =
= c x integral_(0 to x) y dy = c x/2 (y^2)_(0 to x) = c x^3/2
Basic definitions
(for more explanations and examples see Video: IE255.7i, Video: IE255.7j and Video: IE255.7k)
Formula(3.13) Definition of expectation for continuous joint distributions
E(h(X,Y)) = integral_R integral_R h(x,y) f(x,y) dx dy