# Uniform random vector with zero sum restriction?

I'm building a Metropolis transition kernel and figured out I would need a very specific distribution for optimal results. How can I construct a random vector $$(U_1, U_2, \dots, U_n)$$ such that

• $$\sum_i U_i = 0$$.
• $$-a \leq U_i \leq a$$ for all $$i$$. (Not necessary, but it would be useful)
• $$f(u_1, u_2, \dots, u_n) = \text{constant}$$. (If the previous condition holds)

My initial idea was to use a Dirichlet distribution with parameters $$(1,1,\dots,1)$$, what would lead to a uniform distribution but with the restriction that $$\sum U_i = 1$$ with $$0 \leq U_i \leq 1$$ and $$f(u_1, \dots, u_n) = \frac{1}{\Gamma(n)}$$.

It seems like simply rescaling and shifting should be enough as (I suppose) defining $$V_i = (U_i - \frac{1}{n})$$ makes the zero-sum condition hold, but if $$n>2$$ the inverval for $$V_i$$ is not symmetric around zero.

Is it possible to reasonably transform the Dirichlet distribution so that those three conditions hold? Are there other distributions that are easy to sample from that have, at least, the first condition?

• The constraints on the vector components define the intersection of the hyperplane $\sum u_i=0$ with the hypercube $(-a,a)^n$. The uniform distribution is therefore the density with constant equal to the inverse of the volume of the set. Feb 7, 2020 at 17:33
• The Dirichlet has beta marginals, so other than $n=2$ you won't get symmetry around zero or your third condition. In fact, because of the sum constraint, I don't think the joint pdf exists in $n$ dimensional space (the measure of your sample space is zero in $n$ dimensions). You could try singular normal distributions, which will satisfy your first condition and symmetry. You could probably force the standard deviation so the second condition is satisfied to your needs as well. Feb 7, 2020 at 22:43

Here's an approach using the singular normal mentioned in the comment. Generate 3 standard normal realizations. Then subtract off one third of the sum from each variate, giving the zero sum.

Here is R code illustrating:

library(data.table)

x <- rnorm(100000,0,1)
y <- rnorm(100000,0,1)
z <- rnorm(100000,0,1)

norm3 <- data.table(x = x,y = y,z = z)
norm3$$sum <- norm3$$x + norm3$$y + norm3$$z

norm3$$a <- norm3$$x - norm3$$sum/3 norm3$$b <- norm3$$y - norm3$$sum/3
norm3$$c <- norm3$$z - norm3$sum/3 norm3$$check <- norm3$$a + norm3$$b + norm3$$c hist(norm3$a)


Here's the histogram for the first component (the others are similar):

• Doesn't this strongly violate the constant-density criterion (#2 in the question) as well as the compact support criterion, #3?
– whuber
Feb 9, 2020 at 15:57
• At the end of the post the question asks for a non-Dirichlet distribution that is easy to sample from and satisfies the sum constraint. This answers addresses that need as well as the mid-question request for symmetry around zero. Feb 10, 2020 at 17:32

Here is an approach for the trivariate case that is based on the Dirichlet. Generate $$X \sim \ U[-1/3, \ 1/3]$$ Now set $$Y$$ conditional on $$X$$ : $$Y =\begin{cases} X+{1/3} \ , & \text{if} \ X \le {0} \\ X-{1/3} \ , & \text{if} \ X \gt {0} \end{cases}$$ Finally, to satisfy the sum constraint, we set $$Z = -(X+Y)$$

All the marginals have identical uniform distributions and therefore satisfy your bound constraint.

Here is R code:

library(data.table)

# Force the sum to be zero
x <- runif(10000,-1/3,1/3)
all <- data.table(x=x)
all[,':='(y = ifelse(x < 0,x + 1/3,x - 1/3))]
all[,':='(z = -1.0*(x+y))]

# Show the marginals
hist(all$$x) hist(all$$y)
hist(all$z) # Get a rotatable chart in 3D library(rgl) library(car) scatter3d(all$$x,all$$y,all$z)


I can't post the rotatable chart, but if you are able to run this you will see the realizations come from two parallel lines in the plane satisfying the equation $$x+y+z=0.$$ I think this scheme can be generalized to higher dimensions.