In this homework you can use R for any numerical calculations.

Problem 1

  1. Say X is a discrete random vector with \(P(X=k)=c(30-(k-5)^2)\), k=0,..,10, c some constant. Let F be the cdf. Find F(7)
k=0:10
cc=sum(30-(k-5)^2)
p=c(30-(k-5)^2)/cc
cumsum(p)[k==7]
## [1] 0.8181818
  1. Say X is a continuous random vector with \(P(X=x)=c(30-(x-5)^2), 0<x<10\), 0 otherwise, c some constant. Let F be the cdf. Find F(7).

\[ \begin{aligned} &F(x) =\int_{-\infty}^\infty f(t)dt = \int_0^x c(30-(t-5)^2) dt =\\ &c(30t-(t-5)^2/2)|_0^x = c(30x-(x-5)^2/2) \\ &1=F(10) =c(30*10-(10-5)^2/2) = c216.666\\ &F(7) = (30*7-(7-5)^2/2)/216.1666 = 0.7646 \end{aligned} \]

Problem 2

Let X be an exponential random variable with rate 1, that is \(f(x)=e^{-x},x>0\). Let Y=X|X>1. Find \(F_Y(2)\). Write a simulation in R that verifies your answer. (R command: rexp(n, 1))

\[ \begin{aligned} &F_Y(y) =P(Y<y) = P(X<y|X>1) = \\ &\frac{P(1<X<y)}{P(X>1)} =\frac{F_X(y)-F_X(1)}{1-F_X(1)} \\ &F_X(x) =\int_0^x e^{-t}dt=-e^{-t}|_0^x = 1-e^{-x}=\\ &F_Y(y) = \frac{e^{-1}-e^{-y}}{e^{-1}} = 1-e^{1-y}\\ &F_Y(2) = 1-e^{1-2} = 0.6321\\ \end{aligned} \]

x=rexp(1e5, 1)
y=x[x>1]
sum(y<2)/length(y)
## [1] 0.6309964

Problem 3

Let the random variable X have density \(P(X=k) = k/6, k=1,2,3\). Let the random variable Y have conditional density \(f_{Y|X=k}(y|k)=ke^{-ky}\). Find \(F_Y(2)\).

\[ \begin{aligned} &f_{Y|X=k}(y|k) = \frac{f(k,y)}{f_X(k)}\\ &f(k,y) = f_X(k)f_{Y|X=k}(y|k) = \frac{k}6ke^{-ky}\\ &f_Y(y) =\sum_{k=1}^3 f(k,y) =\sum_{k=1}^3 \frac16 k^2e^{-ky}\\ &F_Y(y) = \int_0^y\sum_{k=1}^3 \frac16 k^2e^{-kx}dx = \\ &\frac16\sum_{k=1}^3\int_0^y k^2e^{-kx}dx =\\ &\frac16\sum_{k=1}^3 (-ke^{-kx}|_0^y =\\ &\frac16\sum_{k=1}^3 k(1-e^{-ky}) \\ &F_Y(2) =\frac16\sum_{k=1}^3 k(1-e^{-2k}) = 0.97\\ \end{aligned} \]

k=1:3
sum(k*(1-exp(-k*2)))/6
## [1] 0.9700995

Here is a simulation to verify the answer:

x=sample(1:3, size=1e5, replace=TRUE, prob=1:3)
y=rexp(1e5, x)
sum(y<2)/1e5
## [1] 0.96938

Problem 4

Say X and Y are two independent continuous random variables with the same density f. What can be said about \(P(X<Y)\)?

Here is one solution, using the law of total probability for continuous random variables:

\[ \begin{aligned} &P(X<Y) =\int_{-\infty}^\infty P(X<Y|Y=y)f(y)dy = \\ &\int_{-\infty}^\infty P(X<y)f(y)dy = \\ &\int_{-\infty}^\infty F(y)f(y)dy = \\ &F(y)^2|_{-\infty}^\infty - \int_{-\infty}^\infty f(y)F(y)dy = \\ &1-P(X<Y)\\ &2P(X<Y)=1\\ &P(X<Y)=\frac12 \end{aligned} \]

and here is another solution:

Let’s say f is their density, F the cdf, then by independence f(x)f(y) is their joint density. So

\[ \begin{aligned} &P(X<Y) =\int_{-\infty}^\infty \int_{-\infty}^x f(x)f(y)dydx = \\ &\int_{-\infty}^\infty f(x)\left(\int_{-\infty}^x f(y)dy\right)dx = \\ &\int_{-\infty}^\infty f(x)F(x)dx = \\ &\int_0^1 t dt = t^2/2\rvert_0^1 = \frac12 \end{aligned} \] were I did the substitution t=F(x), so dt=f(x)dx, \(F(-\infty)=0\) and \(F(\infty)=1\).

What can be said if X and Y are discrete? First here is a simple calculation that is always true:

\[1=P(X<Y)+P(X=Y)+P(X>Y)\]

wlog we can assume that X and Y take integer values (why?), so

\[ \begin{aligned} &P(X>Y) =\\ &\sum_{i=0}^\infty \sum_{j=i+1}^\infty f(i)f(j) =\\ &\sum_{j=0}^\infty \sum_{i=0}^{j-1} f(j)f(i) = \\ &P(X<Y) \\ \end{aligned} \] by a simple change of summation. So now we have

\[ \begin{aligned} &1=P(X<Y)+P(X=Y)+P(X>Y) =2P(X<Y)+P(X=Y) \\ &P(X<Y) =\frac{1-P(X=Y)}2 \end{aligned} \]

so clearly \(0\le P(X<Y) \le \frac12\).

One of the extreme cases can happen: Say X,Y are degenerate random variables, that is for some real number k P(X=k)=1, then P(X=Y)=1 and P(X<Y)=0. On the other hand there is at least one number k such that \(P(X=k)=P(Y=k)=\delta>0\) , so then

\[P(X=Y)>P(X=k,Y=k)=P(X=k)P(Y=k)=\delta^2>0\]

and then

\[P(X<Y) =\frac{1-P(X=Y)}2\le \frac{1-\delta^2}2<\frac12\]

So all that can be said in the discrete case is \(0\le P(X<Y)< \frac12\).

So the answer that is always true for continuous random variables is never true for discrete ones!