The following piece of code randomly maps a set of ranges onto a circumference of a circle. In the example, the circumference is of length 1000 and legal ranges are e.g. (0,8)=0,1,2,...,8 and (995,2)=995,996,...,999,0,1,2 (i.e. zero-based coordinates; both start and end are inclusive).
I take some arbitrary position on the circumference (e.g. 36) and count how many ranges cover it in each simulation.
finally, I calculate the mean and variance of this statistic.
use strict; use warnings; use Statistics::Descriptive; my $n_simulations = 1000; my $circumference = 1000; my @lengths_distrib = (100) x 100; # distibution of range lengt +hs my $some_pos = 36; # arbitrary position my $stat = Statistics::Descriptive::Full->new(); foreach my $sim ( 1 .. $n_simulations ) { # randomly map ranges onto circumference my @random_ranges = map { my $start = int( rand($circumference) ); [ $start, ( + $start + $_ -1 ) % $circumference ] } @lengths_distrib; # count how many range contain $some_pos my $num_covering_ranges = scalar( grep { ( $_->[0] <= $some_pos and $_->[1] >= $some_pos ) o +r ( $_->[1] < $_->[0] and $_->[1] > $some_pos ) } @random_ranges ); $stat->add_data($num_covering_ranges); } print $stat->mean, ' ', $stat->variance, "\n";
To the best of my knowledge, this kind of random variable should follow Poisson distribution (law of rare events and so on). Hence, the mean and variance should be equal. However, the variance seems to systematically be a bit lower than the mean.
What am I missing?
UPDATE: this question is now also shared with the guys at CrossValidated (http://stats.stackexchange.com/questions/5005/).
In reply to Unexpected under-dispersion in random simulations by daverave
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |