Dear Monks,

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.