# How to derive the distribution of a random variable as the absolute value of a uniform random variable

I'm trying to derive the distribution of a random variable $$Y$$ given that I know the distribution of a random variable $$X$$ and the relationship they share.

The $$pdf$$ of $$X$$ is expressed as:

$$f_{X} = \begin{cases} 1/3 & \text{if -2 < x < 1}\\ 0 & \text{otherwise} \end{cases}$$

I also know that $$Y = g(X) = |{X}|$$

In problems like this, I learned one must first calculate the $$CDF$$ of $$Y$$ and then derived in relation to $$y$$.

$$F_{Y}(y) = \mathbb{P}( Y \le y) = \mathbb{P}(|X| \leq y) = \mathbb{P}( X < y) + \mathbb{P}( X \geq -y)$$

Given that $$Y$$ is the absolute value of $$X$$, the inequality can be seen as the area of triangles (as far as I understand it).

But considering these are continuous random variables, I can't see how I'll integrate to find $$\mathbb{P}(.)$$

Here is a figure based on a simulation in R that suggests the answer. The simulation uses a million observations of $$X \sim \mathsf{Unif}(-2,1).$$ Then we show histograms of the samples of $$X$$ and of $$Y = |X|.$$

You have made a reasonable start on the formal derivation. Now, you need to express the right-hand side of the CDF of $$Y$$ as a function of $$y$$ and then take its derivative to get the PDF of $$Y.$$

 set.seed(2020)
x = runif(10^6, -2, 1)                  # simulate sample of X's
y = abs(x)                              # transform to get Y's
par(mfrow=c(1,2))                       # make histogram of X's and of Y's
hist(x, prob=T, br=12, col="skyblue2")
hist(y, prob=T, br=12, col="skyblue2")
par(mfrow=c(1,1)) The plots below (based on Empirical CDFs of the two samples) suggest the linear functions that make up the CDFs of $$X$$ and $$Y.$$ • This is an inventive solution, BruceET. Thank you. I was hoping for a more clear mathematical derivation. At least, the beginning of it so I could follow from there. =) – Mason Beau Mar 27 at 23:32