Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

🎥 See More
Loading...

Let random variables XX and YY have the joint density defined by

f(x,y) = {30(yx)4,   0<x<y<10        otherwisef(x, y) ~ = ~ \begin{cases} 30(y-x)^4, ~~~ 0 < x < y < 1 \\ 0 ~~~~~~~~ \text{otherwise} \end{cases}
def jt_dens(x,y):
    if y < x:
        return 0
    else:
        return 30 * (y-x)**4

Plot_3d(x_limits=(0,1), y_limits=(0,1), f=jt_dens, cstride=4, rstride=4)
<Figure size 864x576 with 1 Axes>

Then the possible values of (X,Y)(X, Y) are in the upper right hand triangle of the unit square.

<matplotlib.figure.Figure at 0x1a0bd392e8>

Here is a quick check by SymPy to see that the function ff is indeed a joint density.

x = Symbol('x', positive=True)
y = Symbol('y', positive=True)

joint_density = 30*(y-x)**4
Integral(joint_density, (y, x, 1), (x, 0, 1)).doit()
Loading...

17.3.1Marginal Density of XX

We can use the joint density ff to find the density of XX. Call this density fXf_X. We know that

fX(x)dxP(Xdx)=yP(Xdx,Ydy)=yf(x,y)dxdy=(yf(x,y)dy)dx\begin{align*} f_X(x)dx &\sim P(X \in dx) \\ &= \int_y P(X \in dx, Y \in dy) \\ &= \int_y f(x, y)dxdy \\ &= \big( \int_y f(x, y)dy \big)dx \end{align*}

You can see the reasoning behind this calculation in the graph below. The blue strip shows the event {Xdx}\{ X \in dx \} for a value of xx very near 0.25. To find the volume P(Xdx)P(X \in dx), we hold xx fixed and add over all yy.

<matplotlib.figure.Figure at 0x1a13fd47b8>

So the density of XX is given by

fX(x) = yf(x,y)dy     for all xf_X(x) ~ = ~ \int_y f(x, y)dy ~~~~~ \text{for all } x

By analogy with the discrete case, fXf_X is sometimes called the marginal density of XX.

In our example, the possible values of (X,Y)(X, Y) are the upper left hand triangle as shown above. So for each fixed xx, the possible values of YY go from xx to 1.

Therefore for 0<x<10 < x < 1, the density of XX is given by

fX(x)=x130(yx)4dy=3015(yx)5x1=6(1x)5\begin{align*} f_X(x) &= \int_x^1 30(y-x)^4 dy \\ &= 30 \cdot \frac{1}{5} (y-x)^5 \Big\rvert_x^1 \\ &= 6(1-x)^5 \end{align*}

Here is the joint density surface again. You can see that XX is much more likely to be near 0 than near 1.

Plot_3d(x_limits=(0,1), y_limits=(0,1), f=jt_dens, cstride=4, rstride=4)
<Figure size 864x576 with 1 Axes>

That can be seen in the shape of the density of XX.

<Figure size 432x288 with 1 Axes>

17.3.2Density of YY

Correspondingly, the density of YY can be found by fixing yy and integrating over xx as follows:

fY(y)=xf(x,y)dx    for all yf_Y(y) = \int_x f(x, y)dx ~~~~ \text{for all } y

In our example, the joint density surface indicates that YY is more likely to be near 1 than near 0, which is confirmed by calculation. Remember that y>xy > x and therefore for each fixed yy, the possible values of xx are 0 through yy.

For 0<y<10 < y < 1,

fY(y) = 0y30(yx)4dx = 6y5f_Y(y) ~ = ~ \int_0^y 30(y-x)^4dx ~ = ~ 6y^5
<Figure size 432x288 with 1 Axes>
🎥 See More
Loading...

17.3.3Conditional Densities

Consider the conditional probability P(YdyXdx)P(Y \in dy \mid X \in dx). By the division rule,

P(YdyXdx) = P(Xdx,Ydy)P(Xdx) = f(x,y)dxdyfX(x)dx = f(x,y)fX(x)dyP(Y \in dy \mid X \in dx) ~ = ~ \frac{P(X \in dx, Y \in dy)}{P(X \in dx)} ~ = ~ \frac{f(x, y)dxdy}{f_X(x)dx} ~ = ~ \frac{f(x, y)}{f_X(x)} dy

This gives us a division rule for densities. For a fixed value xx, the conditional density of YY given X=xX=x is defined by

fYX=x(y) = f(x,y)fX(x)    for all yf_{Y\mid X=x} (y) ~ = ~ \frac{f(x, y)}{f_X(x)} ~~~~ \text{for all } y

Since XX has a density, we know that P(X=x)=0P(X = x) = 0 for all xx. But the ratio above is of densities, not probabilities. It might help your intuition to think of “given X=xX=x” to mean “given that XX is just around xx”.

Visually, the shape of this conditional density is the vertical cross section at xx of the joint density graph above. The numerator determines the shape, and the denominator is part of the constant that makes the density integrate to 1.

Note that xx is constant in this formula; it is the given value of XX. So the denominator fX(x)f_X(x) is the same for all the possible values of yy.

To see that the conditional density does integrate to 1, let’s do the integral.

yfYX=x(y)dy = yf(x,y)fX(x)dy = 1fX(x)yf(x,y)dy = 1fX(x)fX(x) = 1\int_y f_{Y\mid X=x} (y)dy ~ = ~ \int_y \frac{f(x, y)}{f_X(x)} dy ~ = ~ \frac{1}{f_X(x)} \int_y f(x, y)dy ~ = ~ \frac{1}{f_X(x)} f_X(x) ~ = ~ 1

In our example, let x=0.4x = 0.4 and consider finding the conditional density of YY given X=0.4X = 0.4. Under that condition, the possible values of YY are in the range 0.4 to 1, and therefore

fYX=0.4(y)=30(y0.4)46(10.4)5=50.65(y0.4)4      y(0.4,1)f_{Y \mid X=0.4} (y) = \frac{30(y - 0.4)^4}{6(1 - 0.4)^5} = \frac{5}{0.6^5} (y - 0.4)^4 \;\;\; y \in (0.4, 1)

This is a density on (0.4,1)(0.4, 1):

y = Symbol('y', positive=True)

conditional_density_Y_given_X_is_04 = (5/(0.6**5)) * (y - 0.4)**4

Integral(conditional_density_Y_given_X_is_04, (y, 0.4, 1)).doit()
Loading...

The figure below shows the overlaid graphs of the density of YY and the conditional density of YY given X=0.4X = 0.4. You can see that the conditional density is more concentrated on large values of YY, because under the condition X=0.4X = 0.4 you know that YY can’t be small.

<Figure size 432x288 with 1 Axes>

17.3.4Using a Conditional Density

We can use conditional densities to find probabilities and expectations, just as we would use an ordinary density. Here are some examples of calculations. In each case we will set up the integrals and then use SymPy.

P(Y>0.9X=0.4)=0.9150.65(y0.4)4dyP(Y > 0.9 \mid X = 0.4) = \int_{0.9}^1 \frac{5}{0.6^5} (y - 0.4)^4 dy

The answer is about 60%.

Integral(conditional_density_Y_given_X_is_04, (y, 0.9, 1)).doit()
Loading...

Now we will use the conditional density to find a conditional expectation. Remember that in our example, given that X=0.4X = 0.4 the possible values of YY go from 0.4 to 1.

E(YX=0.4) = 0.41y50.65(y0.4)4dy = 0.9E(Y \mid X = 0.4) ~ = ~ \int_{0.4}^1 y \frac{5}{0.6^5} (y - 0.4)^4 dy ~ = ~ 0.9
Integral(y*conditional_density_Y_given_X_is_04, (y, 0.4, 1)).doit()
Loading...

You can condition XX on YY in the same way. By analogous arguments, for any fixed value of yy the conditional density of XX given Y=yY = y is

fXY=y(x)=f(x,y)fY(y)      for all xf_{X \mid Y=y} (x) = \frac{f(x, y)}{f_Y(y)} \;\;\; \text{for all } x

All the examples in this section and the previous one have started with a joint density function that apparently emerged out of nowhere. In the next section, we will study a context in which they arise.