#!/usr/bin/perl use strict; my $numtrials = 1000000; # tweak these probabilities experimentally to see outcomes my $background_probability_1 = 0.81; print "Background probability 1: $background_probability_1\n"; my $background_probability_2 = 0.61; print "Background probability 2: $background_probability_2\n"; # Sample sizes and observed rates; leave these fixed my $sample_size_1 = 47; my $sample_size_1_threshold = 36; # we count the times our sample goes *below* this threshold my $sample_size_2 = 54; my $sample_size_2_threshold = 38; # we count the times our sample goes *above* this threshold my $times_threshold_1_met = 0; my $times_threshold_2_met = 0; my $times_both_thresholds_met = 0; for (my $i = 1; $i <= $numtrials; ++$i) { my $threshold_1_met = 0; my $threshold_2_met = 0; my $count_1 = 0; for (my $j = 0; $j <= $sample_size_1; ++$j) { if (rand(1) < $background_probability_1) { ++$count_1; } } if ($count_1 <= $sample_size_1_threshold) { $threshold_1_met=1; } my $count_2 = 0; for (my $j = 0; $j <= $sample_size_2; ++$j) { if (rand(1) < $background_probability_2) { ++$count_2; } } if ($count_2 >= $sample_size_2_threshold) { $threshold_2_met=1; } if ($threshold_1_met) { ++$times_threshold_1_met; } if ($threshold_2_met) { ++$times_threshold_2_met; } if ($threshold_1_met && $threshold_2_met) { ++$times_both_thresholds_met; } } print "Times threshold 1 met: $times_threshold_1_met/$numtrials\n"; print "Times threshold 2 met: $times_threshold_2_met/$numtrials\n"; print "Times both thresholds met: $times_both_thresholds_met/$numtrials\n";