The 2016 presidential contest was awash with charges that the fix was in: Republican Donald Trump repeatedly claimed that the election was rigged against him, while Democrats have accused the Russians of stacking the odds in Trump’s favor.

Less attention was paid to manipulation that occurred not during the presidential race, but before it – in the drawing of lines for hundreds of U.S. and state legislative seats. The result, according to an Associated Press analysis: Republicans had a real advantage.

The AP scrutinized the outcomes of all 435 U.S. House races and about 4,700 state House and Assembly seats up for election last year using a new statistical method of calculating partisan advantage. It’s designed to detect cases in which one party may have won, widened or retained its grip on power through political gerrymandering.

The analysis found four times as many states with Republican-skewed state House or Assembly districts than Democratic ones. Among the two dozen most populated states that determine the vast majority of Congress, there were nearly three times as many with Republican-tilted U.S. House districts.

Traditional battlegrounds such as Michigan, North Carolina, Pennsylvania, Wisconsin, Florida and Virginia were among those with significant Republican advantages in their U.S. or state House races. All had districts drawn by Republicans after the last Census in 2010.

The AP analysis also found that Republicans won as many as 22 additional U.S. House seats over what would have been expected based on the average vote share in congressional districts across the country. That helped provide the Republican with a comfortable majority over Democrats instead of a narrow one.

Republicans held advantages heading into the 2016 election. They had more incumbents, which carried weight even in a year of “outsider” candidates. Republicans also had a geographical advantage because their voters were spread more widely across suburban and rural America instead of being highly concentrated, as Democrats generally are, in big cities.

JUST DO THE MATH

Yet the data suggest that even if Democrats had turned out in larger numbers, their chances of substantial legislative gains were limited by gerrymandering.

“The outcome was already cooked in, if you will, because of the way the districts were drawn,” said John McGlennon, a professor of government and public policy at the College of William & Mary in Virginia who ran unsuccessfully for Congress as a Democrat in the 1980s.

A separate statistical analysis conducted for AP by the Princeton University Gerrymandering Project found that the extreme Republican advantages in some states were no fluke. The Republican edge in Michigan’s state House districts had only a 1-in-16,000 probability of occurring by chance; in Wisconsin’s Assembly districts, there was a mere 1-in-60,000 likelihood of it being random, the analysis found.

The AP’s findings are similar to recent ones from the Brennan Center for Justice at the New York University School of Law, which used three statistical tests to analyze the 2012-2016 congressional elections. Its report found a persistent Republican advantage and “clear evidence that aggressive gerrymandering is distorting the nation’s congressional maps,” posing a “threat to democracy.” The Brennan Center did not analyze state legislative elections.

The AP’s analysis was based on a formula developed by University of Chicago law professor Nick Stephanopoulos and Eric McGhee, a researcher at the nonpartisan Public Policy Institute of California. Their mathematical model was cited last fall as “corroborative evidence” by a federal appeals court panel that struck down Wisconsin’s state Assembly districts as an intentional partisan gerrymander in violation of Democratic voters’ rights to representation.

A dissenting judge ridiculed the Wisconsin ruling for creating a “phantom constitutional right” of proportional political representation. Wisconsin’s attorney general has argued on appeal that the ruling could “throw states across the country into chaos.”

Although judges have commonly struck down districts because of unequal populations or racial gerrymandering, the courts until now have been reluctant to define exactly when partisan map manipulation crosses the line and becomes unconstitutional. The U.S. Supreme Court has agreed to hear arguments on the Wisconsin case this fall. If upheld, it could dramatically change the way legislative districts are drawn across the U.S. – just in advance of the next round of redistricting after the 2020 Census.

But if partisan gerrymandering “goes unchecked, it’s going to be worse – no matter who’s in charge,” said Sam Wang, director of the Princeton Gerrymandering Project.

‘PACKING’ AND ‘CRACKING’

Throughout U.S. history, Democrats and Republicans alike have been accused of drawing political districts in ways that favored their own interests.

It typically occurs in one of two ways:

n “Packing” a large number of voters from the opposing party into a few districts to concentrate their votes.

n “Cracking,” in which the majority party spreads the opposing party’s supporters among multiple districts to dilute their influence.

Another way of explaining it: When the party controlling the redistricting process sets out to draw lines, it has detailed information about the number of supporters the opposing party has, and where they reside. It sets out to shape districts so its opponents’ votes are wasted – spreading them out in some places so they are unlikely to win, and compacting them in others so they have far more votes than they need for victory. Both methods allow the party already in power to translate its votes into a greater share of victories – or, put another way, to be more efficient with its votes.

The “efficiency gap” formula developed by Stephanopoulos and McGhee creates a way to measure whether gerrymandering has helped a political party enlarge its power.

The formula compares the statewide average share of the vote a party receives in each district with the statewide percentage of seats it wins, taking into account a common political expectation: For each 1 percentage point gain in its statewide vote share, a party normally increases its seat share by 2 percentage points. So a party that receives 55 percent of the statewide vote could expect to win 60 percent of the legislative seats.

Michigan provides a good example of how the formula works.

Last fall, voters statewide split their ballots essentially 50-50 between Republican and Democratic state House candidates. Yet Republicans won 57 percent of the House seats, claiming 63 seats to the Democrats’ 47. That amounted to an efficiency gap of 10.3 percent in favor of Michigan’s Republicans, one of the highest advantages among all states.

That also marked the third straight Michigan House election since redistricting with double-digit efficiency gaps favoring Republicans. Stephanopoulos said such a trend is “virtually unprecedented” and indicative of a durable Republican advantage.

Republicans controlled both chambers of the Michigan Legislature, as well as the governor’s office, when the maps were redrawn in 2011.

As lawmakers prepared to vote on those maps, former Democratic state Rep. Lisa Brown says a top Republican lawmaker showed her two potential maps. One kept her in the same district while the other shifted her neighborhood into a predominantly Republican district to the east.

Brown said she was offered a deal: Vote with Republicans or get stuck with the less-favorable map. She declined.

As a result, Brown said, “I was gerrymandered out of my district.”

Instead of opting for a re-election campaign, she ran for Oakland County clerk, a position she still holds.

DETAILS OF THE DISTRICTS

The Michigan House redistricting was led in 2011 by then-state Rep. Pete Lund, a Republican who now is the Michigan director of Americans for Prosperity, a conservative interest group backed by billionaire industrialists Charles and David Koch. Lund told the AP that he doesn’t remember the details of his redistricting conversation with Brown and doesn’t recall trying to draw anyone out of a district.

He said if Michigan’s House districts appear to have any “distortion,” it’s because Democrats are naturally concentrated in the state’s urban areas and because Republicans tried to comply with the federal Voting Rights Act by ensuring racial minorities have large enough concentrations to elect a representative of their choice.

Lund denied gerrymandering districts to favor Republicans, instead blaming Democrats for their own losses.

“The Democrats don’t know how to run campaigns; they’re horrible at it. We beat them right and left,” he said.

State House Minority Leader Tim Greimel stepped down from his leadership post after his party failed to cut into the Republican majority in 2016.

“Is it truly impossible for Democrats to win a majority in the statehouse with the districts drawn the way they are? I don’t know,” he said. “But it certainly makes it far more difficult – and that’s the purpose of gerrymandering.”

HEXED IN THE CITY

Experts agree with parts of both Lund’s explanation and Greimel’s. The clustering of Democrats in urban areas creates some “unintentional gerrymandering” that works against them, said Jowei Chen, an associate political science professor at the University of Michigan.

“But overt partisan gerrymandering is certainly a big part of the explanation, as well,” both in Michigan and elsewhere, Chen said.

The current Republican supremacy in many states traces to the 2010 elections, when a Republican wave two years after Democrat Barack Obama was elected president allowed the party to grasp full control of 25 state legislatures and 29 governorships. That was just in time to carry out the mandatory duty of redistricting based on the 2010 Census.

Since then, the Republican dominance has grown to 33 legislatures and 33 governorships – doubling the totals for Democrats – as well as both chambers of Congress and the presidency.

Acknowledging Republican dominance in many states, Democrats recently launched an initiative led by former Attorney General Eric Holder and aided by Obama that is intended to better position the party for the redistricting process after the 2020 Census.

Their three-pronged approach will target key state races, support legal challenges to current maps and pursue ballot initiatives to change the redistricting methods in some states.