Photo: David Paul Morris/Bloomberg via Getty Images/© 2016 Bloomberg Finance LP

The Democratic National Convention was scored this week by a very particular and persistent soundtrack: that one song that they wouldn’t stop playing, yes, but also a clamor of boos, many of which came from (justifiably) angry and disappointed Bernie Sanders supporters reluctant to abandon the candidate they believed in. Despite some of the stories circulated about the stubbornness of the Bernie or Bust movement, most of the Bernie backers will indeed vote for Hillary Clinton in November. And yet, it’s hard to let go of something like this, something that seemed so frustratingly within reach.

There are so many complicating factors here, both among the #StillSanders folks in particular and in this extraordinarily unusual election in general. But one way to understand these fierce emotions is through the lens of psychology, specifically something researchers call counterfactual thinking. You might think of this like a highbrow, academic approach to that Gwyneth Paltrow movie from the late ’90s, Sliding Doors. “It’s the contemplation of alternative realities or different pathways one might’ve taken,” explained Columbia Business School psychologist Adam Galinsky, who has studied the allure of this mode of contemplation. It could be as simple as imagining a world where you didn’t miss your morning train, if only you’d woken up a little earlier; it could be as complex as wondering how your life might’ve turned out differently if you’d followed your gut and studied what you truly loved in college. It’s the road not taken; it’s the ghost ship that didn’t carry us.

There are countless ways to reimagine your reality, of course, but according to the psychology literature, there are two situations that reliably trigger this sort of thinking. One is the almost scenario: Something very nearly went the way you wanted it to and then it just … didn’t. The psychologist Daniel Kahneman, who won the Nobel Prize in economics in 2002, published a well-known study in the 1980s about this feeling, using the analogy of a missed flight. If you miss it by hours — well, fine, you really had no chance of making that flight, anyway. Your attention quickly shifts away from the frustration over the travel mishap and toward how to fix it. But if you just barely miss your flight — if you’re at the gate just minutes after they’ve shut the door? Of the two, that’s the scenario that tends to result in more counterfactual thinking. What if you’d left just a little bit earlier? What if you’d booked an evening flight instead of pretending to yourself that you could make a 7 a.m. flight? What if, what if, what if?

It’s the almost factor that is likely making things particularly painful for many Sanders supporters. True, Clinton won by a solid margin, “by 359 pledged delegates, and 884 delegates overall (counting superdelegates),” according to FiveThirtyEight’s Nate Silver; Clinton also won 55 percent of the popular vote, compared to Sanders’ 43 percent. But that’s almost beside the point, Galinsky explained. “So, it wasn’t particularly close on a lot of fronts,” he said. “But he won a lot of states, and he had momentum at various times. So I think, psychologically, it feels like he almost won it, and that is, I think, why people were so upset at the DNC and why the emails made such a big impact. Because they’re like, ‘He could’ve won, if the system wasn’t rigged.’” This almost factor, by the way, also helps explain why it’s a decade and a half later and people still sometimes engage in some what ifs about the 2000 election. “Bush and Gore were so close — and, in fact, Gore won the popular vote — so you could imagine a world where we had a different election system, and Gore was the winner,” Galinsky said.

But Bernie supporters are, of course, not the only voters imagining what might’ve been; Republicans, especially those who dislike Trump, are likely doing the same, though for a different reason. In addition to this idea of psychological closeness, the second situation that tends to spark counterfactual thinking is the abnormal scenario. When something unusual happens, in other words, it’s hard to stop imagining the alternate reality when nothing unusual happened, and everything proceeded like it typically does. Imagine these two events: You take your normal route home, and you get into a car crash. Or, you decide to take a new route home, and you get into a car crash. Experiments have shown that most people feel more regret in the second situation than the first. “With the normal route, they’re much more likely to focus on things like, ‘Okay, how am I going to get to work tomorrow, I’ve gotta get my car fixed,’” Galinsky said. “And when they went a different way home from work it’s, ‘Oh man! I should’ve just gone the normal way.’”

And now, an understatement: The abnormal factor is not difficult to apply to the 2016 election. “Trump really represents the abnormal counterfactual,” Galinsky said. “Because he’s so out of the normal. Everything about him is abnormal for a typical election. So it’s easy for Republicans to go back in time and go, ‘What if Ted Cruz had gone after him from the beginning? What if Marco Rubio hadn’t been Marco Robot in the New Hampshire primary?”

People often tend to conflate this sort of thinking with regret, which can of course be a painful psychological state to dwell in. But an intriguing line of research is lately showing that, at least when applied to their personal lives, people use this form of reflection to help imbue their lives with meaning. Galinsky shared an example from his own life. “I’m expecting my first child in three weeks,” he told me. “I partially moved to New York because I hadn’t met anyone — I dated someone for a long time, and then we broke up, and I hadn’t met anyone else in Chicago, and so I moved to New York to meet someone. So for me it’s easy to imagine, ‘Wow, what if I hadn’t moved from Chicago? Or hadn’t gone to this party? I almost didn’t go to this party where I met my now-wife.” It gives your autobiography some overarching purpose, or even a sense of fate.

People tend to use two different forms of counterfactual thinking, depending on the situation: There’s upward counterfactual thinking, or imagining how things could’ve turned out better, and there’s downward counterfactual thinking, or imagining how things could’ve turned out worse. Research has shown that people tend to use these two forms strategically, depending on the situation. Experiments conducted by Ohio University psychologist Keith Markman have, for example, found that when people know they will never get the chance to do some task again, they try to make themselves feel better about mediocre results by indulging in some downward counterfactual thinking: Eh, it could’ve gone worse. “But if they’re going to get to do the task again, it’s actually really beneficial to engage in upward counterfactuals, because they’re incredibly powerful learning mechanisms for you,” Galinsky said. Thinking about how things could’ve gone better can help reveal things you could do to make your real world match a little more closely to your ideal one.

It’s like my reading a critical but annoyingly accurate comment under a post I’ve written. It stings. But it could also be useful, in that could help make my writing better. Thinking through upward counterfactuals can require some “psychological resilience,” Galinsky said, but it can also inspire important changes. “You could imagine the Bernie supporters saying, ‘Well, these are the changes we want in the DNC structure so this doesn’t happen again,’” he added. Okay, obviously, that part is much easier said than done. But the idea — seeing things as they are while imagining how they could be better — is the most optimistic vision I’ve heard yet of what comes next for disappointed Sanders supporters. It’s not a bad framework for considering your own Sliding Doors moments, either.