# How does one calculate moments from discontinuous distributions?

Consider U(0,1), and lets shift down the density downwards (from the original 1) in the interval [0, U], and to balance it out, shift the density upwards (from the original 1) in the interval [U, 1] - call this new discontinuous random variable $D$ **. My intuition is unclear on whether variance increases. How can I calculate the second moment in this new distribution? Do I simply integrate $x^2*density1$ over [0, U] and add to that the integration of $x^2*density2$ over [U, 1]?

Furthermore, what if I'm interested in the overall standard deviation of $D$ PLUS another, independent, random variable Q. Do I just add the standard deviation of the previous R.V. $U$ (easily obtained by sqrt(secondMoment-0.5^2) PLUS the standard deviation of the standard deviation of $Q$?

SD(D+Q) ?= SD(D) + SD(Q)

**Or, maybe we can get even more sophisticated (I'm not familiar with real analysis) and shift up the density at a set of random disjoint real numbers in the interval [0,1] and shift down the rest (maybe every alternating real number is shifted in the opposite direction in the density: 1/2, 1.5, 1/2, 1.5,...).

-

Your description is not the clearest possible, but on the your first question, the answer is yes, since if the density is $p(x)$ the second moment about $0$ is still $$\int x^2 p(x) dx$$ which in the case you describe is $$\int_0^U x^2 p_1 dx + \int_U^1 x^2 p_2 dx$$ with $p(x)$ taking the different values $p_1$ and $p_2$ in the two intervals. You can easily extend this to your ** example or to other more complicated cases.
For a random variable made up of the sum of two independent random variables, you should not sum the standard deviations but the variances so $$Var(D+Q)=Var(D)+Var(Q).$$
You would typically only be justified in summing the standard deviations if there was a linear relationship between the two random variables, such as $Q=a+bD$, or if one of the standard deviations was zero.
Thanks for your answer. In my ** example, if we select a subset of size U to shift up to $p_2$; the points are randomly selected in the interval [0,1] and can be disjoint (the complement of size 1-U in the same interval is changed to $p_1$, is the variance unchanged from Var(U(0,1))=1/12 or is it increased? – Wuschelbeutel Kartoffelhuhn Oct 26 '12 at 5:39