# Divergence from uniform distribution (continuous): dispersion measure?

I have data of a continuous random variable within the range [-1,1], which sometimes is concentrated around 0, while other times is concentrated toward -1 and 1, while zero is relatively underpopulated.

What measure can I use for both these cases to measure the divergence from a uniform distribution?

In other terms: I am looking for a measure of how evenly spread out the data is within the range, but standard dispersion measures (like variance) don't seem to work, since they favor distributions in which the tails are higher than the 'peak', e.g., when the region around zero is relatively underpopulated.

• you mean like some goodness of fit statistic (such as a Kolmogorov-Smirnov or Cramer-von Mises statistic)? – Glen_b Feb 10 '14 at 11:02

Expanding on @Glen_b 's comment:

KS works quite well here. In R, first create distributions like those mentioned

set.seed(123)
library(moments)
library(lattice)

UniDist <- runif(10000,-1,1)
NormDist <- rnorm(10000,0,1)
TruncNormDist <- NormDist[NormDist > -1 & NormDist < 1]
LowDist <- rnorm(5000,-.5,.1)
HighDist <- rnorm(5000,.5,.1)
TruncLowDist <- LowDist[LowDist < 0 & LowDist > -.5]
TruncHighDist <- HighDist[HighDist > 0 & HighDist < .5]
InvDist <- c(TruncLowDist, TruncHighDist)


Then test with ks.test:

ks.test(TruncNormDist, UniDist)
ks.test(InvDist, UniDist)


However, the D values are not intuitive (at least, not to me); ordinarily, I would suggest also using quantile plots:

qqplot(TruncNormDist, UniDist)


But that does not work well here (there is almost no divergence). Nor is a basic scatterplot much help:

xyplot(TruncNormDist~UniDist)


But Tukey mean difference plots are another matter

tmd(xyplot(TruncNormDist~UniDist))


Shows that the difference between the two distributions is near 0 at -1 and 1, but larger in the middle.

Comparing the inverse distribution to the truncated normal is much easier; both qqplot and xyplot show huge differences, and tmdplot is fascinating.

• It's been a while since I've used R. How do I get tmd and xyplot? – Angelorf Feb 10 '14 at 12:28
• install.packages("lattice") and library(lattice). If you use SAS you can get both of these plots there, as well. Let me know if that's the case and I will provide more details. – Peter Flom Feb 10 '14 at 12:28
• Yes, I just needed to do library(lattice). Not using SAS, though. – Angelorf Feb 10 '14 at 12:32