Home prices in most markets are cheap relative to what they were a few years ago. But “cheap” doesn’t exist in a vacuum. To understand whether houses are really selling for a bargain and whether it’s best to buy or to rent, you need to weigh price trends against a host of factors, the local economy and housing demand among them. The easiest way to do this is to look at what’s happening in your local rental market.

“Over time, rental prices and housing prices tend to move together,” says Gleb Nechayev, a senior economist with Torto Wheaton Research in Boston. “When the two show very different trends, that’s when you start seeing some indications of a correction in one direction or the other.” Theory goes, if the economic and demographic trends are driving home prices higher — or lower — those factors should also affect rents.

When the cost to rent is disproportionately lower than the cost to buy, it suggests that the market is being propped up on speculation rather than fundamentals — and that kind of growth isn’t sustainable. On the other hand, if the cost of owning is disproportionately lower than the cost of renting, it’s an indication that the housing market might have been oversold. Based on this measure, home prices in 16 of the 20 markets tracked by the Standard & Poor’s Case-Shiller housing index are undervalued relative to the going rate to rent a single-family home.

Economists refer to the relationship between renting and owning as a housing market’s price-to-earnings ratio, or P/E. The measure is widely used by stock analysts to gauge the relative value of a stock by taking the stock price, dividing it by a company’s earnings and comparing it with the stock’s historical P/E or that of its peers. In the case of housing, a P/E is the median home price divided by the median annual rent. While the measure isn’t perfect — among other things, it doesn’t account for interest rates — it is one way to see if a housing market is overvalued or undervalued relative to historical norms.

In relatively affordable housing markets, such as Atlanta or Cleveland, the median P/E in the decade between 1998 and 2008 has hovered around 10. In markets where home prices have historically been high — Los Angeles, New York, San Francisco — the typical housing P/E has been about twice as much. Homeowners have always paid a premium to buy property in these markets and probably always will because rents (or “earnings”) grow at a much faster rate, says Mike Sklarz, senior economist for Cyberhomes.

It’s when the P/E deviates from its historical norm that economists start questioning whether the housing market is out of whack. And indeed, looking back, the P/E has corresponded with housing bubbles and busts.

In Los Angeles, the median P/E over the last decade has been about 18.5. Yet, it peaked at more than 23 in 2006, when home prices were at their highest. Data for the first quarter of 2009 suggest that prices are now lower than their 10-year norm; the P/E is about 14.75, indicating that the median home price, at $385,000, is relatively cheap. Las Vegas and Miami, meanwhile, look to be the biggest bargains of the group. Both metros have P/Es below 10, versus about 13 for the previous decade.

Although home prices have fallen in most markets, the housing P/E isn’t down across the board. Prices in the Portland, Ore., metro are selling at more than 16 times earnings, considerably more than the area’s 10-year median P/E of 13. In Seattle, home prices are selling at 18.9 times earnings, slightly higher than the 10-year norm of 17.2. “The P/Es in these markets have held up because they’ve experienced relatively small price declines since their peak levels,” says Sklarz. Does that mean their prices have further to fall? “Not necessarily,” he says. “These have been stronger markets all along and probably have not been impacted as much by subprime issues or overbuilding.”

The housing P/E is useful, but only to a point. For most would-be buyers, it’s more useful to compare the cost of owning versus renting. To crunch the numbers for your own market, follow the instructions in a previous story, “Why Rent Matters.”

Rent vs. buy in the Case-Shiller markets