Charlie Gardner finds an association between metropolitan area weighted density and housing affordability:

Income is more strongly correlated with weighted density than total population, although not dramatically so. However, median home values were even more strongly correlated with weighted density. The result is that, for cities of equivalent size, the city with the higher weighted density will generally be less affordable in relative terms, even if incomes are higher (for instance, Sacramento is almost twice as dense as similarly-sized and lower-income Kansas City, but is only two-thirds as affordable).

I believe high home prices are generally caused by housing being too scarce rather than housing being built too close together, so I didn't expect weighted density to have much bearing on home affordability. In fact, it doesn't: the association between weighted density and affordability is weak, with weighted density explaining only about 17% of the variation in affordability (the ratio of median home price to median income*) among metropolitan areas. Whatever the culprits for unaffordability, they're mostly something other than density. (Being located in California is a better predictor of high relative housing cost, for example, than having high density. The variation in affordability explained by weighted density drops to 10.5% when California cities are excluded.)

Below is a scatterplot pairing the weighted density of each MSA with the ratio of its median home price to median income. The trend line slopes upward, which means that housing tends to get less affordable as the metropolitan area gets denser. As the scatterplot should make clear, though, weighted density doesn't really have much predictive value, particularly for MSAs with weighted densities less than 5,000-6,000 pssm. (Contrast this with having "San" or "Santa" in the city name; this seems to be a very good predictor of high unaffordability.)

(click to enlarge).

One thing that jumps out from the chart is just how much of an outlier the New York City metropolitan area is. It's an outlier in density, of course - it's almost three times as dense as LA and San Francisco. But it's also an outlier in its distance *below *the trend line. The New York City metropolitan area is much, much more affordable than the trend line predicts. The trend line predicts that the median home in the New York MSA should cost a bit more than 15 times the median income; in reality, the ratio is under 11. Moreover, the slope of the trend line is itself skewed downward by New York City: if you fitted a trend line to the data ignoring NYC, it would predict a home value-to-income ratio of arond 20 for a city with 31,000 ppsm.

New York City has horrible land-use regulations. Ed Glaeser et al. estimated a few years ago that regulatory constraints are responsible for at least 50% of the overall unit value in the average owned apartment in Manhattan. Vast swaths of the City have been mummified by historic preservation districts. The City has casually downzoned large chunks of Brooklyn. Many of New York's suburbs are notoriously NIMBY.

Still, it ain't California.

As California's coastal cities prove, a city (with sufficient amenities) can make itself completely unaffordable at any given weighted density. While California has many natural amenities, they're no greater than, say, Honolulu's. Honolulu, of course, is squeezed into a small sliver of land on an island between volcanos and the ocean. (Note that roughly half of New York's metropolitan population is also situated on three islands.) Santa Cruz and San Luis Obispo don't have Honolulu's (or New York's) geographic constraints. What they do have is a nasty set of land-use regulations that are, evidently, just as effective as volacanos, rivers and oceans in depressing the supply of new housing below the market-clearing level.

*Charlie uses the reciprocal; i.e., median income divided by median home value. That yields a slightly stronger correlation with weighted density, but the resulting trend line is not as steep.

(NB. Corvalis, another outlier, is not particularly expensive; it just has a very low median income. I assume this means that college students are an unusually high percentage of the population.)