# If $X \sim$ unif$(0,1)$, what is the distribution of $U=\max \{X,1-X \}$?

Let $X$ be uniformly distributed in $(0,1)$ and set $U=\max \{X, 1-X\}$. How can I find the distributiopn of $U$?

My first thought was to consider this a mixture distribution problem and use the CDF technique as follows:

$$F_U (u)= P\left( U \leq u \right)=P\left( U \leq u , U=X \right) +P\left(U \leq u, U=1-X \right)$$

and then proceed accordingly.

That approach turns out to be incorrect but I do not quite understand why.

I would be grateful therefore if someone could firstly point out the gap in my syllogism above and then present an appropriate way to deal with this kind of problems.'

Thank you.

• I don't see anything wrong. You can write $U=X$ as $X < 1-X$ i.e. $X<\frac12$ and contiinue... – Stéphane Laurent Jul 26 '14 at 14:20
• @StéphaneLaurent Yes, I thought so too but the distribution of $U$ turns out to be uniform on $(0,1)$ this way. The correct answer though is uniform on $(0.5,1)$. – JohnK Jul 26 '14 at 14:22
• @StéphaneLaurent Isn't it $P(U \leq u, U=X)= F_X(u) \times P(X \geq 1-X)$? – JohnK Jul 26 '14 at 14:33
• No. You have to express the event in terms of $X$ only: note that $P(U\leq u, U=X) = P(X \leq u, X>\frac12)$, and you easily have the value of this probability by considering separately the cases $u\leq \frac12$ and $u>\frac12$. – Stéphane Laurent Jul 26 '14 at 15:08
• @StéphaneLaurent That was subtle, thank you. I hadn't realized this works only for events concerning $X$. Feel free to post this as an answer, so I can mark it as the correct one. – JohnK Jul 26 '14 at 15:18

$U$ is not a mixture of $X$ and $1-X$ because they are not independent.

One general way to deal with such problems, when a random variable $X$ is transformed according to some definite procedure into another random variable $U$, is to compute the cumulative distribution function (CDF) of $U$. To illustrate, let's do that with this example.

The first step is to find the support of the new variable: what values can it take on? Because almost surely $X\in [0,1]$, we compute that $U\in [1/2,1]$. An easy way to carry out this calculation is to plot the graph of $u = \max(x, 1-x)$ for $0\le x\le 1$ and inspect the range of heights it attains.

The range of this graph spans all $u$ values between $1/2$ and $1$: those are the ones for which the CDF must be calculated.

The second step is to compute the CDF for arguments in the support. This usually proceeds in two stages.

1. Substitute a function of $X$ in place of $U$. The CDF of $U$ for $u\in[1/2,1]$ is, by definition,

$$F_U(u) = \Pr(U \le u) = \Pr(\max(X, 1-X)\le u).$$

2. Evaluate the chance of the resulting event. This usually requires some algebraic manipulation but often does not require any use of probability or Calculus. Here

$$\{x \big| x\le u, 1-x\le u\} = \{x \big|1-u \le x\le u\} = [1-u, u].$$

Putting these two results together (plugging (2) into (1)) yields

$$F_U(u) = \Pr(X\in [1-u,u]) = F_X(u) - F_X(1-u) = u-(1-u) = 2u-1.$$

In some tricky cases (where $U$ has neither a continuous nor an entirely discrete distribution) it is important to evaluate the CDF at all real numbers. (An example is worked out at Distribution function of maximum of n iid standard uniform random variables....) In the present case, because the values just computed for $F_U(u)$ range from $0$ at $u=1/2$ through $1$ at $u=1$ and any CDF must be a nondecreasing function, the remaining values of $F_U$ are completely determined: $F_U(u)=1$ for $u\gt 1$ and $F_U(u)=0$ for $u\lt 1/2$.

The job is done. In many circumstances the resulting distribution might not be recognizable, but this one evidently is the CDF of a Uniform$(1/2,1)$ distribution.

• Wonderful! Thank you very much for this great answer. – JohnK Jul 26 '14 at 15:27

$U=\max{\left(X,1-X\right)} \sim \mathcal{U}(0.5,1)$

Because if $X > 1-X$ (i.e. if $X > 0.5$), then $U \sim \mathcal{U}\left(0.5,1\right)$, and
if $1-X > X$ (i.e. if $1-X > 0.5$), then $U \sim \mathcal{U}\left(0.5,1\right)$ also.

Plus, simulation:

X<-runif(100000)
U<-pmax(X,1-X)
hist(U)

• Thank you. Yes I understand why the correct answer is uniform on $(0.5,1)$. I do not understand though why my approach is incorrect. – JohnK Jul 26 '14 at 14:31
• I think $P(U≤u,U=X) = 0$ when $U\ne X$ and $P(U≤u,U=1-X)=0$ when $U \ne 1-X$, so I do not see the error. What error are you seeing? – Alexis Jul 26 '14 at 14:33
• Why are these probabilities zero? I have been using the fact that: $P(U \leq u, U=X)= F_X(u) \times P(X \geq 1-X)$ – JohnK Jul 26 '14 at 14:37
• Just musing. . . (sans caffeine, just woke up :). – Alexis Jul 26 '14 at 14:39
• Well good morning, lol. – JohnK Jul 26 '14 at 14:40