I am trying to reconstruct the following "jiggled" distribution from this article: American Scientist.
The article states that the pair correlation function is defined as follows: "For each distance x, the correlation function counts how many pairs of levels are separated by x, whether or not those levels are nearest neighbors. The pair-correlation function for a random distribution is flat..."
I wrote the following code in Matlab to recreate the middle picture in this: middle picture.
function two_point(num)
close(gcf);
dx = 0:.01:1;
count = zeros(1,length(dx));
x = zeros(1,num);
for i=1:(num-1)
x(i+1) = x(i) + rand(); % increase at uniformly distributed random distances
end
for i=1:length(dx)
del = dx(i);
for j=1:(length(x) - 1)
for k=(j+1):length(x) % start at j+1 so I don't double count
dist = abs(x(j) - x(k)); % check all neighbors against one another
if (dist >= (del - .01) && dist <= (del + .01)) % just using 2 significant digits
count(i) = count(i) + 1;
end
end
end
end
ind = (count == 0);
count(ind) = nan; % so I don't plot the distances that don't show up
scatter(dx, count, 'fill');
end
The problem is that every picture I generate has a large upward trend (think y = mx, m > 0), where the higher distances seem more likely. Shouldn't the uniform distribution result in a flat picture, because all distances are equally likely? I'm thinking I have a bug somewhere in my code. Here is the trend that gets generated: (redacted, not enough reputation for more than 2 links). I have also tried the double for loop (1->length(x), 1->length(x)) with the same result.
Thank you for any help!
In the quoted sentence they never talk about a uniform distribution. In fact the statement is not clear to me (what random distribution?).
However, focusing on your code, you are simulating an increasing process as you are imposing postive increments. So it is no surprise that higher distances are more likely to be found if you consider distances between all the possible pairs. Either you focus on distances between adiacent elements only or you need to change your process if you want to show a flat behaviour of the correlation pair.