Democrat Doug Jones’s stunning victory in Alabama on Tuesday should send a shiver down the spine of GOP elected officials everywhere. Yes, Jones likely would have lost the special election for a U.S. Senate seat had his Republican opponent, Roy Moore, not been an extremely flawed candidate. But Moore’s defeat is part of a larger pattern we’ve seen in special elections so far this year, one in which Democrats have greatly outperformed expectations. If history holds (and, of course, it may not), the special election results portend a Democratic wave in 2018.

There have been more than 70 special elections for state and federal legislative seats in 2017 so far. We’re interested in each of those contests, naturally, but we’re also interested in what the races tell us about the national political environment. To measure that, we compared each special election result to the partisan lean of that state or district — how we’d expect the state or district to vote in a neutral environment (i.e. an environment in which a Democratic and Republican presidential candidate would tie 50-50 nationally).

So, in a neutral environment, we’d expect each special election result to match the partisan lean of that state or district. Instead, Democrats have outperformed the partisan lean in 74 percent of these races.

The Democratic margin has been 12 percentage points better, on average, than the partisan lean in each race. Sometimes this has resulted in a seat flipping from Republican to Democratic (e.g. in the Alabama Senate face-off on Tuesday or Oklahoma’s 37th state Senate District contest last month). Sometimes it has meant the Democrat barely lost a race you wouldn’t think a Democrat would be competitive in (e.g. in South Carolina’s 5th Congressional District in June). Sometimes it’s merely been the case that the Democrat won a district by an even wider margin than you’d expect (e.g. in Pennsylvania’s 133 House District last week).

The point is that Democrats are doing better in all types of districts with all types of candidates. You don’t see this type of consistent outperformance unless there’s an overriding pro-Democratic national factor.

And to be clear, although there have been more special elections on the state level, the pro-Democratic environment is quite clear if you look only at federal special elections. There have been seven special U.S. House and U.S. Senate elections so far this year. The Democrats have outperformed the partisan lean in all of them.

Special elections for the U.S. House and Senate in 2017 2017 congressional special election results vs. districts’ partisan lean based on recent presidential results DATE SEAT PARTISAN LEAN DEM. MARGIN DEM SWING 4/4 California 34th* D+69 +87 +18 4/11 Kansas 4th R+29 -6 +23 5/25 Montana At-Large R+21 -6 +15 6/20 Georgia 6th R+9 -4 +6 6/20 South Carolina 5th R+19 -3 +16 11/7 Utah 3rd R+35 -32 +3 12/12 Alabama Senate R+29 +2 +30 Average +16 *Democratic and Republican vote shares are for all candidates of each respective party. The partisan lean compares the district’s or state’s vote in the last two presidential elections to the nation’s, with the 2016 election weighted 75 percent and the 2012 election weighted 25 percent. SOURCES: SECRETARIES OF STATE, DAILY KOS ELECTIONS

As you might expect, Tuesday’s Alabama result was the Democrats’ best result versus partisan lean. Still, the average Democrat has outperformed the baseline by 16 percentage points. (The median is 16 points, too, so it’s not just one outlier moving the average.) Before Alabama, Democrats’ overperformance hadn’t resulted in a flipped seat, but it was probably just a matter of time. That’s why I’ve been emphasizing looking at the shift in the margin and not just wins/losses in order to understand the national environment.

The average swing in special federal elections has forecast midterm results fairly well since the 1994 cycle. We can see this below by looking at the average swing in special federal elections preceding each midterm cycle versus the national House vote in that midterm.

Special elections have tended to predict midterm outcomes Swing in average special congressional election from weighted presidential lean vs. the national House vote margin in the next midterm since 1994 CYCLE AVERAGE SWING NATIONAL HOUSE MARGIN DIFFERENCE 2014 R+4 R+6 2 2010 R+6 R+7 1 2006 D+15 D+8 7 2002 0 R+5 5 1998 D+1 R+1 2 1994 R+9 R+7 2 Average 3 The swing compares the district’s Democratic lean in the previous two presidential elections vs. the special election result. The Democratic lean compares the district’s voting patterns to the nation. For each cycle, the previous presidential election is weighted 75 percent and the one before is weighted 25 percent. Sources: DAILY KOS ELECTIONS, Polidata, SWING STATE PROJECT, Ourcampaigns

We only have six data points here, so we shouldn’t get carried away drawing conclusions. That said, Democrats have to like the look of this table.

The cycle that looks most like this one is 2006, when Democrats gained 30 seats and control of the House from the Republicans thanks to a hefty win in the popular vote across all House races. In 2018, they need 24 seats to win back control of the lower chamber. The difference between the average swing in special federal elections and the margin of the national vote for the House has averaged just 3 percentage points since 1994. It has never differed by more than 7 points. So even if Democrats do 7 points worse in the national House vote than the average swing so far suggests, they’d still win the national House vote by 9 points, which would likely mean that they reclaim a House majority next year.

Indeed, the special election results so far this year are merely another indication of the GOP’s precarious position. President Trump’s approval rating is below 40 percent and Democrats hold an 11-percentage-point lead on the generic congressional ballot.

We’re still nearly a year from the 2018 midterms. That’s enough time for things to shift. Maybe Trump will grow more popular, for example. But historically, the environment doesn’t change much between this point in an election cycle and the midterms. So if you’re a Democrat, Tuesday’s Alabama result is just the latest special election sign that things are looking up heading into 2018.