# How to calculate the mean and variance of a uniformly distributed data set

I generated a series of 20 numbers uniformly distributed in the interval [0,1].

i Ui

1 0.179249377

2 0.55231524

3 0.845266587

4 0.335790807

5 0.755363948

6 0.136198531

7 0.641448669

8 0.479322568

9 0.779031078

10 0.610433663

11 0.989860381

12 0.765129741

13 0.840363047

14 0.255395385

15 0.002587429

16 0.311871613

17 0.081981029

18 0.791845714

19 0.896312967

20 0.858145209

For Uniform distribution

mean = (a+b)/2

variance = (b-a)2/12

Does this mean that for this data set:

mean = (min+max)/2 = (0.002587+0.989860)/2 = 0.4962

variance = (max-min)2/12 =(0.989860-0.002587)2/12=0.0812

Or would I calculate the mean and variance for this data set the regular way?

mean = ∑Ui/20 = 0.5554

variance = ∑(Ui-μ)2/20-1 = 0.0954

You should do it in the regular way.

The formulae $$\text{mean}=\frac{a+b}{2}$$ $$\text{variance}=\frac{(b-a)^2}{12}$$

are theoretical value (population mean and variance) for uniform distribution in $[a,b]$, to which your estimators (sample mean and unbiased estimator of variance) should approach when the number of data tends to infinity.

• (1) Because the question asks about "this data set," this answer doesn't seem appropriate. (2) Please check the formula for the variance: its units of measurement are incorrect and therefore it cannot possibly be right. You likely meant to square the numerator. – whuber Oct 9 '17 at 21:39

To compute the mean and variance of a sample, you needn't know the distribution.

$$\bar u=\frac1n\sum_{k=1}^n u_k,$$ and

$$\text{var}(u)=\frac1{n-1}\sum_{k=1}^n(u_k-\bar u)^2.$$

If you are after the mean and variance of the distribution itself, they are

$$\frac12$$ and $$\frac1{12}.$$