If life were a Netflix series, no one would blame you for thinking that it had jumped the shark by the end of Season 4.

According to new research published by the National Bureau of Economic Research, decreasing life satisfaction over our thirties and into our forties is a nearly universal human experience. But so is increasing happiness over our fifties and sixties. Using data from 132 countries, both rich and poor, economist David Blanchflower finds that self-reported happiness bottoms out at age 47, after which point we grow a little bit more satisfied with our lives with each year we grow older.

There is an antidote to this mid-life happiness slump. Marriage. Multiple studies have shown that people who are married, and especially people who are married to their best friend, are able to stay much more cheerful through these difficult middle years—when the happiness gap between married and single people is at its widest.

We can all think of social and economic factors as to why married people might be happier, but the explanation for the mid-life happiness gap just might have a more primitive explanation. And the fact that researchers have found that great apes—specifically chimpanzees and orangutans—experience the same pattern in happiness over their lifetimes suggests that part of this story is biological.

I have my own theory. I think that sex makes people happy. Young people have more sex than middle aged people. And middle-aged people who are married have more sex than those who are single. The gap in happiness between married and single people could be explained, in part at least, by the gap in easy access to a sexual partner.

There are no published academic papers that prove this marriage/sex/happiness story, but there is evidence that backs up my theory.

The first piece of evidence can be found by using the General Social Survey (1989-2018), a nationally representative survey that asks people how frequently they have sex. According to that data the median married adult between the ages of 40 and 60 has sex once a week, whereas the median single adult that age has sex only once a month. And among people in that same age group, 34 percent of single adults had no sex in the last year compared to only 3 percent of married adults.

This result makes sense given that people who are single at mid-life are looking for sex on much thinner markets—there are fewer options available to them given that so many of their cohort are already in committed relationships. Marriage at any age gives people easier access to a sexual partner, and the advantage that married people have increases as we grow older.

The second piece of evidence suggests sex makes people happy in general. A 2004 paper by David Blanchflower and Andrew J. Oswald, titled Money, Sex, and Happiness: An Empirical Study, finds that the more sex people have, the happier they report to being. The biggest sex effect was for those having it more than four times per week. Those people are very happy. But even having sex once a week significantly increases life satisfaction.

The final piece of evidence, found in that same paper, is that while we might like a little variety in sexual partners, the happiness maximising number of sexual partners is exactly one. Just to be clear, that is measured as “sexual partners in the past year,” not on one crazy night.

If this result is accurate, this means that married people are getting a double boost in happiness at midlife—the first from having sex more frequently and the second from having one consistent sexual partner.

None of this explains why happiness swings back up again as we move into older age, or why the happiness gap between single and married people become much smaller after age 60 when the gap in sexual frequency becomes larger.

Between age 60 and 70, 67 percent of single people have not had sex in the past year compared to 16 percent of married people—in fact, the median married person at that age is still having sex once a month and 19 percent are still having sex weekly.

But maybe sex isn’t as important at that stage of life. Maybe playing pickleball is just as good. I hazard to guess that finding a partner for pickleball is much easier and not being married to them frees up your time to spend more time doing other things you love.