# Expected distance to nearest neighbour: Why integral of survivor function? (instead of derivative)

Previously, I asked the question how to calculate the expected distance to the nearest neighbor molecule in 3-dimensional space. This question was fully answered, which is I ask this related question in a separate thread. As a disclaimer, I know that the previous answer reflects the literature, and I do not intend to question its validity whatsoever.

I wanted to calculate the expected distance of 1 particular of 500 molecules to its closet of 499 neighbors that are randomly diffusing in a volume of 1 cubic micrometer.

I think I understand the following statement:

Since the neighbor positions are independent, the chance that all are further than distance 𝑟 is

$$S_{N;d}(r) = (1-r^d)^N.$$

But to my mind, without former education in math and statistics, I would argue that the derivative of this function - the change in probability at given r - should reflect the probability of finding closest neighbors at this r. Also this approach seemingly perfectly recreates a 3d simulation:

3D simulation (Python)

import numpy as np

import numpy as np
def min_eucledian(centers):
squared = np.square(centers)
summed = [sum(squared[i*3:i*3+3]) for i in range(len(squared)//3)]
return np.sqrt(min(summed))

N = 499
simulation_length = 3*10**6 #this was used, I know it is excessive
distances = []
for i in range(simulation_length):
protein_centers = np.random.uniform(low=-500, high=500, size=N*3)
distances.append(min_eucledian(protein_centers))
if i%10000 == 0:
print(i)


"Derivative" approach

Probability of finding 0 neighbors within r:

Derivative:

So, the derivative seems logical to me, also it perfectly recreates the simulation. Instead, the textbook approach is off by around 70%. (see linked question)

So I would like to ask 2 questions:

1. Could you explain the logic behind using the integral in simple English, understandable without much education in statistics?

2. How may I interpret the discrepancy of the results? Am I asking different questions? Is my simulation wrong?

EDIT: I happened to find the answer to the question. I repeated the calculation without the sphere-factor (4/3 * pi), what perfectly recreates the previous answer. I know what is going on. A moderator may delete the question, unless it is found educative. Thanks!

• Since you found the answer, could you answer your own question (and accept it) with a bit more detail? I think this would help others more. See here for details. Mar 16, 2021 at 13:39
• I can't answer the full question, I just happened to find the root of the discrepancy of results. Mar 16, 2021 at 13:55