Princeton Election Consortium

Innovations in democracy since 2004

Outcome: Biden 306 EV (D+1.2% from toss-up), Senate 50 D (D+1.0%)
Nov 3 polls: Biden 342 EV (D+5.3%), Senate 50-55 D (D+3.9%), House control D+4.6%
Moneyball states: President AZ NE-2 NV, Senate MT ME AK, Legislatures KS TX NC

An online app to diagnose partisan gerrymandering

June 26th, 2016, 11:30pm by Sam Wang

Today, Mark Tengi and I release an online application to help diagnose whether partisan gerrymandering is evident in a set of election results. The application is intended for the use of judges, clerks, litigants, and others who want a statistically well-founded and easily understood test for partisan asymmetry. The Supreme Court has suggested that partisan asymmetry may form a basis for a manageable standard for partisan gerrymandering, but they have not settled upon a specific standard. I hope to fill that gap.

The website,, implements three tests for partisan gerrymandering as described in an article I published last week in the Stanford Law Review. These proposed standards recently won a prize in Common Cause’s 2016 contest to define a partisan gerrymandering standard. The website is in beta-test, and I welcome your comments. If you detect a problem, email the output PDF if possible.

My three standards have two key features: (1) they implement the principle of partisan asymmetry, as others have also recently done; and (2) they do so without the use of any consideration of maps.

The second point is quite important. Most people who get exercised at the offense of gerrymandering may gravitate toward examination of a district’s convoluted boundaries. Although this is perfectly reasonable, existing precedents and consequences of the Voting Rights Act have conspired to make consideration of boundaries a tough sell with courts – at least for statewide partisan gerrymandering. Let me explain.

The word “gerrymandering” encompasses two kinds of offense.

First, an individual district can be drawn to give an overwhelming advantage to one party or candidate. To paraphrase legal scholar George Berman, this consists of a legislator choosing his/her voters, and not the other way around. The Supreme Court has said that districts should be “compact.” However, they have also allowed that compactness could be geographic…or community-based. This means that a strange shape is permissible. In addition, Section 2 of the Voting Rights Act (as well as the late Section 5, which was killed by the Shelby County v. Holder decision) mandated the creation of districts that empowered specific communities of interest such as blacks or Hispanics. Since the 1970s, district boundaries have gotten more complicated, probably because of this mandate. So an argument that a district’s boundaries are convoluted can be countered with the defense that it was necessary and/or legally permissible.

The second kind of gerrymander is partisan: the construction of an entire statewide scheme, composed of single-district gerrymanders, that gives a net overall advantage to one party. Here, the consideration of a single district’s boundaries is again ambiguous. Why? Because any individual district can be part of a statewide scheme that is neutral overall, or helps one party. For example, if all districts in a state were drawn to be 60-40 for either party, the overall effect would not give either side an advantage. But a party could pack most of its opponents into a tiny number of 80-20 districts, and get more 60-40 districts for itself. A given 60-40 district could potentially look the same in both schemes. So an argument based on the properties of single districts may not be logically watertight.

I therefore suggest that any standard for diagnosing partisan gerrymandering should consider all districts in a state as a whole. Apprehending lots of data at once in a single measure is the raison d’être for the field of statistics.

The online app calculates three statistical quantities:

  1. The presence of lopsided wins for one party but not the other. This calculation uses a two-sample t-test, perhaps the most widely used statistical test in the world.
  2. The construction of consistent wins for one party. This can be measured two ways: by the mean-median difference to detect overall skewness, or a chi-squared test to test whether one party’s wins are too consistent to have occurred by chance.
  3. The number of seats that a party has gained in excess of what would arise naturally, given national population-clustering patterns. This is done by calculating 1,000,000 hypothetical “fantasy delegations” to see what would arise if redistricters were not seeking a systematic statewide advantage.

The first two tests can be done pretty easily; one objective of makes it fairly painless to calculate them. In addition, the website gives you the ability to calculate the third test at the press of a button. As it turns out, a map-less approach to calculating fantasy delegations can be done extremely fast. One million delegations can be simulated in well under a minute.

If you want to consider specific district boundaries, there has been lots of effort in that direction. One example is a random-map-drawing approach taken by Jowei Chen and John Rodden. Another is the first-place winner in this year’s Common Cause contest, by Wendy Tam Cho and Yan Y. Liu. These approaches go into great geographic detail, and are complementary to my proposal. However, they have the disadvantage that a judge would have difficulty applying them without the help of an expert witness. My hope is to place a tool into the hands of a judge that he or she could apply directly – even by jotting it in the margin of a brief.

I hope one or more of these standards will find a receptive audience at the Supreme Court in the near future. No matter whose standard is adopted, it will be a substantial improvement over the current limbo. You can read more about that limbo in my article.

Tags: House · Redistricting

21 Comments so far ↓

  • counsellorben

    I am unclear on the “lopsided margins” test. Should this measure include uncontested races? I believe this understates the lopsidedness of wins in contested races.

    For example, running the online app for PA 2014 House races shows significant clustering for all Republican victories. Running a t-test excluding the uncontested races at gives p < 0.05. Including the uncontested races gives p ~ 0.21.

    It appears to me that including uncontested races in this measure understates the effect of the gerrymandering in PA.

    • Sam Wang

      I guess we could have an option to omit uncontested races.

      My view is that uncontested races must be considered in some way, since a race is usually uncontested because the winning party is strong in that district. Currently, I deal with this by assuming that uncontested races were won with X% of the vote, where X is defined by the user. The default value is X=75%. For Pennsylvania, that assumption leads to p=0.035 for the lopsided-margins test.

      An aside: for Republican-drawn gerrymanders, one would expect these tests to show less extreme results in 2014 than in 2012. The point of a partisan gerrymander is to build a defense against an election that favors one’s opponents. Since 2014 heavily favored the GOP, these advantages should appear to be smaller than in 2012.

    • counsellorben

      I re-ran the 2014 PA House results to make sure. It appears that there is a bug in the lopsidedness test in the app, as it returns a result that the lopsidedness is not statistically significant. It looks as if the calculator is using 100% for uncontested results, instead of the selected default 75%.

    • Sam Wang

      It seems to be working okay. However, we may be using different assumptions about the type of test. I have changed these now.

      Previously, I used unequal variances, two-tailed.

      Now, I assume equal variances, one-tailed. Specifically, in MATLAB, ttest2(f1,f2,’tail’,’left’,’Vartype’,’equal’), in cases where the mean of f1 is greater than f2. This corresponds to the Excel function =TTEST(range1,range2,1,2)

      Probably I should have a spreadsheet version so people can see the process for themselves.

    • counsellorben

      I see that the app has been adjusted to the new test, and the lopsidedness results are in close agreement with my manual calculation. Thank you for this tool. I look forward to a time when you present such evidence in court as an expert witness.

  • Olav Grinde

    This is brilliant! I really do hope your work will have an impact on judges that decide such cases.

    Question: Do your proposed gerrymandering tests require before and after data – or can “lopsided margins” develop naturally over time (and, if so, then to what extent)?

    • Sam Wang

      It would be best to compare the statistics before and after redistricting. The presence of a jump immediately following redistricting is a clear tell that the asymmetry arises from the redistricting, and not from population clustering-based effects.

      That said, sometimes the map is already gerrymandered before redistricting, in which case one would have to look at the particulars of the situation.

  • Scott

    Sam – this is fabulous. If successful, you will have gone a long way toward un-disenfranchising millions of voters in this great democracy of ours. In my opinion, a Pulitzer-worthy accomplishment.

  • Matt McIrvin

    Your banner is a map of my neighborhood!

  • TJ Baker

    A simple suggestion for usability: add a loading spinner on the button while results are being calculated.
    How to do it with Bootstrap:

  • Marc Sullivan

    Thank you for your very excellent work! I am very proud of you!

  • happyjack27

    Here’s a better way to measure gerrymandering:

    and here’s a sortable list based on that and another score:

  • Amitabh Lath

    Hi Sam, I was trying out the app with the “Enter data manually” option. I created my own state (State of Amit) and populated it with 4 districts. I filled it in symmetrically (45/55, 40/60, 60/40, 55/45) and let it rip.

    I expected the symmetry would lead to the algorithm showing no gerrymandering but instead:

    The average Democratic share of the two-party total vote was 0.0% (raw)The average Democratic share of the two-party total vote was 0.0% (raw)The average Democratic share of the two-party total vote was 50.0% (raw).

    Analysis of Intents: Lopsided wins by one side.

    Obviously I’m using it wrong. What I am I not setting properly?

    Reply: Sorry, that was a mistake. The Python code takes your custom data and passes it to a MATLAB routine. The MATLAB routine was looking for the wrong data format. It should work now.

  • Lorem

    A couple user friendliness suggestions:

    – When you select a year in Step 1, Option 1, it should probably propagate down to Step 3 and set the same year there.

    – It would be nice if you had a button to automatically fill in values for some well-known gerrymandered race and another for a non-gerrymandered one. That way, the beginning user could quickly see what kind of results to expect for uncontroversial examples of each type.

    • Lorem

      Oh, I got the “At a national level, the standard deviation is NaN%. ” bug.

      Parameters: year=2012 states=16 yearbaseline=1912 statebaseline=1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 imputeduncontested=0.650000 symm=1 statelabel=Kansas outputfilename=2016-06-28T20:39:55.308650


      Reply: Good catch on a scenario that is not frequently queried: single-party dominance, few districts. This should be fixed now. Note that it is challenging to reach statistical significance in this example since there are so few districts (four).

  • Kevin

    It seems to me there are two types of gerrymanders: those which advantage one party at the expense of another, and those which protect incumbents from challengers. In Washington state, we have a redistricting commission law which requires at least some level of bipartisan consensus, so the resulting maps do not have a heavy partisan skew (there is a 5-member commission consisting of 2Rs and 2Ds appointed by the parties, 1 nonvoting chair agreed by both parties, with 3 of 4 votes required to adopt a map). There is a tendency, however, for the parties to collude to protect their incumbents.

    I believe your method allows maps to be drawn to create safe districts, as long as the the advantages are symmetric to each party. Do the court decisions address this kind of gerrymander? Even if this is a problem, it strikes me as a significant upgrade from the current situation.

    • Sam Wang

      Based on my reading of precedents, single-district gerrymanders are allowed. In the domain of partisan gerrymanders (i.e. statewide), the Supreme Court has specifically called out partisan asymmetry, which would not cover a bipartisan gerrymander.

      If bipartisan gerrymanders ever became justiciable, a modified version of my Second Test of Intents could be used to detect such a situation using the chi-square test.

  • Matt McIrvin

    Mass media now freaking out about an outlier Quinnipiac poll with Clinton +2 nationally. The more things change…

    Looks like you put up your 2016 general-election operation just in time.

  • rachel Findley

    Is there a big push to take back state legislatures now through 2020 to make the legislatures better reflect the composition of the citizenry?

  • TJ Baker

    I know that gerrymandering has been done by both the Democratic and Republican parties over the years, but I’m curious if there’s some way to see which has abused the process and benefited by it more. If I were to guess I’d say it’s benefited Republicans more often than Democrats, but is there some way to validate that?

    This is a question for those of you with bigger brains than me :)

    • Sam Wang

      Yes. This is a principal goal of the standards of gerrymandering that I have developed. Go to, use the application, and examine the report. The Analysis of Effects quantifies the excess number of seats that is likely to have been won by partisan redistricting.

      Of course, this application could easily be used to calculate the total effects of gerrymandering across all states and many elections. I should do that soon.

Leave a Comment