#!/usr/bin/perl -w # # Read Florida election data, and try to re-adjust Kerry votes # from the opscan counties using a linear fit to the data from the # e-touch counties. # use strict; my $adjust_by_size = 0; my $dem_weight = 0.65095; # Weights set from the linear model of Kerry votes my $rep_weight = 0.08187; my $ind_weight = 0.36361; ##my $slope = 0; ##my $intercept = 0; my $slope = 1.437e-05; # By-population least-squares line for Kerry votes my $intercept = -10.57; # Values computed from linear model against ET county actual data my $ind_votes_ind_coef = -0.006868; # Linear model of independent votes by registration my $ind_votes_dem_coef = 0.010636; my $ind_votes_rep_coef = 0.008530; ##my $dem_turnout = 0.659; ##my $rep_turnout = 0.799; ##my $ind_turnout = 0.813; ##my $dem_prefer_kerry = 0.85; ##my $rep_prefer_kerry = 0.07; ##my $ind_prefer_kerry = 0.57; ##my $dem_prefer_bush = 0.14; ##my $rep_prefer_bush = 0.93; ##my $ind_prefer_bush = 0.41; ##my $slope = 1.487e-05; # By-pop least-squares line, using exit poll turnout/pref data ##my $intercept = -4.089; my @counties; # County names -- other tables are indexed by name my %c_used_op_scan; # 1 => used op_scan voting, 0 => used e-touch my %c_voted; # Triples, [rep, dem, total] my %c_reg; # Triples, [rep, dem, total] my $tot_os = 0; my $tot_et = 0; my $vote_file = "florida_votes_reduced.txt"; my $dbg = 0; sub dbprint ($) { my ($str) = (@_); if ($dbg) { print $str; } } # **************************************************************** # Read arguments while (@ARGV > 0) { $_ = shift; if (/^-debug/) { $dbg = 1; } elsif (/^-by_size/) {$adjust_by_size = 1; } else { die "Argument $_ not understood\n"; } } # **************************************************************** # Read the vote file open VFILE, "<$vote_file" or die "Can't open vote file $vote_file\n"; while () { chomp; if (! /^ (E-Touchscreen|Op-Scan-Precinct) \s+ # Machine type ([a-zA-Z .\-]+) \s+ # County name (\d+) \s+ # Rep votes (\d+) \s+ # Dem votes (\d+) \s+ # Total votes (\d+) \s+ # Rep registration (\d+) \s+ # Dem registration (\d+) \s+ # Total registration ([0-9.\-]+) \s+ # %votes difference ([0-9.\-]+) # %reg difference $/x) { dbprint "Line not matched: $_\n"; next; } my ($mach,$county,$repv,$demv,$totv,$repr,$demr,$totr) = ($1,$2,$3,$4,$5,$6,$7,$8); ##dbprint "Machine: $mach ; County: $county\n"; push @counties, $county; my $is_os = ($mach eq "Op-Scan-Precinct") ? 1 : 0; if ($is_os) { $tot_os++; } else { $tot_et++; } $c_used_op_scan{$county} = $is_os; $c_voted{$county} = [$repv, $demv, $totv]; $c_reg{$county} = [$repr, $demr, $totr]; } close VFILE or die "Can't close votes file"; # **************************************************************** # Digest one variety of vote sub do_votes () { my $tot_os_votes = 0; my $tot_et_votes = 0; my $tot_votes = 0; my $tot_kerry_os_votes_raw = 0; my $tot_kerry_os_votes_adjusted = 0; my $tot_kerry_et_votes = 0; my $tot_bush_votes = 0; my $tot_indep_votes = 0; my $tot_et_indep_votes = 0; my $tot_os_indep_votes = 0; my $tot_os_indep_model_votes = 0; foreach my $county (@counties) { my $c_opscan = $c_used_op_scan{$county}; my $voted = $c_voted{$county}; my $reg = $c_reg{$county}; my $rep_c_votes = $$voted[0]; my $dem_c_votes = $$voted[1]; my $tot_c_votes = $$voted[2]; my $ind_c_votes = $tot_c_votes - ($rep_c_votes + $dem_c_votes); my $rep_c_reg = $$reg[0]; my $dem_c_reg = $$reg[1]; my $tot_c_reg = $$reg[2]; my $other_c_reg = $tot_c_reg - ($rep_c_reg + $dem_c_reg); $tot_votes += $tot_c_votes; $tot_indep_votes += $ind_c_votes; if (! $c_opscan) { $tot_et_votes += $tot_c_votes; $tot_et_indep_votes += $ind_c_votes; $tot_kerry_et_votes += $dem_c_votes; printf "%15s: Votes (no adjustment): %d; independent votes: %d (%3.1f%%)\n", $county, $dem_c_votes, $ind_c_votes, ($ind_c_votes / $tot_c_votes) * 100; next; } $tot_os_votes += $tot_c_votes; $tot_kerry_os_votes_raw += $dem_c_votes; $tot_os_indep_votes += $ind_c_votes; my $model_indep_votes = ($ind_votes_ind_coef * $other_c_reg) + ($ind_votes_rep_coef * $rep_c_reg) + ($ind_votes_dem_coef * $dem_c_reg); $tot_os_indep_model_votes += $model_indep_votes; # Compute expected Kerry vote my $expected_c_kerry_votes = $rep_c_reg * $rep_weight; $expected_c_kerry_votes += $dem_c_reg * $dem_weight; $expected_c_kerry_votes += $other_c_reg * $ind_weight; my $factor; if (!$adjust_by_size) { $factor = 1; } else { # Compute expected excess, based on voter count my $expected_excess = $intercept + ($slope * $tot_c_reg); # Compute the skewed Kerry vote $factor = 1 + ($expected_excess / 100); } my $skewed_vote = $expected_c_kerry_votes * $factor; $tot_kerry_os_votes_adjusted += $skewed_vote; my $adjusted_by = ($skewed_vote - $dem_c_votes) / $dem_c_votes; printf "%15s: Raw: %6d; Adjusted: %6d; Adjustment factor: %5.1f%%; Independent votes: %d (%3.1f%%); Model ind votes: %d (%3.1f%%)\n", $county, $dem_c_votes, $skewed_vote, $adjusted_by * 100, $ind_c_votes, ($ind_c_votes / $tot_c_votes) * 100, $model_indep_votes, ($model_indep_votes / $tot_c_votes) * 100; } my $tot_indep_model_votes = $tot_et_indep_votes + $tot_os_indep_model_votes; printf "\n" . " Total ET votes: $tot_et_votes\n" . " Total OS votes: $tot_os_votes\n" . " Total votes: $tot_votes\n" . " Total Kerry ET votes: $tot_kerry_et_votes\n" . " Raw Kerry OS votes: $tot_kerry_os_votes_raw\n" . "Adjusted Kerry OS votes: %d\n\n" . " Total Indep ET votes: $tot_et_indep_votes (%3.2f%%)\n" . " Total Indep OS votes: $tot_os_indep_votes (%3.2f%%)\n" . "Total Independent votes: $tot_indep_votes (%3.2f%%)\n" . " Indep OS Model votes: %d (%3.2f%%)\n" . "Total Indep Model votes: %d (%3.2f%%)\n", $tot_kerry_os_votes_adjusted, ($tot_et_indep_votes / $tot_et_votes) * 100, ($tot_os_indep_votes / $tot_os_votes) * 100, ($tot_indep_votes / $tot_votes) * 100, $tot_os_indep_model_votes, ($tot_os_indep_model_votes / $tot_os_votes) * 100, $tot_indep_model_votes, ($tot_indep_model_votes / $tot_votes) * 100; print "\n"; printf " Percent to Kerry from ET counties: %3.1f\n", ($tot_kerry_et_votes / $tot_votes) * 100; printf " Raw percent to Kerry from OS counties: %3.1f\n", ($tot_kerry_os_votes_raw / $tot_votes) * 100; printf "Adjusted percent to Kerry from OS counties: %3.1f\n", ($tot_kerry_os_votes_adjusted / $tot_votes) * 100; printf "Total votes for Kerry, raw: %d\n", $tot_kerry_os_votes_raw + $tot_kerry_et_votes; printf "Total votes for Kerry, adjusted: %d\n", $tot_kerry_os_votes_adjusted + $tot_kerry_et_votes; printf "Total percent to Kerry, raw: %3.1f\n", (($tot_kerry_os_votes_raw + $tot_kerry_et_votes) / $tot_votes) * 100; printf "Total percent to Kerry, adjusted: %3.1f\n", (($tot_kerry_os_votes_adjusted + $tot_kerry_et_votes) / $tot_votes) * 100; } # **************************************************************** do_votes ();