Testing random

Steven D'Aprano steve at pearwood.info
Sun Jun 7 09:06:52 EDT 2015


On Sun, 7 Jun 2015 10:52 pm, Steven D'Aprano wrote:

> The median is unchanged, the mean shifts slightly higher, and the standard
> deviation increases. But as you can see, these are not particularly
> powerful tests of randomness: only the mode shows an obvious deviation
> from uniformity.

Oh, I forgot: we can look at the frequencies themselves as well. If our
sample is absolutely perfectly distributed uniformly, then every element
will have a frequency of exactly 10000. We don't necessarily expect this
from a random sample, but if we're too far from that, we should be
concerned. Here are the results from the fair sample:

py> statistics.mean(f.values())
10000.0
py> statistics.median(f.values())
9995.0
py> statistics.stdev(f.values())
91.8027089673141

If I do the same thing with the biased sample, the standard deviation stands
out like a sore thumb:

py> statistics.mean(g.values())
10000.0
py> statistics.median(g.values())
9993.0
py> statistics.stdev(g.values())
1442.527341617181



-- 
Steven




More information about the Python-list mailing list