You may have more in common with your friends than you think, according to a new study published in Proceedings of the National Academy of Sciences. Your genes may be similar, too.

Past research has suggested that people tend to be somewhat genetically similar to their spouses and adult friends, likely because humans naturally gravitate toward people with whom they have something in common. But how and why does this subconscious sorting happen? Researchers from Stanford, Duke and the University of Wisconsin—Madison studied 5,000 pairs of adolescent friends using data from Add Health, a long-term study of people who were in grades seven through 12 during the 1994-1995 school year. They ran a number of genetic comparisons, seeking to learn more about pairs of friends and schoolmates.

Overall, the researchers found that friends were more genetically similar than random pairs of people, and about two-thirds as similar as the average married couple. Study author Benjamin Domingue, an assistant professor at the Stanford Graduate School of Education, says this similarity is strong enough to detect, but not nearly on the same level as siblings, for example.

Get our Health Newsletter. Sign up to receive the latest health and science news, plus answers to wellness questions and expert tips. Please enter a valid email address. Sign Up Now Check the box if you do not wish to receive promotional offers via email from TIME. You can unsubscribe at any time. By signing up you are agreeing to our Terms of Use and Privacy Policy . This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply. Thank you! For your security, we've sent a confirmation email to the address you entered. Click the link to confirm your subscription and begin receiving our newsletters. If you don't get the confirmation within 10 minutes, please check your spam folder.

This effect may be due to a concept called social homophily, or the idea that individuals form bonds based on shared characteristics, many of which can be traced back to genetics.

But there may also be a second phenomenon at work, according to the paper: social structuring, or the idea that people are drawn to others in their own social environment, which may itself be partially shaped by genetics. For example, certain socially mediated traits, like educational attainment and body mass index, were particularly alike among friends, while those without a strong interpersonal dimension — such as height — were less likely to match up, according to the paper.

The equation grew more interesting when the researchers compared schoolmates’ genomes. Classmates were about half as genetically similar as friends and significantly more similar than unaffiliated individuals — which suggests that a shared environment and background may account for a good chunk of the genetic likeness observed among friends, Domingue explains. That, in turn, underscores how closely genetics and social circumstances are linked.

“Are individuals actively selecting to be around people who are like them, or is it due to impersonal forces, such as social structures, that we all are affected by?” Domingue says. “Our evidence, with respect to friends, suggest that it’s largely the effect of social structures.”

Genes and social environments intertwine in many ways, adds fellow study author and University of North Carolina Chapel Hill sociology professor Kathleen Mullan Harris. Genetic similarity among schoolmates could be due to everything from the school’s location to the type of parent who decides to send their child to that institution, she says.

It’s a complicated equation, Mullan notes — and one that other researchers should keep in mind moving forward.

“Geneticists need to pay attention to the social context when they’re estimating genetic influences on [traits] like education attainment,” she says. “It’s important to pay attention to these shared genetic effects that we speculate are really due to social structure.”

Write to Jamie Ducharme at jamie.ducharme@time.com.