The mean and variance of the discrete uniform distribution

The discrete uniform distribution

The uniform discrete distribution has range of n points in [a, b], or
\{a, a +1, a+2, .... b-1, b \}. Each point has a uniform pmf (probability mass function)

Pr(x) = 1/n.

where n = b -a + 1.

Mean of the discrete uniform distribution

Let us compute the mean and variance. Intuitively, we feel that the mean is at the
midpoint (a + b) / 2. We shall see that this intuition is correct.

E(X) = \sum x \frac{1}{n} = \frac{1}{n} \sum {x}.

But \sum {x} is just a sum of an arithmetic progression where the start value a
and the last value is b with common difference of 1. The sum is then

S = n (a + b)/2

from which the mean or expectation is computed to b be

\mu_X = E(X) = (a+b)/2


The variance of the uniform discrete distribution.

Let us first translate the random variable range from [a,b] to the range[1,n]. Then we know that the variance is not affected by the translation.

V(X) = \overline{X^2} - (\overline{X})^2
= (n (n+1) (2n+1)/(6 n) - [(n+1)/2)]^2
=  \frac{2n^2 + n + 2n + 1}{6}- \frac{(n^2 + 2n + 1)}{4}
= \frac{[4 n^2 + 2n + 4n + 2 - 3n^2 -6n -3]}{12}
=  \frac{[n^2 -1] }{12}
=  \frac{(n+1) (n -1) }{12}

Here we used the fact that \sum_{i=1}^n i^2 = \frac{(n (n+1) (2n+1)}{6} and \sum_{i=1}^n i = \frac{n (n+1)}{2}. These formulas are well known.

Substituting n = b -a + 1 in the above formula yields V(X) = (b -a + 2) (b -a)/12 =  (b -a +1)^2 -1.

To recap: The mean and variance of a random variable X with domain \{a, a+1, \cdots, b-1, b\}
are given by

E(X)= (a + b) / 2

V(X)= \frac{(b-a+1)^2 - 1}{12}= \frac{(b -a + 2) (b-a)}{12}.

2 Responses to “The mean and variance of the discrete uniform distribution”

  1. Rasoul Says:

    I think the proof is not general because we cannot say that

    \Sum_{x=0}^{n} x^2 = \Sum_{x=a}^{b} x^2

    even if n = b - a + 1

    From summation identities, we have

    \Sum_{x=a}^{b} x^2 = \Sum_{x=0}^{b-a} (x+a)^2

  2. ernie Says:

    Thanks Rasoul, I will review this article when I have the time.