# HIDDEN
from datascience import *
from prob140 import *
import numpy as np
import matplotlib.pyplot as plt
plt.style.use('fivethirtyeight')
%matplotlib inline
import math
from scipy import stats
from sympy import *
init_printing()
Informally, the definition of independence is the same as before: two random variables that have a joint density are independent if additional information about one of them doesn’t change the distribution of the other.
One quick way to spot the lack of independence is to look at the set of possible values of the pair (X,Y). If that set is not a rectangle then X and Y can’t be independent. The non-rectangular shape implies that there must be two values of X for which the corresponding values of Y are different.
Answer
(iii)
from IPython.display import YouTubeVideo
YouTubeVideo('jVHgjZBMYq0')
Loading...
🎥 See More
Loading...
If the set of possible values is rectangular then you have to check independence using the old definition:
Jointly distributed random variables X and Y are independent if
P(X∈A,Y∈B)=P(X∈A)P(Y∈B)
for all intervals A and B.
Let X have density fX, let Y have density fY, and suppose X and Y are independent. Then if f is the joint density of X and Y,
Notice the circular symmetry of the surface. This is because the formula for the joint density involves the pair (x,y) through the expression x2+y2 which is symmetric in x and y.
Notice also that P(X=Y)=0, as the probability is the volume over a line. This is true of all pairs of independent random variables with a joint density: P(X=Y)=0. So for example P(X>Y)=P(X≥Y). You don’t have to worry about whether or not to the inequality should be strict.
Answer
f(x,y)=2π⋅21e−21⋅4x2⋅2π⋅31e−21⋅9y2
for all x,y
Let X and Y be independent random variables. Suppose X has the exponential (λ) distribution and Y has the exponential (μ) distribution. The goal of this example is to find P(Y>X).
By the product rule, the joint density of X and Y is given by
f(x,y)=λe−λxμe−μy,x>0,y>0
The graph below shows the joint density surface in the case λ=0.5 and μ=0.25, so that E(X)=2 and E(Y)=4.
To find P(Y>X) we must integrate the joint density over the upper triangle of the first quadrant, a portion of which is shown below.
# NO CODE
plt.axes().set_aspect('equal')
xx = np.arange(0, 10.1, 0.1)
yy = 10*np.ones(len(xx))
plt.fill_between(xx, xx, yy, alpha=0.3)
plt.xlabel('$x$')
plt.ylabel('$y$', rotation=0)
plt.title('$Y > X$ (portion of infinite region)');
The probability is therefore
P(Y>X)=∫0∞∫x∞λe−λxμe−μydydx
We can do this double integral without much calculus, just by using probability facts. As you calculate, try to involve densities as much as possible, and remember that the integral of a density over an interval is the probability of that interval.
P(Y>X)=∫0∞∫x∞λe−λxμe−μydydx=∫0∞λe−λx(∫x∞μe−μydy)dx=∫0∞λe−λxe−μxdx(survival function of Y, evaluated at x)=λ+μλ∫0∞(λ+μ)e−(λ+μ)xdx=λ+μλ(total integral of exponential (λ+μ) density is 1)
Thus
P(Y>X)=λ+μλ
Analogously,
P(X>Y)=λ+μμ
Notice that the two chances are proportional to the parameters. This is consistent with intuition if you think of X and Y as two lifetimes. If λ is large, the corresponding lifetime X is likely to be short, and therefore Y is likely to be larger than X as the formula implies.
If λ=μ then P(Y>X)=1/2 which you can see by symmetry since P(X=Y)=0.
Answer
(i)
Answer
2/3
If we had attempted the double integral in the other order – first x, then y – we would have had to do more work. The integral is
P(Y>X)=∫0∞∫0yλe−λxμe−μydxdy
Let’s take the easy way out by using SymPy to confirm that we will get the same answer.
# Create the symbols; they are all positive
x = Symbol('x', positive=True)
y = Symbol('y', positive=True)
lamda = Symbol('lamda', positive=True)
mu = Symbol('mu', positive=True)
# Construct the expression for the joint density
f_X = lamda * exp(-lamda * x)
f_Y = mu * exp(-mu * y)
joint_density = f_X * f_Y
joint_density
Loading...
# Display the integral – first x, then y
Integral(joint_density, (x, 0, y), (y, 0, oo))
Loading...
# Evaluate the integral
answer = Integral(joint_density, (x, 0, y), (y, 0, oo)).doit()
answer
Loading...
# Confirm that it is the same
# as what we got by integrating in the other order
simplify(answer)