# PDF of function of X

I'm learning about functions of random variables and am trying to work out an example I made up. If $y = \sin(x)$ and $x$ has domain $[0, 4\pi]$, is the following the correct expression for the pdf of $y$: \begin{align*} f_Y(y) &= \frac{d}{dy}F_Y(y)\\ &= \frac{d}{dy}[F_X(2\pi) - F_X(\pi) + F_X(4\pi) - F_X(3\pi)]\\ &= \frac{d}{dx}F_X(2\pi)\left|\frac{dg^{-1}(y)}{dy}\right| - \frac{d}{dx}F_X(\pi)\left|\frac{dg^{-1}(y)}{dy}\right| + \frac{d}{dx}F_X(4\pi)\left|\frac{dg^{-1}(y)}{dy}\right| - \frac{d}{dx}F_X(3\pi)\left|\frac{dg^{-1}(y)}{dy}\right|\\ &=f_X(2\pi)\left|\frac{1}{\sqrt{1-0}}\right| - f_X(\pi)\left|\frac{1}{\sqrt{1-0}}\right| + f_X(4\pi)\left|\frac{1}{\sqrt{1-0}}\right| - f_X(3\pi)\left|\frac{1}{\sqrt{1-0}}\right|\\ &= f_X(2\pi) - f_X(\pi) + f_X(4\pi) - f_X(3\pi)\\ \end{align*}

• This is hopelessly and irretrievably incorrect from the second equation onwards. Have you given any thought to the fact that the quantity in square brackets on line 2 is not a function of $y$ at all, and so the derivative with respect to $y$ must be $0$ and not the gobbledygook that you have conjured up out of thin air? Feb 22 '15 at 17:18
• Thanks for your comment, @Dilip. I see $x = g^{-1}(y) = sin^{-1}(y)$. Although the question asks for $f_Y(y)$, I was looking at $f_Y(Y = 0)$ to simplify the intervals over which to write an expression for the CDF. I realize that this doesn't make sense either since the PDF at any one point is $0$. Drawing the picture, I see that for a particular $y$, we will have 0 (at $y = -1$), 1 (at $y = 1$), 2 (at $y = 0$), or 3 (other values of $y$) intervals over which we have to write an expression for the CDF. We can then differentiate this to get an expression for the PDF. Is this the right idea? Feb 22 '15 at 18:16

Draw a picture.

Although you can apply a standard formula for changes of variable, this one is tricky because the transformation $X\to Y$ is not one-to-one. Often the most convenient and reliable method is to compute the distribution function (CDF) and then differentiate it.

The distribution function of $Y=\sin(X)$ is, by definition,

$$F_Y(y) = \Pr(Y \le y) = \Pr(\sin(X) \le y) = \Pr(\{X\,|\, \sin(X) \le y\}).$$

The latter probability is with respect to $X$. The graph of $\sin$ has been emphasized where its height is less than or equal to $y$. The values of $X$ where this occurs, shown in thick blue along the axis, show the set $\{x\in[0,4\pi]\,|\, \sin(x) \le y\}$.

When $0 \lt y$, this set consists of three disjoint intervals $\newcommand{s}{\sin^{-1}y}[0, \s]$, $[\pi -\s, 2\pi + \s]$, and $[3\pi - \s, 4\pi]$. Because they are disjoint, the chance that $X$ lies within this union is the sum of the chances of each interval:

\eqalign{ \Pr(\sin(X) \le y) &= F_X(\s) - F_X(0) \\ &+ F_X(2\pi + \s) - F_X(\pi - \s)\\ &+1 - F(3\pi - \s). }

The value $1 = F_X(4\pi)$ appeared because the range of $X$ is $[0, 4\pi]$. However, we may not replace $F_X(0)$ by $0$ because possibly $X$ has nonzero probability there.

When $y \lt 0$, the set $\{X \in[0,4\pi]\,|\, \sin(X) \le y\}$ is the union of just two disjoint intervals:

By emulating the preceding argument, you should have no trouble writing down an expression for their probability in terms of $F_X$.

The PDF, when it exists, is the derivative of $F_Y$. In the first case

$$f_Y(y) = \frac{d}{dy} F_Y(y) = \frac{d}{dy}\left(F_X(\s) - F_X(0) + F_X(2\pi + \s) \cdots - F(3\pi - \s)\right).$$

Apply the Chain Rule, recognizing that $\frac{d}{dy}\s = 1/\sqrt{1-y^2}$:

$$f_Y(y) = \frac{1}{\sqrt{1-y^2}}\left(f_X(\s) + f_X(\pi-\s) + f_X(2\pi+\s) + f_X(3\pi-\s)\right)$$

This formula can be understood for all $y$ provided we replace $f_X(\s)$ by $f_X(4\pi + \s)$ whenever $y \lt 0$. Equivalently, and much more generally (with no restrictions on the range of $X$),

$$f_Y(y) = \frac{1}{\sqrt{1-y^2}}\sum_{i=-\infty}^\infty f_X(2i \pi + \s) + f_X((2i+1)\pi - \s).$$

• Fantastic, @whuber! Makes completely sense and is what I was hinting at in my comment to @DilipSarwate. Thank you! Feb 23 '15 at 23:41