## Compute pass/fail criteria for Voter Inclusion Index (VII). sub getnum { my ($prompt) = @_; my ($inp); print $prompt; $inp = ; if ($inp =~ m%((\d+(\.\d+)?)|(\.\d+))%) { return $1; } else { die "Bad input\n"; } } ### ### ### ### ### ### ### ### ### ### ### ### ### ### MAIN LINE STARTS HERE ### ### ### ### ### ### ### ### ### ### ### ### ### ### ## You can either enter the scores in the array below or just enter ## the mean and std. dev. directly ## If you want the program to compute mean and std.dev. for you, fill in ## the following array with the participant scores. ## Fill in results for the system under test - must be at least 100 entries. ## Valid values are 0 thru 28. These arrays don't really need to be sorted, BTW. @tst_val = ( ## Example of how to enter the results: 28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28, 28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28, 28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,27,27,27,27, 27,26,26,26,26,26,26,26,26,26,22,22,22,22,22,22,21,21,21,21, 20,20,20,20,20,20,20,20,19,19,18,16,16,16,16,16,16,16,11, 9, 9, 2 ); $warn = ""; while ($warn ne "OK") { print "$warn \nDo you wish to enter mean and std.dev directly (d), \n", "or use the array of scores (a) ? "; $inp = ; if ($inp =~ m%\A([ad])%) { $warn = "OK"; $method = $1; } else { $warn = "\n\nResponse must be \"a\" or \"d\". \n"; } } print "Compute pass/fail criteria for Voter Inclusion Index (VII) \n\n"; if ($method eq "d") { # enter values directly $ncast = getnum ("Enter the number of participants who successfully cast a ballot: "); $vii_mean = getnum ("Enter the mean of the participants' success percentages (0-100): "); $vii_sd = getnum ("Enter the std.dev. of the participants' success percentages: (0-100): "); # express as fraction, not percentage $vii_mean /= 100 if ($vii_mean > 1); $vii_sd /= 100 if ($vii_sd > 1); } else { # derive values from array $ncast = scalar (@tst_val); $tot = 0; foreach $num (@tst_val) { die "\nERROR: Test value not in 0-28 range: $num \n" if ($num < 0 || $num > 28); $tot += $num / 28; } $vii_mean = $tot / $ncast; $tot = 0; foreach $num (@tst_val) { $tmp = $vii_mean - ($num / 28); $tot += $tmp * $tmp; } $vii_sd = sqrt ($tot / ($ncast - 1)); printf "Mean = %8.3f; Std.dev = %8.3f \n", $vii_mean, $vii_sd; } if ($ncast < 100) { print "\nWARNING: #cast ballots = $ncast; results are valid only if ", "#cast ballots >= 100 \n\n"; } $signif_95 = 1.96; # set for 95% confidence $vii = ($vii_mean - 0.85) / (3 * $vii_sd); $sigma = sqrt ( 1 / (9 * $ncast) + ($vii * $vii) / (2 * ($ncast-1))); $high_CI = $vii + $signif_95 * $sigma; $low_CI = $vii - $signif_95 * $sigma; printf "\nVII = %8.3f; sigma = %8.3f; CI = [ %8.3f, %8.3f ] \n", $vii, $sigma, $low_CI, $high_CI; if ($high_CI < 0.35) { print "CI for VII is below benchmark of 0.35; test failed.\n"; } else { print "High end of CI for VII exceeds benchmark of 0.35; test passed.\n"; }