Introduction to JavaScript Voting Program (Version 021)I've recently rewritten my 2010 voting program (originally written in Java) as a JavaScript program (see previous post for download). The interface is somewhat similar to the original, but it has been improved in a number of ways. Here's a screen shot of what it looks like when you first open it:
- V21_Just_Opened.png (62.87 KiB) Viewed 6558 times
If you don't change anything and click on the "Calculate Results" button, you'll find that those votes select "A" as the winner. That result would be based on the "Simple Plurality" default voting method setting. But if you change the "Simple Plurality" setting to "Condorcet" and click "Calculate Results", you'll find that those same votes will select "C" as the winner. So what's up? How can the same ballots produce different results? That's what this post is all about. Please read on ...
Before getting into the details of the voting methods, let's first talk about votes - or more precisely, ballots. When we "vote" on anything we can use many different means to express our desires. In some situations, people can vote by voice ("yeas and nays", for example) and the loudest result is the winner. In other cases, people might vote by raising their hands or moving to one side or another of the room. In this case, we're going to focus on votes cast with written (paper or electronic) ballots. Let's start with an example.
Let's say there are 4 candidates named (conveniently enough) "A", "B", "C", and "D". And let's say that there are 5 voters (who don't have to be named, but we'll call them "Voter 1" through "Voter 5" for easy reference). Then we would expect to get 5 different ballots (one from each voter). But what would be on those ballots? In our typical plurality voting system, each ballot would contain just one name ... the name of each voter's favorite candidate. That might look like this:
Voter 1's ballot: | C |
Voter 2's ballot: | A |
Voter 3's ballot: | B |
Voter 4's ballot: | A |
Voter 5's ballot: | D |
Now if that's all the information that we have, then we can see that there are 2 votes for "A", 1 vote for "B", 1 vote for "C", and 1 vote for "D". So we would generally say that "A" wins because there are more votes for candidate "A" than for any other candidate. But does that mean that "A" is really the favorite choice according to these voters? Think about it carefully before you commit to an answer.
What if candidates "B" and "D" were to drop out of the race so that the voters could only choose between "A" and "C". Would "A" still win in that case? It turns out that we don't know because we don't know how "Voter 3" and "Voter 5" would have voted without candidates "B" and "D" on the ballots. In other words, these "single favorite candidate" ballots don't have enough information to tell us what the voters would do if an election were held between "A" and "C" alone.
So maybe we could expand our ballots to let voters list their choices in order of preference? It turns out that's called a "
ranked voting" system where voters can list multiple candidates and show which ones they prefer. Wikipedia shows 3 different examples of ranked voting (or ranked preference) ballots:
- Ranked_Voting_Ballots_Wikipedia.png (83.74 KiB) Viewed 6554 times
With ranked preference ballots, voters can express their preferences among
all candidates, so if one drops out, their votes will still show their preference among the remaining candidates. This also suggests the possibility that voters could choose their favorite candidates first without worrying whether those candidates had much chance of winning.
With those thoughts in mind, let's take a look at our simple "A", "B", "C", "D" election. Let's say that we allow each voter to cast a ballot where they can list all 4 candidates in their order of preference (with their first choice on the left). Here's what those ballots might look like showing the voters' full preferences among all the candidates:
Voter 1's ballot: | C | B | A | D |
Voter 2's ballot: | A | C | B | D |
Voter 3's ballot: | B | C | A | D |
Voter 4's ballot: | A | D | C | B |
Voter 5's ballot: | D | C | B | A |
Their first choices haven't changed. "Voter 1" would still vote for "C" first, and "Voter 2" would still vote for "A" first, and so on. But now we can see how they would vote if their first choice (or second choice or third choice) wasn't available. That brings us back to our earlier question:
What if candidates "B" and "D" were to drop out of the race?Well, let's see. We can just erase candidates "B" and "D" from the ballots leaving only "A" and "C":
Voter 1's ballot: | C | | A | |
Voter 2's ballot: | A | C | | |
Voter 3's ballot: | | C | A | |
Voter 4's ballot: | A | | C | |
Voter 5's ballot: | | C | | A |
So who would win now? Well, here's what we can see from those ballots:
Voter 1 would prefer "C" before "A".
Voter 2 would prefer "A" before "C".
Voter 3 would prefer "C" before "A".
Voter 4 would prefer "A" before "C".
Voter 5 would prefer "C" before "A".
In other words, if we compress the ballots to remove the empty positions we have this:
Voter 1's ballot: | C | A |
Voter 2's ballot: | A | C |
Voter 3's ballot: | C | A |
Voter 4's ballot: | A | C |
Voter 5's ballot: | C | A |
It's clear now, that in an election between "A" and "C", that the voters would prefer ... "C"!!
Now that's a bit odd. We've found that if we only let each voter choose their single favorite candidate (and no others), then the winner might be a candidate ("a" in this case) that could be defeated by some of the other candidate(s) ("c" in this case) in one-on-one runoff election(s). That's not good. In fact, it's very bad because the newly elected candidate could be immediately challenged as illegitimate ... and that challenge would stick. It's also easy to show cases (see below) where one candidate might defeat every other candidate by factors of 10 to 1 (or more) and yet still lose the election to one of those other less preferred candidates if the wrong voting system is used.
That brings us to what is known as the "
Condorcet Winner Criterion":
Wikipedia wrote:The candidate who wins a majority of the vote in every head-to-head election against each of the other candidates – that is, a candidate preferred by more voters than any others – is the Condorcet winner
In other words, the "Condorcet Criterion" says that the winner of any election should NEVER EVER be defeatable in a runoff against any loser of that same election using the same ranked ballots. A simple plurality election (where each voter only picks one candidate) fails to meet the Condorcet Criterion in all cases because there are examples (such as this one) where a candidate who lost the election would actually defeat the winner in a one-on-one runoff election - using the same ballot preferences!! That's a pretty serious flaw because you can end up getting a candidate that almost no one wants. For example, one of the cases in the previous program shows an election where one of the challengers would defeat the plurality winner by a vote of 11 to 3 in a one-on-one election!! This happens because consensus candidates can sometimes get fewer votes than factional candidates ... especially when there are many different factions.
The only rub with the Condorcet Criterion is that sometimes there isn't any single candidate who can defeat all others in a one-on-one basis. That's somewhat like the "Rock Paper Scissors" case where each candidate can be defeated by at least one other candidate. In that case, the winner can be chosen by some other predetermined means (plurality winner, instant runoff winner, range winner, candidate registration date, coin toss, etc). But by requiring that the winner pass the Condorcet Criterion FIRST, a voting system can help ensure that the winner could not be defeated by a losing challenger in a one-on-one runoff election. It's that simple.
So far, we've only allowed our candidates to be listed in strict order of preference. But sometimes a voter might find two candidates equal. It turns out that can be expressed by putting an equal sign ("=") between the two (or more) candidates that are considered to be equal.
In this example, "Voter 4" might have felt that candidates "A" and "D" were really equal, but had entered them on the ballot as "A D C B" (see earlier example). That ballot could have been written as "A=D C B" to express that "A" and "D" were equal first choices followed by C and B. This can be helpful in a crowded election where a voter might not care about the differences between a number of candidates. In that case, they could all be listed as being equally bad in the last place:
"C B D A=E=F=G=H"
As a shorthand notation, any missing candidates can be considered as being equally unfavorable. So that same ballot could be expressed by listing the favorites in order (without the "tied for last place" candidates):
"C B D"
It turns out that the equals sign can be used to express equality of candidates at any level of preference. This can amount to "groups" of candidates being listed by preference (extra space added for emphasis):
"C=B D A=E=F G=H"
In that ballot, the voter wanted either "C" or "B" as their first choice, "D" as their second choice, either "A", "E", or "F" as their third choice, and either "G" or "H" as their last choice.
That pretty much explains the ballots in the program except for one last feature. There are some voting systems (such as "Range" voting) that require scores to be assigned to the candidates. The scores typically have a predefined range (such as 0 to 10, or 0 to 100). These can be expressed as numbers in square brackets following each candidate in the list. Here's the same example that we've been using with numeric scores ranging 0 to 100 following each candidate:
C[100] B[75] A[50] D[25]
A[100] C[75] B[50] D[25]
B[100] C[75] A[50] D[25]
A[100] D[75] C[50] B[25]
D[100] C[75] B[50] A[25]
When numbers are given for
every candidate, the order doesn't matter. So the previous ballot (where candidates are listed in ranked in order of 100, 75, 50, 25) is equivalent to this ballot (where the candidates are listed alphabetically as "A", "B", "C", "D"):
A[50] B[75] C[100] D[25]
A[100] B[50] C[75] D[25]
A[50] B[100] C[75] D[25]
A[100] B[25] C[50] D[75]
A[25] B[50] C[75] D[100]
Note, however, that if you don't explicitly assign numbers to
every candidate when using "Range" voting, the program will automatically generate "reasonable" numbers (according to each candidate's ranking order) for candidates without numbers. But those auto-generated numbers defeat the purpose of the Range Voting method. The auto-generated numbers also do not reflect the strengths and weaknesses of Range Voting. Indeed, when using auto-generated numbers, the "Range" option isn't really using the "Range" method because the numbers are being calculated by an algorithm not defined by the Range Voting method.
Ballot Area DescriptionThe ballot area is the large text entry box in the upper left corner of the page. The "Notes" section (to the right of the ballot area) describes the expected format of the ballots in the ballot area:
- Each line is one ballot cast by one voter.
- Candidate choices are separated by spaces.
- The first choice is listed first (on the left).
Simple example ballot: b d a c - Equal choices are expressed with "=".
Ballot with an equal choice: b d=a c - Numeric scores may be entered inside brackets.
Ballot with numeric scores: b[95] d[70] a[70] c[5] - Voting methods use ordering and scores differently.
You can type ballots in directly. You can copy and paste ballots from other sources. You can select and load from among the predefined examples.
Examples Selector DescriptionThe Examples selector selects from among the predefined examples. The actual example isn't loaded into the Ballot Area until the "Load Example" button is clicked.
There are a number of examples currently listed, and some of them were intended to replicate the examples coded into the Java version (they typically start with the name "Java"). The example listed as "Examples" is the same one described above with four candidates and five voters. The "Rock Paper Scissors" example shows a case where three candidates
should tie (although the Instant Runoff's random elimination will produce a non-tied result).
Hidden Consensus ExampleThe "Hidden Consensus" example demonstrates a strong consensus candidate ("a") running against a number of "factional" candidates ("b", "c", "d", "e", "f", and "g"). Simple Plurality selects a winner of "g" because there are 3 voters (out of 14) who listed candidate "g" as their first choice. So plurality selects a winner of "g" even though 11 out of 14 voters expressed a preference for "a" over "g". In fact, "g" was the last choice for 11 out of 14 voters. Similarly, the Instant Runoff method eliminates the consensus candidate "a" in the first round because the consensus candidate is not strongly endorsed by any of the factions. So Instant Runoff selects a winner of "b" even though 12 of the 14 voters expressed a preference for "a" over "b". Here are the ballots:
a b c d e f g
b a c d e f g
b a c d e f g
c a b d e f g
c a b d e f g
d a b c e f g
d a b c e f g
e a b c d f g
e a b c d f g
f a b c d e g
f a b c d e g
g a b c d e f
g a b c d e f
g a b c d e f
Here are the results from the Condorcet method:
- Consensus_Candidate_Condorcet.png (15.68 KiB) Viewed 6550 times
The leftmost table (above) shows the original ballots. The remaining tables ("a v b", "a v c" ... "a v g") show the one-on-one comparisons of candidate "a" with each of the other candidates ("b", "c", "d", "e", "f", "g"). The text below each table shows the vote count by which candidate "a" defeats each of the other candidates:
a vs b: | 12 to 2 |
a vs c: | 12 to 2 |
a vs d: | 12 to 2 |
a vs e: | 12 to 2 |
a vs f: | 12 to 2 |
a vs g: | 11 to 3 |
Java Strong 2nd 2 ExampleThe "Java Strong 2nd 2" example is another case where the Condorcet winner ("A") would easily defeat every other candidate (by 5 votes to 2 votes each) even though the Simple Plurality and Range methods pick other candidates.Here are the ballots:
A[9] B[4] C[3] D[2]
B[9] A[4] D[3] C[2]
B[9] A[4] D[3] C[2]
C[9] A[4] B[3] D[2]
C[9] A[4] B[3] D[2]
D[9] A[4] B[3] C[2]
D[9] A[4] B[3] C[2]
Here are the results from each of the 4 voting methods:
Method | Resulting Winner(s) |
Simple Plurality | tie between B, C, and D |
Range | B |
Instant Runoff | B |
Condorcet | A |
Note that the Condorcet method is the ONLY one to pick candidate "A" as the winner. Here are the results of running each of the other candidates against the Condorcet winner ("A") in one-on-one elections:
- Condorcet_Beats_All_Others_5_to_2.png (10.2 KiB) Viewed 6549 times
Load Example Button DescriptionThe Load Example button loads the currently selected example into the Ballot Area.
Voting Methods DescriptionThe voting methods selector selects the voting method that will be used when the "Calculate Results" button is clicked. The current program supports 4 different voting methods:
- Simple Plurality (only the first choice is used)
- Range (uses a sum of scores for each candidate)
- Instant Runoff (sequential evaluation and discarding to arrive at a majority)
- Condorcet (winner must defeat all others in one-on-one pairings)
Calculate Results Button DescriptionThe Calculate Results button computes the result of the ballots in the Ballot Area using the currently selected Voting Method in the Voting Method selector. The results are displayed below the "Calculate Results" button. The details of the displayed results will likely differ for each voting method.