# Confusion about calculating cdf and pdf of random variable

Let $$X$$ be a random variable with pdf: $$p_X(x)=\begin{cases} 1-|x| & x\in[-1,1] \\ 0 & \text{Otherwise} \end{cases}$$

Let $$Y$$ be $$Y=g(X)=\begin{cases} -X & x<0 \\ 2X & x\geq 0 \end{cases}$$ Find cdf and pdf of $$Y$$. This is my attempt: If $$0\leq y\leq 1$$, then $$\mathbb{P}(Y\leq y)=\mathbb{P}(-X\leq y)=\mathbb{P}(X\geq -y)=1-\mathbb{P}(X\leq -y)$$. Furthermore, $$\mathbb{P}(X\leq -y)=\int_{-1}^{-y}(1+x)dx=\dfrac{1}{2}-y+\dfrac{y^2}{2}$$, hence $$\mathbb{P}(Y\leq y)=\dfrac{1}{2}+y-\dfrac{y^2}{2}$$. On the other hand, $$\mathbb{P}(Y\leq y)=\mathbb{P}(2X\leq y)=\mathbb{P}(X\leq \dfrac{y}{2})=\int_0^{y/2}(1-x)dx=\dfrac{y}{2}-\dfrac{y^2}{8}$$. So, that would yield $$P_y(Y)=\begin{cases} \dfrac{1}{2}+\dfrac{3y}{2}-\dfrac{5y^2}{8} & y\in[0,1] \\ \dfrac{y}{2}-\dfrac{y^2}{8} & y\in(1,2] \\ 0 & \text{Otherwise} \end{cases}$$

Then, I can take the derivative and thus find the pdf. However, I have several problems, because there is a jump at $$y=0$$, namely $$P_y(0^-)=0$$, but $$P_y(0^+)=\dfrac{1}{2}$$; also $$P_y(1)=1.375$$, which doesn't make sense. I know I am doing something wrong, but I am not sure where or what. Could someone give me some hint? Thanks!

Edit: Since I know the pdf of $$Y$$ and I know that the cdf is just the integral and its value final value should be $$1$$, I calculated: $$P_y(Y)=\begin{cases} \dfrac{3y}{2}-\dfrac{5y^2}{8} & y\in[0,1] \\ \dfrac{1}{2}+\dfrac{y}{2}-\dfrac{y^2}{8} & y\in(1,2] \\ 0 & \text{Otherwise} \end{cases}$$

Everything seems to work, but I still can't "formally" get the cdf.

I didn't check your arithmetic, but I got different results, which are consistent.

$$P(Y\le y)=\frac{3y}{2}-\frac{5y^2}{8}$$ for $$0\le y\le 1$$.

$$P(Y\le y)=\frac{y}{2}-\frac{y^2}{8}+\frac{1}{2}$$ for $$1\le y\le 2)$$.

Note that it is continuous at $$y=1$$ where $$P=\frac{7}{8}$$ so getting density is no problem.

Derivation: $$Y\le 1$$, $$\int_{-y}^0(1-|x|)dx+\int_0^\frac{y}{2}(1-|x|)dx$$

$$1\le Y\le 2$$, $$\int_\frac{1}{2}^\frac{y}{2}(1-|x|)dx+\frac{7}{8}$$

• how did you get your results? I don't think my arithmetic has a problem. I think my problem is formulating the calculations. To get $P(Y\leq y)$ you must've calculated an integral for each of the cases, what integral was it? Commented Jan 19, 2021 at 22:58
• My original post had errors. These have been corrected and I added derivation integrals. Commented Jan 20, 2021 at 0:14

From the other direction: find the Y-pdf from the X-pdf, then integrate to obtain the Y-CDF

(NOTE: that is CDF for "Cumulative Distribution Function").

We have $$Y= -X\,\mathbf 1_{X<0}+ 2X\,\mathbf 1_{X\geqslant 0}$$ and $$p_{\small X}(x)=(1-\lvert x\rvert)\,\mathbf 1_{x\in[-1..1]}$$ , so using the Jacobian Transformation technique:

\begin{align}p_{\small Y}(y) &=p_{\small X}(-y)\left\lvert\dfrac{\mathrm d (-y)}{\mathrm d y}\right\rvert\mathbf 1_{y\in(0..1]}+p_{\small X}(y/2)\left\lvert\dfrac{\mathrm d (y/2)}{\mathrm d y}\right\rvert\mathbf 1_{y\in[0..2]}\\[2ex] &=(1-y)\mathbf 1_{y\in(0..1]}+\tfrac 12(1-y/2)\mathbf 1_{y\in[0..2]}\\[2ex]&=\frac {6-5y}4\mathbf 1_{y\in[0..1)}+\frac{2-y}4\mathbf 1_{x\in[1..2]}\\[4ex]F_{\small Y}(y) &=\int_0^y\dfrac{6-5t}{4}\,\mathrm d t\cdot\mathbf 1_{y\in[0..1)}\,+\left(\int_0^1\dfrac{6-5y}{4}\,\mathrm d t+\int_1^y\dfrac{2-y}{4}\,\mathrm d t\right)\mathbf 1_{y\in[1..2]} \\[2ex]&=\left[\dfrac{12t-5t^2}{8}\right]_{t=0}^{t=y}\mathbf 1_{y\in[0..1)}+\left(\left[\dfrac{12t-5t^2}{8}\right]_{t=0}^{t=1}+\left[\dfrac{4t-t}{8}\right]_{t=1}^{t=y}\right)\mathbf 1_{y\in[1..2)}+\mathbf 1_{y\in[2..\infty)}\\[2ex]&=\frac{12y-5y^2}{8}\mathbf 1_{y\in[0..1)}+\frac{4+4y-y^2}{8}\mathbf 1_{y\in[1..2)}+\mathbf 1_{y\in[2..\infty)}\end{align}

\begin{align}p_{\small Y}(y)&=\dfrac{\mathrm d ~~}{\mathrm d y}\left(\frac{12y-5y^2}{8}\mathbf 1_{y\in[0..1)}+\frac{4+4y-y^2}{8}\mathbf 1_{y\in[1..2)}+\mathbf 1_{y\in[2..\infty)}\right)\\[2ex]&=\dfrac{6-5y}{4}\mathbf 1_{y\in[0..1)}+\dfrac{2-y}{4}\mathbf 1_{y\in[1..2]}\end{align}