SAN FRANCISCO — Facebook directs advertising to audiences in ways that could promote racial and gender discrimination, a new study showed, adding to allegations that prompted the U.S. government to sue the world's largest social media company last week.

Facebook's algorithms, which match marketing messages with viewers, leans on stereotypes when it comes to housing and jobs, according to the study by researchers from Northeastern University, University of Southern California and advocacy group Upturn. The study was posted on arXiv, an online forum for research awaiting peer review, on Wednesday.

"Ad platforms themselves can shape access to information about important life opportunities in ways that might present a challenge to equal opportunity goals," said the group, whose university researchers have done separate studies on online ad systems.

Facebook spokesman Joe Osborne responded in a statement that the company recognizes it must do more, and said the findings would be included in ongoing discussions about changing its ad system.

"We've been looking at our ad delivery system and have engaged industry leaders, academics, and civil rights experts on this very topic — and we're exploring more changes," he said.

The researchers advertised lumber job ads on Facebook and found that the algorithms delivered the postings to mostly white men, while secretary positions mostly went to black women. That held true even when lumber ads pictured black people, and the secretarial jobs white people.

The Facebook study also found that ads about homes for sale in North Carolina reached a mostly white audience while rental ads went to a mostly black one.

Facebook does not provide race data, according to the researchers, but they inferred it by linking general audience details to voter registration data.

Though the pictures of people in the job ads did not appear to affect the audience makeup, the photos used did appear to be a factor for Facebook's algorithm in other cases.

Showing a football or soldiers versus a flower or paint set led to a mostly male audience for an otherwise identical ad unrelated to jobs, the researchers found.

The Trump administration sued Facebook last Thursday, accusing it of selling targeted advertising that discriminated on the basis of race, in violation of the U.S. Fair Housing Act.

Facebook removed some targeting options in response to complaints from the government and civil rights groups.

Addressing racial and gender discrepancies in automated systems, including for facial recognition, has become a priority for Silicon Valley.