# The mean of a continuous random variable that has a discontinuity in its density

Consider U(0, b). I shift up the density the segment from [0, 0.2*b) to contain probability 0.8, and shift down the density in segment from [0.2*b, b] to contain probability 0.2.

I know that the mean will be in the segment [0, 0.2*b) because at least 50% is under the curve there. I compute the c.d.f.

$$\int_0^x \! \frac{0.8}{0.2\times b} \, \mathrm{d} x. = \frac{4\times x}{b}$$

and set it equal to 0.5 (which is where the mean is).

$$\frac{4\times x}{b} = 0.5$$ $$x = 1/8 \times b$$

1. Is this approach correct? I'm not sure if I'm calculating the median or mean. If not, please suggest an alternative. Can I simply calculate first moments of each segment and then add ALL the integrals together? EDIT: RESOLVED: Its the latter.
2. In the case where the first segment does not contain the mean, I subtract the area under the curve in the first segment from 0.5. Then, use the c.d.f. of the next segment and set it equal to that difference and solve for x to get the mean? Or is there a more elegant way to do this?EDIT: RESOLVED:
3. Somehow related: If I take the probability distribution of any random variable and shift around density (cont.) or weight (discrete) at arbitrary intervals and points around, does the variance stay the same? My intuition tells me yes, because the mean remains unchanged and the dispersion at each value in the support does not get lost.
-
"I know that the mean will be in ..... because at least 50% is under the curve there." Be careful about assertions such as these. For an exponential density $f(x) = \exp(-x)$ for $x \geq 0$, the mean is $1$, but more than $1-e^{-1} > 63\%$ of the area under the curveis to the left of the mean. – Dilip Sarwate Oct 30 '12 at 4:10

As your post indicates, you know that our changed density function $g(x)$ is given by $g(x)=\dfrac{4}{b}$ on the interval $[0,0.2b]$, $g(x)=\dfrac{1}{4b}$ on the interval $[0.2b, b]$, and $g(x)=0$ elsewhere. The value of the density function can be changed at a point, or a finite number of points, without changing any probabilities.
You calculated the median, not the mean. The mean is equal to $$\int_0^b xg(x)\,dx.$$ To evaluate the integral, we split it into two parts. So the mean is $$\int_0^{0.2b} \frac{4x}{b}\,dx+\int_{0.2b}^b \frac{x}{4b}\,dx.$$ The integrations are straighforward. I believe that the answer is $0.28b$. The mean is rather far from the median, because of the long "tail."