# Computing directly the pdf of $Y=X^2$ for the pdf $f_X(x) = \frac{2}{9}(x+1)$

In the book Statistical inference by Casella and Berger, given that the pdf of X is $f_X(x) = \frac{2}{9}(x+1)$ for $-1 \le x \le 2$, we want to find the pdf of $Y=X^2$. But it says we are not able to directly use the theorem 2.1.8 which is

Theorem 2.1.8 Let $X$ have pdf $f_X(x)$ and let $Y=g(X)$. Suppose there exists a partition, $A_0, A_1, \dots A_k$ of $\cal{X}$ such that $P(X \in A_0)=0$ and $f_X(x)$ is continuous on each $A_i$. Further, suppose there exist functions $g_1(x), ..., g_k(x)$ defined on $A_1, ..., A_k$ respectively, satisfying

i. $g(x) = g_i(x)$ for $x\in A_i$

ii. $g_i(x)$ is monotone on $A_i$

iii. the set $\cal{Y} = \{y: y=g_i(x) \mathrm{\ for\ some\ } x \in A_i \}$ is the same for each $i=1, ..., k$

iv. $g_i^{-1}(y)$ has a continuous derivative on $\cal{Y}$ for each $i=1,...,k$.

Then, for $y \in \cal{Y}$, $$f_Y(y) = \sum^k_{i=1} f_X(g_i^{-1}(y)) \left|{d \over dy} g_i^{-1}(y) \right|$$

The $f_X(x)$ in question seems to satisfy all conditions: $f_X(x)$ is a monotonically increasing function, so we can create partitions so that $-1 \le x \le 0$ is $A_1$, $0 < x \le 2$ be $A_2$ and the rest $A_0$. Why can't we directly apply this theorem?

EDIT: it seems like the third condition does not hold. But can we find a partition that meets the third condition? Is there a way to know that whether such partition exists?

EDIT 2: By simply doing what @Dilip suggested me, I get

\begin{align} F_Y(y) &= P(Y \le y) \\ &= P(X^2 \le y) \\ &= P(-\sqrt{y} \le X \le \sqrt{y}) \\ &= P(-\sqrt{y} < X \le \sqrt{y}) \\ &= F_X(\sqrt{y}) - F_X(-\sqrt{y}) \\ f_Y(y) &= { d \over dy} F_Y(y) \\ &= {1 \over 2\sqrt{y}}f_x(\sqrt{y}) + {1 \over 2\sqrt{y}} f_X(-\sqrt{y}) \end{align} If I plug in $f_X(x)$, I get ${2 \over 9\sqrt{y}}$ which is correct only when $y \le 1$. How do I know that I need to separate the range into two subsets?

• Instead of all the gobbledygook of the theorem, why not just apply the simple result that for $y\geq 0$, $F_Y(y)$ equals the probability of the event $X \in [-\sqrt y, \sqrt y]$ and differentiate to find $f_Y(y)$ in terms of $f_X(x)$? You will get precisely that vaunted formula, with two terms in it for $y\in [0,1]$ and one term for $y \in (1,2]$. – Dilip Sarwate Mar 18 '18 at 15:04
• @DilipSarwate how do i know that $y$ must be separated into two terms $y \in [0,1]$ and $y \in (1,2]$? – MoneyBall Mar 19 '18 at 1:50
• " How do I know that I need to separate the range into two subsets?" That is exactly the case of not being able to apply the theorem directly. When 'multiple X -> single Y' then the theorem allows you to compute the pdf of Y by partitioning X into cases of 'single X_i -> single Y' but they need to be the same domain. X from -1 to 0 and X from 0 to 2 have Y from 0 to 1 and Y from 0 to 4. – Sextus Empiricus Mar 19 '18 at 6:17
• How to know this case occurs the theorem does not tell. It starts after you did the work to figure this out (e.g. looking at the plot selecting subdomains of X with same image of Y) "suppose there exist a partition..." – Sextus Empiricus Mar 19 '18 at 6:22
• The resolution when you "plug in $f_X(x)$" is incorrect as you forget the indicator function in$$f_X(x)=\frac{2}{9}(1+x)\mathbb{I}_{(-1,2)}(x)$$(See my own answer.) – Xi'an Mar 19 '18 at 6:29

The third condition is important in that \begin{align*} \mathbb{P}(Y\in B) &= \int_B f_Y(y)\text{d}y\\ &= \mathbb{P}(g(X)\in B)\\ &= \sum_{i=1}^k \mathbb{P}(g(X)\in B,\,X\in A_i)\\ &= \sum_{i=1}^k \mathbb{P}(g_i(X)\in B,\,X\in A_i)\\ &= \sum_{i=1}^k \mathbb{P}(X\in g_i^{-1}(B)\cap A_i)\\ &= \sum_{i=1}^k \int_{g_i(g_i^{-1}(B)\cap A_i)} f_X\{g_i^{-1}(y)\}\left|{d \over dy} g_i^{-1}(y) \right|\text{d}y\\ \end{align*} and hence one needs to have $$g_i(g_i^{-1}(B)\cap A_i)=B\cap\cal{Y}$$ for $i=1,2,\ldots,k$ in order for the formula from Statistical Inference to hold. Otherwise, additional indicator functions are necessary.

The alternative suggested by Dilip Sarwate in his comment does not require the same condition: \begin{align} F_Y(y) &= \mathbb{P}(Y\le y)\\ &= \mathbb{P}(g(X)\le y)&\quad\text{[definition]}\\ &= \mathbb{P}(g(X)\in (0,y))\\ &=\sum_{i=1}^k \mathbb{P}(g(X)\in (0,y),\,X\in A_i)&\quad\text{[partition]}\\ &=\sum_{i=1}^k \mathbb{P}(g_i(X)\in (0,y),\,X\in A_i)&\quad\text{[specialisation]}\\ &=\sum_{i=1}^k \mathbb{P}(X\in g_i^{-1}\{(0,y)\},\,X\in A_i)&\quad\text{[invertibility]}\\ &=\sum_{i=1}^k \left|\int_{0}^{g_i^{-1}(y)} f_X(x)\mathbb{I}_{A_i}(x)\text{d}x\right|&\quad\text{[monotonicity]}\\ &=\sum_{i=1}^k \underbrace{\xi_i\int_{0}^{g_i^{-1}(y)} f_X(x)\mathbb{I}_{A_i}(x)\text{d}x}_{\xi_i\text{ is monotonicity of }g_i}\\ &=\int_0^y f_Y(\omega)\text{d}\omega \end{align} leading to
\begin{align}f_Y(y) &= \sum_{i=1}^k \xi_i f_X\{g_i^{-1}(y)\}\,{d \over dy} g_i^{-1}(y) \,\mathbb{I}_{A_i}\{g_i^{-1}(y)\}\\&=\sum_{i=1}^k f_X\{g_i^{-1}(y)\}\left|{d \over dy} g_i^{-1}(y) \right|\,\mathbb{I}_{A_i}\{g_i^{-1}(y)\}\end{align} In the example, $A_1=(-1,0)$ and $A_2=(0,2)$, $g_1(x)=g_2(x)=x^2$: $$f_Y(y)=\frac{2}{9}\frac{1}{2\sqrt{y}}(1-\sqrt{y})\mathbb{I}_{(-1,0)}(-\sqrt{y})+\frac{2}{9}\frac{1}{2\sqrt{y}}(1+\sqrt{y})\mathbb{I}_{(0,2)}(\sqrt{y})$$ which simplifies into $$\frac{2}{9\sqrt{y}}\mathbb{I}_{(0,1)}(y)+\frac{1}{9\sqrt{y}}(1+\sqrt{y})\mathbb{I}_{(1,4)}(y)$$

• is it because $Y=X^2$? If so, is there a way to generalize it without assuming $Y=X^2$? – MoneyBall Mar 19 '18 at 10:07
• In the general case, replace $0$ with $-\infty$. – Xi'an Mar 19 '18 at 10:13

The third condition fails.

$2^2=4$ is in the image of $\mathcal{A}_2$ but it is not in the image of $\mathcal{A}_1$.

Remark: Question has been changed.

• the third condition is what confuses me the most. Does that mean every partition must have the same image? – MoneyBall Mar 18 '18 at 7:51
• but then if we set $A_1$ to be in $-2 \le x < 0$ and $A_2$ to be in $0 < x \le 2$, wouldn't they be the same? – MoneyBall Mar 18 '18 at 7:53
• $\mathcal{X}=\{x: f_X(x)>0\}$ and $\mathcal{A}_0, \ldots, \mathcal{A}_k$ is a partition of $\mathcal{X}$. $[-2,-1]$ can't be included. – Siong Thye Goh Mar 18 '18 at 8:11
• so you're saying these partitions can only exist for $x$ such that their probabilities are greater than 0, and all partitions must have the same image. – MoneyBall Mar 18 '18 at 9:06
• yes, condition $3$ means same image. and the positive density is due to equation $(2.7.1)$. Note that these are just sufficient conditions and not necessary conditions. – Siong Thye Goh Mar 18 '18 at 17:10

To provide an alternative series of steps to arrive at the density of $Y$, using the "distribution function" method as @Xi'an answer does, we have

$$P(Y \leq y) = P(X^2 \leq y)$$

For the support of $X \in [-1,1]$ we have

$$P(X^2 \leq y) = P(-\sqrt{y}\leq X \leq \sqrt{y}), \;\;\; X \in [-1,1]$$

For $X\geq 1$ we have

$$P(X^2 \leq y) = \{P(X \leq \sqrt{y}),\;\;\;X\geq 1\} = P(1\leq X \leq \sqrt {y})$$

Combining,

$$P(Y\leq y) = \cases {\int_{-\sqrt{y}}^{\sqrt{y}}f_X(x)dx\;\;\; |x|\leq 1 \\ \\ \int_1^{\sqrt{y}}f_X(x)dx\;\;\; x\geq 1} \\$$

Differentiating with respect to $y$ leads to @Xi'an final result. The upper branch corresponds to $y \in [0,1]$ and the lower branch to $y \in [1,4]$