PHYCS 3730/6720
Assignment 06

Fall Semester 2006

(return to Assignments page)

Problem 1.

During a U.S. presidential election, a million votes in some state are cast for two opposing candidates. Suppose that voters are slightly less likely to vote for one candidate than for the other. Specifically, assume that on average, 49.9% of voters will choose the less favored candidate.

To answer these questions, assume that the votes for the less-favored candidate follow a binomial distribution such that the chance of the candidate getting exactly k votes out of a total of n votes is

prob(k;n,p) = n!/[k!*(n-k)!] * p^k * (1-p)^(n-k) 
where p is the probability that any individual voter will vote for this candidate (i.e., p=0.499). This equation may be difficult to solve numerically, owing to the large numbers involved. To mitigate this difficulty, here is some code (in which a function is defining) to estimate the probability that a candidate, who on average will get a fraction p of the votes, gets specifically k votes out of a voting population of size n:
double binomial_pdf_approx(const double p, const int n, const int k) 
// this is a gaussian approximation to a binomial probability 
// of getting exactly k occurrences of some event (whose likelihood
// is p (between 0 and 1)) in n independent trials.
// THUS THIS FUNCTION RETURNS "prob(k;n,p)" or at least a good 
// approximation for large n, as described in the assignment.

  const double pi = acos(-1.0); 
  double x = k-n*p; 
  double x2 = x*x;
  double var = n*p*(1-p); 
  return (exp(-x*x/2./var)/sqrt(2*pi*var)); 
This is an estimate only, but it should be very good for p near 0.5 and n=1000000. I encourage you use it to solve this problem.

Write a C++ code which takes input from stdin (e.g., via C++'s cin) to specify p, the likelihood that one of the candidates will win on average. Have your code print out the followin statements:

 probability of tie: XXX
 probability of win: YYY
(XXX, YYY are numbers--you should find them to be in the range of 0.00001 to 0.1 when p is set to 0.499).

Note: this probabilistic interpretation of voters does not mean that voters themselves necessarily act in a random fashion. Instead, probabilities are assigned because the myriad influences on individual choices prevent us from knowing much more than how voters behave on average, as gleaned from surveys and polls. In this sense the situation is similar to a coin-flipping experiment, wherein unpredictable processes influence the outcome and we only know (if the coin is a fair/"honest" one) that on average, we'll get 50% heads (p=0.5 in the above equation). Play around with different p values. I think it is amazing how finely tuned p must be for there to be a close election!

U.S. National Archives electoral college FAQ pages contain some interesting data on the functioning of our electoral process.

bcb 4-Oct-06.