Donald Trump speaks at a campaign rally in Macon, Ga., on Nov. 30, 2015. (Christopher Aluka Berry/Reuters)

As Americans settled in on the evening of Nov. 8 to watch the election returns, there was widespread agreement that Hillary Clinton was likely to win the presidency. Models based on polling data had nearly all suggested that a Donald Trump victory was either virtually impossible or at least unlikely.

Many had locked in these forecasts relatively early on. “It is totally over,” tweeted Sam Wang of the Princeton Election Consortium on Oct. 18. “If Trump wins more than 240 votes I will eat a bug.”

The good news is that bugs are packed with protein, because Trump won the presidency.

If this is a modern “Dewey Defeats Truman” moment (though some disagree) how did it come to be? One possibility is that the polls were off because people were uncomfortable openly sharing with pollsters that they planned to vote for Trump.

Discomfort with openly admitting a political viewpoint is hardly new. In the book “Independent Politics,” two of us (Klar and Krupnikov) demonstrate that people will often hide behind the label “independent” to avoid publicly associating with either of the two parties — particularly when those parties are stigmatized.

The culprit is social desirability bias. To avoid “looking bad,” some people avoid answering survey questions or, even worse, outright lie. Social desirability becomes even more powerful in a negative context: The more negative messages people receive about a certain group, the more likely they are to avoid publicly associating with that group.

By the time the 2016 campaign was in its home stretch, the media culture surrounding the Trump candidacy had become significantly more negative. Almost no mainstream newspapers had endorsed his candidacy (though some highlighted his endorsement by the official newspaper of the KKK). Many mainstream newspapers highlighted Trump’s flaws, and journalists openly grappled with their inability to withhold judgment. In short, identifying as a Trump supporter may have seemed — at least to some people — as socially undesirable.

Could Trump’s social undesirability have mattered for pre-election polls? The challenge here is that people refuse to answer survey questions in a variety of ways. Hiding your views need not mean lying. It could mean saying that you’re undecided or simply not taking the poll at all. Right now, the data don’t tell us definitively what happened.

That said, certainly there were more undecided voters in 2016 than 2012 — 15 percent vs. 5 percent as of late October. Meanwhile, exit poll data suggests an unexpected level of enthusiasm for Trump, and more subdued reactions for Clinton. Turnout patterns point in a similar direction: Clinton underperformed with key Democratic-coalition groups, while Trump did better than expected among Republicans and independents.

Moreover, although some research suggested that “shy Trump voters” were few and far between, other research did find that Republicans were more likely to deflect questions about voting for Trump. And we do not know yet whether some Trump supporters simply didn’t participate in polls at all.

If early coverage is any indication, the 2016 campaign has led many people to doubt the value of modern polling. This is too hasty. As some have suggested, the polls did not fail all that spectacularly in 2016. But they were off by enough in a few key states to give a misleading impression of the outcome.

This should lead us to be more sensitive to the political context in which surveys occur, and the resulting incentives that respondents have to be truthful. Some respondents may change their response if they fear people’s disapproval.

Elizabeth Connors is a PhD student in the political science department at Stony Brook University. Samara Klar is an assistant professor of political science at the University of Arizona. Yanna Krupnikov is associate professor of political science at Stony Brook University.