# Variance of a bounded random variable

Suppose that a random variable has a lower and an upper bound [0,1]. How to compute the variance of such a variable?

• The same way as for an unbounded variable - setting integration or summation limits appropriately. Dec 10, 2012 at 13:46
• As @Scortchi said. But I'm curious why you thought it might be different? Dec 10, 2012 at 14:09
• Unless you don't know anything about the variable (in which case an upper bound on variance might be calculated from the existence of bounds), why would the fact that it's bounded come into the calculation? Dec 10, 2012 at 22:15
• A useful upper bound on the variance of a random variable that takes on values in $[a,b]$ with probability $1$ is $(b-a)^2/4$ and is achieved by a discrete random variable that takes on values $a$ and $b$ with equal probability $\frac{1}{2}$. Another point to keep in mind is that the variance is guaranteed to exist whereas an unbounded random variable might not have a variance (some, such as Cauchy random variables don't even have a mean). Dec 11, 2012 at 17:44
• There is a discrete random variable whose variance equals $\frac{(b-a)^2}{4}$ exactly: a random variable that takes on values $a$ and $b$ with equal probability $\frac{1}{2}$. So, at least we know that a universal upper bound on the variance cannot be smaller than $\frac{(b-a)^2}{4}$. Feb 21, 2013 at 18:01

You can prove Popoviciu's inequality as follows. Use the notation $$m=\inf X$$ and $$M=\sup X$$. Define a function $$g$$ by $$g(t)=\mathbb{E}\left[\left(X-t\right)^2\right] \, .$$ Computing the derivative $$g'$$, and solving $$g'(t) = -2\mathbb{E}[X] +2t=0 \, ,$$ we find that $$g$$ achieves its minimum at $$t=\mathbb{E}[X]$$ (note that $$g''>0$$).

Now, consider the value of the function $$g$$ at the special point $$t=\frac{M+m}{2}$$. It must be the case that $$\mathbb{Var}[X]=g(\mathbb{E}[X])\leq g\left(\frac{M+m}{2}\right) \, .$$ But $$g\left(\frac{M+m}{2}\right) = \mathbb{E}\left[\left(X - \frac{M+m}{2}\right)^2 \right] = \frac{1}{4}\mathbb{E}\left[\left((X-m) + (X-M)\right)^2 \right] \, .$$ Since $$X-m\geq 0$$ and $$X-M\leq 0$$, we have $$\left((X-m)+(X-M)\right)^2\leq\left((X-m)-(X-M)\right)^2=\left(M-m\right)^2 \, ,$$ implying that $$\frac{1}{4}\mathbb{E}\left[\left((X-m) + (X-M)\right)^2 \right] \leq \frac{1}{4}\mathbb{E}\left[\left((X-m) - (X-M)\right)^2 \right] = \frac{(M-m)^2}{4} \, .$$ Therefore, we proved Popoviciu's inequality $$\mathbb{Var}[X]\leq \frac{(M-m)^2}{4} \, .$$

• Nice approach: it's good to see rigorous demonstrations of these kinds of things.
– whuber
Feb 21, 2013 at 18:00
• +1 Nice! I learned statistics long before computers were in vogue, and one idea that was drilled into us was that $$E[(X-t)^2] = E[((X-\mu)-(t-\mu))^2] = E[(X-\mu)^2]+(t-\mu)^2$$ which allowed for the computation of variance by finding the sum of the squares of the deviations from any convenient point $t$ and then adjusting for the bias. Here of course, this identity gives a simple proof of the result that $g(t)$ has minimum value at $t=\mu$ without the necessity of derivatives etc. Feb 21, 2013 at 22:22

If the random variable is restricted to $[a,b]$ and we know the mean $\mu=E[X]$, the variance is bounded by $(b-\mu)(\mu-a)$.

Let us first consider the case $a=0, b=1$. Note that for all $x\in [0,1]$, $x^2\leq x$, wherefore also $E[X^2]\leq E[X]$. Using this result, $$\sigma^2 = E[X^2] - (E[X]^2) = E[X^2] - \mu^2 \leq \mu - \mu^2 = \mu(1-\mu).$$

To generalize to intervals $[a,b]$ with $b>a$, consider $Y$ restricted to $[a,b]$. Define $X=\frac{Y-a}{b-a}$, which is restricted in $[0,1]$. Equivalently, $Y = (b-a)X + a$, and thus $$Var[Y] = (b-a)^2Var[X] \leq (b-a)^2\mu_X (1-\mu_X).$$ where the inequality is based on the first result. Now, by substituting $\mu_X = \frac{\mu_Y - a}{b-a}$, the bound equals $$(b-a)^2\, \frac{\mu_Y - a}{b-a}\,\left(1- \frac{\mu_Y - a}{b-a}\right) = (b-a)^2 \frac{\mu_Y -a}{b-a}\,\frac{b - \mu_Y}{b-a} = (\mu_Y - a)(b- \mu_Y),$$ which is the desired result.

Let $F$ be a distribution on $[0,1]$. We will show that if the variance of $F$ is maximal, then $F$ can have no support in the interior, from which it follows that $F$ is Bernoulli and the rest is trivial.

As a matter of notation, let $\mu_k = \int_0^1 x^k dF(x)$ be the $k$th raw moment of $F$ (and, as usual, we write $\mu = \mu_1$ and $\sigma^2 = \mu_2 - \mu^2$ for the variance).

We know $F$ does not have all its support at one point (the variance is minimal in that case). Among other things, this implies $\mu$ lies strictly between $0$ and $1$. In order to argue by contradiction, suppose there is some measurable subset $I$ in the interior $(0,1)$ for which $F(I)\gt 0$. Without any loss of generality we may assume (by changing $X$ to $1-X$ if need be) that $F(J = I \cap (0, \mu]) \gt 0$: in other words, $J$ is obtained by cutting off any part of $I$ above the mean and $J$ has positive probability.

Let us alter $F$ to $F'$ by taking all the probability out of $J$ and placing it at $0$. In so doing, $\mu_k$ changes to

$$\mu'_k = \mu_k - \int_J x^k dF(x).$$

As a matter of notation, let us write $[g(x)] = \int_J g(x) dF(x)$ for such integrals, whence

$$\mu'_2 = \mu_2 - [x^2], \quad \mu' = \mu - [x].$$

Calculate

$$\sigma'^2 = \mu'_2 - \mu'^2 = \mu_2 - [x^2] - (\mu - [x])^2 = \sigma^2 + \left((\mu[x] - [x^2]) + (\mu[x] - [x]^2)\right).$$

The second term on the right, $(\mu[x] - [x]^2)$, is non-negative because $\mu \ge x$ everywhere on $J$. The first term on the right can be rewritten

$$\mu[x] - [x^2] = \mu(1 - [1]) + ([\mu][x] - [x^2]).$$

The first term on the right is strictly positive because (a) $\mu \gt 0$ and (b) $[1] = F(J) \lt 1$ because we assumed $F$ is not concentrated at a point. The second term is non-negative because it can be rewritten as $[(\mu-x)(x)]$ and this integrand is nonnegative from the assumptions $\mu \ge x$ on $J$ and $0 \le x \le 1$. It follows that $\sigma'^2 - \sigma^2 \gt 0$.

We have just shown that under our assumptions, changing $F$ to $F'$ strictly increases its variance. The only way this cannot happen, then, is when all the probability of $F'$ is concentrated at the endpoints $0$ and $1$, with (say) values $1-p$ and $p$, respectively. Its variance is easily calculated to equal $p(1-p)$ which is maximal when $p=1/2$ and equals $1/4$ there.

Now when $F$ is a distribution on $[a,b]$, we recenter and rescale it to a distribution on $[0,1]$. The recentering does not change the variance whereas the rescaling divides it by $(b-a)^2$. Thus an $F$ with maximal variance on $[a,b]$ corresponds to the distribution with maximal variance on $[0,1]$: it therefore is a Bernoulli$(1/2)$ distribution rescaled and translated to $[a,b]$ having variance $(b-a)^2/4$, QED.

• Interesting, whuber. I didn't know this proof.
– Zen
Feb 21, 2013 at 18:01
• @Zen It's by no means as elegant as yours. I offered it because I have found myself over the years thinking in this way when confronted with much more complicated distributional inequalities: I ask how the probability can be shifted around in order to make the inequality more extreme. As an intuitive heuristic it's useful. By using approaches like the one laid out here, I suspect a general theory for proving a large class of such inequalities could be derived, with a kind of hybrid flavor of the Calculus of Variations and (finite dimensional) Lagrange multiplier techniques.
– whuber
Feb 21, 2013 at 18:04
• Perfect: your answer is important because it describes a more general technique that can be used to handle many other cases.
– Zen
Feb 21, 2013 at 18:06
• @whuber said - "I ask how the probability can be shifted around in order to make the inequality more extreme." -- this seems to be the natural way to think about such problems. Feb 21, 2013 at 23:40
• There appear to be a few mistakes in the derivation. It should be $$\mu[x] - [x^2] = \mu(1 - [1])[x] + ([\mu][x] - [x^2]).$$ Also, $[(\mu-x)(x)]$ does not equal $[\mu][x] - [x^2]$ since $[\mu][x]$ is not the same as $\mu[x]$
– Leo
Aug 8, 2013 at 12:12

At @user603's request....

A useful upper bound on the variance $\sigma^2$ of a random variable that takes on values in $[a,b]$ with probability $1$ is $\sigma^2 \leq \frac{(b−a)^2}{4}$. A proof for the special case $a=0, b=1$ (which is what the OP asked about) can be found here on math.SE, and it is easily adapted to the more general case. As noted in my comment above and also in the answer referenced herein, a discrete random variable that takes on values $a$ and $b$ with equal probability $\frac{1}{2}$ has variance $\frac{(b−a)^2}{4}$ and thus no tighter general bound can be found.

Another point to keep in mind is that a bounded random variable has finite variance, whereas for an unbounded random variable, the variance might not be finite, and in some cases might not even be definable. For example, the mean cannot be defined for Cauchy random variables, and so one cannot define the variance (as the expectation of the squared deviation from the mean).

• this is a special case of @Juho's answer Apr 11, 2014 at 20:00
• It was just a comment, but I could also add that this answer does not answer the question asked. Apr 11, 2014 at 20:05
• @Aksakal So??? Juho was answering a slightly different and much more recently asked question. This new question has been merged with the one you see above, which I answered ten months ago. Apr 11, 2014 at 20:07

Given random variable $$D$$ with mean $$E D=\mu$$, when $$a\le D\le b$$, we have $$\begin{eqnarray*} E (D-\mu)^2&\le& E[(D-\mu)^2-(D-a)(D-b)]\\ &=& E[\mu^2-2\mu D+(a+b)D-ab]\\ &=& (a+b)\mu-\mu^2-ab\\ &=&(\mu-a)(b-\mu), \end{eqnarray*}$$ where the equation holds if and only if $$D\in\{a,b\}$$ with probability $$1$$.

Moreover, if $$\mu$$ can be arbitrary in the support set $$[a,b]$$, then clearly $$E(D-\mu)^2\le \left(\tfrac{a+b}{2}-a\right)\left(\tfrac{a+b}{2}-b\right)=\left(\tfrac{b-a}{2}\right)^2.$$

Here's a really simple proof I found in Sheldon Ross's A first course in probability 10th ed., "theory problem 5.8".

Suppose we have a random variable $$X$$ between $$0$$ and $$c$$. Then $$X \leq c$$ and thus $$E(X^2) \leq c E(X)$$. We thus have

$$\mathrm{Var}(X) \leq c E(X) - E(X)^2 = c^2 \alpha (1 - \alpha) \leq c^2 / 4$$

where $$\alpha \equiv E(X) / c$$ and the final step follows from straightforward differentiation to see that $$\alpha (1 - \alpha)$$ is minimized at $$\alpha = 1/2$$.

A simple proof of Popoviciu's inequality is the following, where $$X\in [m, M]$$: $$$$\color{blue}{\operatorname{Var}[X] \le \operatorname{Var}[X] + \mathbb{E}[(M-X)(X-m)] = \frac{(M-m)^2}{4} - \left(\mathbb{E}[X] - \frac{M+m}{2}\right)^2 \le \frac{(M-m)^2}{4}.}$$$$ Source: https://math.stackexchange.com/a/4264325/31498

(Check this answer out for a one-liner proof of Bhatia—Davis's inequality as well.)

The key elements here are that $$f(x) = x^2$$ is convex, $$EX$$ minimises $$E(X-t)^2$$ and $$X(\omega) \in [a,b]$$.

Let $$x \in [a,b]$$, then $$f(x-{1 \over 2}(a+b)) \le {1 \over 2} (f({x-a \over 2}) + f({x-b \over 2}))$$, or $$(x-{1 \over 2}(a+b))^2 \le {1 \over 2} (({x-a \over 2})^2 + ({x-b \over 2})^2 ) \le ({b-a \over 2})^2$$.

Since $$E(X-t)^2 = E(X-EX + EX-t)^2 = \operatorname{var} X + (EX-t)^2$$ for any $$t$$, setting $$t={1 \over 2}(a+b)$$ shows that $$\operatorname{var} X \le E(X-{1 \over 2}(a+b))^2 \le ({b-a \over 2})^2$$.

are you sure that this is true in general - for continuous as well as discrete distributions? Can you provide a link to the other pages? For a general distibution on $[a,b]$ it is trivial to show that $$Var(X) = E[(X-E[X])^2] \le E[(b-a)^2] = (b-a)^2.$$ I can imagine that sharper inequalities exist ... Do you need the factor $1/4$ for your result?

On the other hand one can find it with the factor $1/4$ under the name Popoviciu's_inequality on wikipedia.

For a uniform distribution it holds that $$Var(X) = \frac{(b-a)^2}{12}.$$
• This answer makes some incorrect suggestions: $1/4$ is indeed right. The reference to Popoviciu's inequality will work, but strictly speaking it applies only to distributions with finite support (in particular, that includes no continuous distributions). A limiting argument would do the trick, but something extra is needed here.