# How to generate random points in the volume of a sphere with uniform nearest neighbour distances

With respect to post (1) and post (2), I generated a large number of uniformly distributed points inside the ball of radius $R$ using $\frac{R_s U^{1/3}}{\sqrt{X_1^2 + X_2^2 + X_3^2}} (X_1, X_2, X_3)$, where $U$ is uniformly distributed between 0 and 1, and $X_1, X_2, X_3$ are independent normal random variables with mean 0 and variance 1. The following figure shows a uniform spherical distribution obtained by this method using 10000 independent draws in a sphere of radius 10. By computing the nearest neighbour distance $d_i$ of every point, I observed that the diagnostic plot of nearest neighbour distances does not follow a uniform distribution. Does this non-uniform distribution mean that one can cluster the points? Does it mean points dont have spatial randomness? If so, then how can I generate random points with uniform nearest neighbour distances.

Temporary images for @Anony-Mousse consideration:  • The very picture shows that the distribution is not uniform, it is more dense in the centre. In what sense is it uniform to you? – ttnphns Feb 5 '14 at 12:04
• @ttnphns yes, you are right. Randomness of $d$ is important for me. I want to avoid point clustering based on nearest neighbor distance metric. – Jolfaei Feb 5 '14 at 12:17
• I was speaking not about randomness, but about uniformity. Am I right in that you want a ball of points uniformly populating inside the ball - i.e. like a solid ball of iron? – ttnphns Feb 5 '14 at 12:27
• In a neat answer to this stats.stackexchange.com/q/79919/3277 @RayKoopman showed how to make a n-dimensional ball of points (and any distribution between normal and ball). May that help? – ttnphns Feb 5 '14 at 14:14
• @ttnphns Those points appear to be correctly generated and distributed. They look more concentrated in the center because the sphere is thicker in the center. – whuber Feb 5 '14 at 22:59

I wouldn't expect the distribution of the nearest neighbour distances to be uniform under spatial randomness.

According to Wikipedia (http://en.wikipedia.org/wiki/Complete_spatial_randomness), the distance of the first neighbour in your case has the following distribution:

$P_1(r) = 3\lambda r^2\exp(-\lambda r^3)$

where $\lambda$ is ta density dependent parameter. This is obviously non-uniform!

Concerning your clustering question: You can always cluster points, independently of their distribution.

• How did you calculate the probability distribution function? what is $Lambda$? – Jolfaei Feb 5 '14 at 13:20
• I think this answer may not be correct. In Complete spatial randomness, the empirical data is assumed to have has Poisson distribution, and randomness is checked with the Poisson theoretical distribution. Also, calculation are done in a 2D space not 3D. This is not my case. – Jolfaei Feb 5 '14 at 13:25
• I didn'd calculate the distribution, I just adapted the formula of the wikipedia article to your situation. $\lambda$ is connected with the point density and the number of dimensions of your problem. – user1449306 Feb 5 '14 at 13:26
• Just read the article. The poisson distribution describes the amount of points per region, not the point distribution. – user1449306 Feb 5 '14 at 13:33
• Well, you place your points independently of each other with a uniform probability over the ball. Hence you get a constant, position independent density and have met the Poisson-requirements of constant rate (=density) and independence of the events (points). – user1449306 Feb 5 '14 at 14:57

Consider a uniform 1 dimensional $U[0;1]$ distribution.

Probably the simplest distribution we can find, right?

The distribution of distances will not be uniform.

Instead (if I'm not mistaken; might only hold for the central area), it should be a Beta $B(k,n+1-k)$ distribution. If you are talking about the 1 nearest neigbor, that is a $B(1,n)$ distribution. This is only uniform, if $n=1$.

• I have done a test with MATLAB. Using the method explained above I generated 10000 independent points in a sphere of radius 10. I calculated the nearest neighbour distance for all points. Using the curve fitting tool of MATLAB, I found that the best fit for the empirical distribution of nearest neighbours is Nakagami distribution. – Jolfaei Feb 6 '14 at 10:06
• Knowing that the distribution of nearest neighbour distances is not uniform, then how can I check their randomness? – Jolfaei Feb 6 '14 at 10:12
• "Randomness" is a big too vague. You may want to look at the discrepancy of the series, goodness-of-fit tests and Hopkins statistic, for a starter. However, things that appear random to us, may be quite well ordered, see e.g. en.wikipedia.org/wiki/Low-discrepancy_sequence for "sub-random" series, that are more evenly distributed than uniform random is... – Has QUIT--Anony-Mousse Feb 6 '14 at 13:07
• When your sample was Nakagami distributed, than the squared distances should be Gamma distributed, right? Often, you will see your squared distances to be $\chi^2$ or $\Gamma$ distributed. But I don't think this will be well usable for a test. – Has QUIT--Anony-Mousse Feb 6 '14 at 13:08
• Can you explain more. – Jolfaei Feb 6 '14 at 13:22