I have an interesting problem, i have seen in many text books ways of calculating conditional pdfs but not many where given a set of conditional pdfs for a variable we wish to calculate it's pdf. In particular i'm interested in problems with mixed types. As an example suppose the random variable $X$ takes values in the set $\{-2,2\}$ with equal probability. Given $X=x$ the random variable $Y \sim N(x,1)$. How can i generate the pdf for $Y$? My approach would be this.

To calculate the cdf $F_{Y}(y) = P(Y \leq y) = P(Y \leq y \cap X=-2) + P(Y \leq y \cap X=2) = P(Y \leq y|X=-2)P(X=-2)+P(Y \leq y|X=2)P(X=2)$.

Since i have the conditional cdf's i can calculate $F_{Y}(y)$. Once i have $F_{Y}(y)$ i can differentiate to calculate $f_{y}(y)$. Now i know there would be no analytical solution given that the conditional distribution of $Y$ is normal but is this approach the right way to go? Are there any other techniques commonly used?

  • $\begingroup$ I presented a solution for something like this some time back, only it was for a conditional distribution, but I think you'll find it helpful here as it applies: stats.stackexchange.com/questions/404102/… $\endgroup$ – StatsStudent May 14 '19 at 16:24
  • $\begingroup$ Thanks, which part exactly relates to this problem? Also is my solution a correct way of approaching it? $\endgroup$ – Iltl May 15 '19 at 8:40
  • 3
    $\begingroup$ $(X,Y)$ does not have a pdf. $Y$ does have a pdf and it's simple to write down in terms of elementary functions, leaving one to wonder what you might mean by "no analytical solution." $\endgroup$ – whuber May 22 '19 at 18:22
  • $\begingroup$ You are absolutely on the right track. $P(Y \leq y \cap X=\pm 2)$ is exactly $\Phi(y\pm 2)$ where $\Phi(\cdot)$ is the standard normal CDF (whose derivative is $\phi(\cdot)$, the standard normal pdf). This gives $$f_Y(y) =\left.\left. \frac 12\right[\phi(y-2)+\phi(y+2)\right]$$ which is the answer obtained by StatsStudent, but with a lot less effort and use of mistaken ideas such as the pdf of $(X,Y)$. As whuber's comment points out, $(X,Y)$ does not have a (joint) pdf. $\endgroup$ – Dilip Sarwate May 23 '19 at 3:16
  • $\begingroup$ @DilipSarwate what ideas do you see as "mistaken?" Genuinely hoping to learn. I'm also not sure this approach is any simpler -- you've just left out the mathematics, although, I could see how some might see this as more intuitive. By the way, I think your comment is good enough for an "answer." $\endgroup$ – StatsStudent May 23 '19 at 14:23

I think you are making this too complicated. You simply need to find:

\begin{eqnarray*} f_{Y}(y) & = & \int_{-\infty}^{\infty}f_{Y|X}(y|x)f_{X}(x)dx\\ & = & \int_{-\infty}^{\infty}f_{X,Y}(x,y)dx \end{eqnarray*}

if your goal is to obtain the PDF of $f_Y(y)$.

So in your case, you can start with:

\begin{eqnarray*} f_{X}(x) & = & \begin{cases} 1/2 & x=-2\\ 1/2 & x=2\\ 0 & otherwise \end{cases} \end{eqnarray*}


\begin{eqnarray*} f_{Y|X}(y|x) & = & \frac{1}{\sqrt{2\pi}}e^{-\frac{1}{2}(y-x)^{2}},\,y\in(-\infty,\infty);x={\{-2,2}\} \end{eqnarray*}

So, you can compute:

\begin{eqnarray*} f_{X,Y}(x,y) & = & f_{Y|X}(y|x)f_{X}(x)\\ & = & \begin{cases} \frac{1}{2\sqrt{2\pi}}e^{-\frac{1}{2}(y+2)^{2}} & x=-2,\,y\in(-\infty,\infty)\\ \frac{1}{2\sqrt{2\pi}}e^{-\frac{1}{2}(y-2)^{2}} & x=2,\,y\in(-\infty,\infty)\\ 0 & \text{otherwise} \end{cases} \end{eqnarray*}

Now, you can find the marginal PDF, $f_Y(y)$ over $y\in(-\infty,\infty)$ by "summing out" $X$: \begin{eqnarray*} f_{Y}(y) & = & \sum_{x=\{-1,2\}}f_{X,Y}(x,y)\\ & = & f_{X,Y}(-2,y)+f_{X,Y}(2,y)\\ & = & \frac{1}{2\sqrt{2\pi}}e^{-\frac{1}{2}(y+2)^{2}}+\frac{1}{2\sqrt{2\pi}}e^{-\frac{1}{2}(y-2)^{2}}\\ & = & \frac{1}{2}\left[\frac{1}{\sqrt{2\pi}}e^{-\frac{1}{2}[(y+2)-0]^{2}}+\frac{1}{\sqrt{2\pi}}e^{-\frac{1}{2}[(y-2)-0]^{2}}\right]\\ & = & \frac{1}{2}\left[\phi(y+2)+\phi(y-2)\right] \end{eqnarray*}

where $\phi(\cdot)$ is the PDF of a Standard Normal Random Variable.

  • 1
    $\begingroup$ can you actually mix pmfs and pdfs like this? What you describe as $f_{X}(x)$ isn't actually a probability density function. $\endgroup$ – Iltl May 22 '19 at 15:26
  • $\begingroup$ $f_X(x)$ here is a PMF. $f_{Y|X}(y|x)$ is a PDF. I think you'd benefit from a review of Section 8-3 of Carol Ash's "Probability Tutoring book." Specifically review Example 2: "First stage discrete, second stage continuous" and problem 3 in that section: bit.ly/30uEyYm. $\endgroup$ – StatsStudent May 22 '19 at 17:10
  • 2
    $\begingroup$ Errrrr No. Your mistake lies in the third line of the $f_Y(y)$ computation where you set $\exp(a) + \exp(b)$ to $\exp(a+b)$. The unconditional pdf of $Y$ is the two-humped camel $\left.\left. \frac 12 \right[\phi(y-2) + \phi(y+2)\right]$ (where $\phi(\cdot)$ is the standard normal pdf) and not what you have written. Put another way, $Y$ has a mixture pdf where the mixture is of two normal pdfs $N(2,1)$ and $N(-2,1)$ with equal weights. $\endgroup$ – Dilip Sarwate May 22 '19 at 18:12
  • 1
    $\begingroup$ haha, ugh. Yes, I totally messed up some very, very simple algebra (I blame my terrible handwriting ;-) ). I'll fix when back at my desk. Thanks for keeping me straight. The rest of the work previous to this step should still stand. Thanks, @DilipSarwate. I could have been more precise with my language: a mixture pdf indeed is the preferred term. $\endgroup$ – StatsStudent May 22 '19 at 18:32
  • 1
    $\begingroup$ Thanks for the link to the great book, do you have a copy with no missing pages? $\endgroup$ – Iltl May 23 '19 at 8:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.