# Statistics/Distributions/Discrete Uniform

### Discrete Uniform Distribution

The discrete uniform distribution (not to be confused with the continuous uniform distribution) is where the probability of equally spaced possible values is equal. Mathematically this means that the probability density function is identical for a finite set of evenly spaced points. An example of would be rolling a fair 6-sided die. In this case there are six, equally like probabilities.

One common normalization is to restrict the possible values to be integers and the spacing between possibilities to be 1. In this setup, the only two parameters of the function are the minimum value (a), the maximum value (b). (Some even normalize it more, setting a=1.) Let n=b-a+1 be the number of possibilities. The probability density function is then

${\displaystyle f\colon \{a,a+1,\ldots ,b-1,b\}\to \mathbb {R} }$

${\displaystyle f\left(x\right)={\frac {1}{n}}}$

#### Mean

Let ${\displaystyle S=\{a,a+1,\ldots ,b-1,b\}}$ . The mean (notated as ${\displaystyle \operatorname {E} [X]}$ ) can then be derived as follows:

${\displaystyle \operatorname {E} [X]=\sum _{x\in S}xf(x)=\sum _{i=0}^{n-1}\left({\frac {1}{n}}(a+i)\right)}$
${\displaystyle \operatorname {E} [X]={1 \over n}\left(\sum _{i=0}^{n-1}a+\sum _{i=0}^{n-1}i\right)}$

Remember that in ${\displaystyle \sum _{i=0}^{m}i=(m^{2}+m)/2}$

${\displaystyle \operatorname {E} [X]={1 \over n}\left(na+{(n-1)^{2}+(n-1) \over 2}\right)}$
${\displaystyle \operatorname {E} [X]={2na+n^{2}-2n+1+n-1 \over 2n}}$
${\displaystyle \operatorname {E} [X]={2a+n-1 \over 2}}$
${\displaystyle \operatorname {E} [X]={a+b \over 2}}$

#### Variance

The variance (${\displaystyle E[(X-EX)^{2}]}$ ) can be derived:

${\displaystyle \operatorname {Var} (X)=\operatorname {E} [(X-\operatorname {E} [X])^{2}]=\sum _{x\in S}f(x)(x-E[X])^{2}=\sum _{i=0}^{n-1}\left({\frac {1}{n}}\left((a+i)-{a+b \over 2}\right)^{2}\right)}$
${\displaystyle \operatorname {Var} (X)={1 \over n}\sum _{i=0}^{n-1}\left({a+2i-b \over 2}\right)^{2}}$
${\displaystyle \operatorname {Var} (X)={1 \over 4n}\sum _{i=0}^{n-1}(a^{2}+4ai-2ab+4i^{2}-4ib+b^{2})}$
${\displaystyle \operatorname {Var} (X)={1 \over 4n}\left[\sum _{i=0}^{n-1}(a^{2}-2ab+b^{2})+\sum _{i=0}^{n-1}(4ai-4ib)+\sum _{i=0}^{n-1}4i^{2}\right]}$
${\displaystyle \operatorname {Var} (X)={1 \over 4n}\left[n(a^{2}-2ab+b^{2})+4(a-b)\sum _{i=0}^{n-1}i+4\sum _{i=0}^{n-1}i^{2}\right]}$

Remember that in ${\displaystyle \sum _{i=0}^{m}i^{2}=m(m+1)(2m+1)/6}$

${\displaystyle \operatorname {Var} (X)={1 \over 4n}\left[n(b-a)^{2}+4(a-b)[(n-1)n/2]+4[(n-1)n(2n-1)/6]\right]}$
${\displaystyle \operatorname {Var} (X)={1 \over 4n}\left[n(n-1)^{2}-2(n-1)(n-1)n+2(n-1)n(2n-1)/3\right]}$
${\displaystyle \operatorname {Var} (X)={1 \over 4}\left[-(n-1)^{2}+2(n-1)(2n-1)/3\right]}$
${\displaystyle \operatorname {Var} (X)={1 \over 12}\left[-3(n-1)^{2}+2(n-1)(2n-1)\right]}$
${\displaystyle \operatorname {Var} (X)={1 \over 12}\left[-3(n^{2}-2n+1)+2(2n^{2}-3n+1)\right]}$
${\displaystyle \operatorname {Var} (X)={n^{2}-1 \over 12}}$