# Test goodness of fit for geometric distribution

Consider a set of variable length non-overlapping intervals on a discrete finite number line.

|------------------------------------------------------------------------------------|
[---]     [-----] [-]     [--------]    [-----]                 [--] [-]     [---]


I want to test whether the spacing of these intervals is random. I have two questions.

1. First, is it correct that under a random arrangement the spacing of the intervals should follow a geometric distribution with probability of success equal to $\frac{N}{S}$ where $N$ is the number of intervals and $S$ is the cumulative length of the space unoccupied by the intervals?
2. How could I, using R or Python, perform a goodness-of-fit test for an observed data set?
• The short answer to 1 is no. Consider the finite-length line $[0,10]$, with two non-overlapping intervals $[0,4]$ and $[5,10]$. Clearly randomly rearranging them won't give you a geometric distribution for the spacing. – jbowman Apr 19 '16 at 19:27

The differences between the "events" have a poisson distribution. Let $N(l)$ be the number of "events" to occur in $[0,l]$, $l$ fixed.
We know, $$P\{N(l) = k\} = \frac{e^{-\lambda l}(\lambda l)^k}{k!}, k=0,1,2,...$$ take $0<l_1<l_2<...<l_n<\infty$ where any given difference $$N(l_1), N(l_2)-N(l_1), ..., N(l_n)-N(l_{n-1})$$ and $$N(l_i) - N(l_{i-1})$$ has a poisson distribution with parameter $\lambda(l_i - l_{i-1})$