How do you count all the rats in New York City? If one urban legend is to be believed, you don't have to: There are as many rats as people — 8 million.

Statistician Jonathan Auerbach decided to test that idea. We'll get to how many rats he found in a bit. First, consider some of the daunting challenges he faced in trying to get a head count.

"Getting an accurate count of any animal population is difficult," he wrote in Significance, the journal of the Royal Statistical Society. "Animals are terrible survey respondents."

So Auerbach used a method called capture-recapture estimation, developed by ecologists. The simplest version of this technique, called the two-sample version, would have required the large-scale release of rats into the population. This obviously posed another problem.

"Unfortunately, NYC's Department of Health and Mental Hygiene is unlikely to approve a large-scale rat-releasing experiment (I know, because I asked)," he wrote. "So, instead, we have to rely on an alternative."

He turned to data maintained by the city's Department of Health — particularly a data set on rat sightings, by location, reported by dialing 311. While this method doesn't allow the marking of individual rats, Auerbach wrote, it does allow the locations in which they were reported to be classified and marked by city lot — of which there are 842,000 in New York.

"If we adapt two-sample capture–recapture estimation to approximate the number of city lots harbouring rats, we can then multiply the total number of inhabited lots by the average number of rats per inhabited lot to recover the population of rats," he wrote.

Here's more about how he did it, in Auerbach's own words:

"Pest management professionals who set traps on rat-inhabited lots can estimate the average number of rats per inhabited lot, and in order to estimate the number of rat-inhabited lots in NYC, we will follow steps similar to capture-recapture. For reference purposes, let us call this adapted procedure 'lot comparison.'"We first observe the number of lots that reported a rat sighting during the first half of 2010. These lots constitute our first sample and are our "marked" lots. Then we observe the number of lots that reported a rat sighting during the first half of 2011. These lots constitute our second sample. Some of them are "marked" in that they were also identified within our first sample. A "marked" lot that appears in the second sample period has been 'recaptured'. If we assume that a recaptured lot is as likely to be reported as any other rat-inhabited lot, the proportion of "recaptured" lots in the second sample period will then provide an estimate of the total number of rat-inhabited lots."

The numbers, when Auerbach ran them, were far lower than 8 million, the stuff of urban legend. His number: a paltry 2 million.

That, he told NPR's Audie Cornish, is far fewer than one estimate he received from an exterminator who believed there were "trillions" of rats in the city.

"The lesson here is that when nobody knows ... everyone has their own personal assessment based on their own anecdotal evidence," he told Cornish.

And, he wrote in his paper, his method still "likely overestimates the population of rats in NYC."

Copyright 2016 NPR. To see more, visit http://www.npr.org/.