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.


*

*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?

*How could I, using R or Python, perform a goodness-of-fit test for an observed data set?

 A: 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})$
A: I have a very similar problem to yours actually, also non-overlapping variable length intervals.
I am right now working on this so I cant give a full answer, also I am not a statistician so I wont even approach this from a math side.
But for your 2nd question, one possible approach is the following:

*

*you compute the interarrival times, so the number of failures between success.

*In my case I have strong belief that these interarrival times follow a geometric distribution. Hence what you can do is a probability plot, in python this can be done with scipy.

*I do the probplot with these interarrival times and the distribution i expect them to be

*If the points lie on a line this is a good argument that they indeed follow this distribution.

Here is an artificial example
import numpy as np
import matplotlib.pyplot as plt
import statsmodels.api as sm
import scipy
from scipy import stats

d1 = np.random.geometric(p=0.1, size=50)
scipy.stats.probplot(d1, dist="expon", plot=plt)
plt.show()

Note: Im using the exponential distribution (which is the continuous counterpart of geometric as far as i understand) because this plot does not seem to work with discrete distributions.
Anyway this produces:

Unfortunately I cant guarantee that this answer is completely correct since again this is also a new area to me. If I learn more I may update the answer
