(Erika P. Rodriguez for The Washington Post)

The Democrats’ success in many recent state and local elections has raised their hopes of taking back the House or Senate in 2018. Fueling their optimism is the fact that President Trump remains distinctively unpopular for a president at this point in his first term — even though the economy continues to grow.

What does this unusual combination — a good economy but an unpopular president — imply for the midterm elections? A simple, albeit early, forecast provides some good news for Democrats.

The House forecast

To produce a House forecast, I drew on a forecasting model originally developed by political scientists Michael Lewis-Beck and Tom Rice. Their model is based on three factors: changes in real gross national product in the first and second quarters of the election year, the president’s approval rating in Gallup polls as of July of the election year, and whether it is a presidential or midterm year. The well-known historical pattern is that the party that does not hold the presidency gains seats in the House in midterm elections.

I applied the Lewis-Beck and Rice model to the 1948-2016 elections. The only modification is that I used gross domestic product (GDP) instead of gross national product because GDP excludes foreign production by American-owned firms.

Then, I forecast what would happened for 2018, assuming that current economic and political conditions stay the same. Specifically, I used the two most recent quarters of change in GDP for which we have data — spring and summer, during which GDP grew at rates of 3 and 3.1 percent, respectively — and Trump’s Gallup poll rating at the end of December, which averaged 38 percent.

The model predicts that the Republicans will lose 38 seats in the House, a number that would give the Democrats a majority in the next Congress. But it’s important to note that simple models such as this one produce forecasts with real uncertainty. In this case, you can think of the forecast as having a “margin of error” of 38 seats.

Thus, a Democratic gain is likely, but the size of that gain is difficult to predict with confidence. Still, a House majority is very much within the Democrats’ reach.

The Senate forecast

Lewis-Beck and Rice’s Senate model is similar to the House model, but includes an additional factor: how many seats the president’s party has up for election. In 2018, this factor favors the Republicans because only eight Republican Senate seats are in play, while 25 Democrats must defend their seats.

In this case, the model predicts that the GOP will gain one seat. Given the uncertainty in the forecast, plus or minus eight seats, control of the Senate is essentially a toss-up.

In short, if Trump’s popularity and the economy continue at their current pace, Republicans should be expecting a major loss in the House and a possible chance of losing the Senate.

Indeed, there are already signs that Republican officeholders are intuiting the same challenges that the forecasting model suggests. Three Republican senators — Bob Corker, Jeff Flake, and Orrin G. Hatch — and 36 Republican representatives have announced that they are not running for reelection.

Looking forward to 2020

Republicans have one other potential worry: 2020. It is very early to make presidential election forecasts — mainly because there are no assurances that the economy or presidential approval won’t change. But if they did not, a model based on these two factors suggests that Trump would receive only 41 percent of the electoral college votes. If Trump’s approval rating did not change, it would take an extraordinary level of economic growth — more than 7 percent — even to make the race a toss-up.

The question now is what happens to economic and political fundamentals in the coming months. Without a significant change in Trump’s approval number, Republicans are at a real risk in 2018 — and possibly beyond.

Eric R. A. N. Smith is professor of political science at the University of California, Santa Barbara.