{"id":2403,"date":"2011-03-17T23:00:55","date_gmt":"2011-03-18T03:00:55","guid":{"rendered":"http:\/\/www.decisionsciencenews.com\/?p=2403"},"modified":"2011-03-21T18:16:41","modified_gmt":"2011-03-21T22:16:41","slug":"the-housing-bubble-by-city","status":"publish","type":"post","link":"https:\/\/www.decisionsciencenews.com\/?p=2403","title":{"rendered":"The housing bubble by city"},"content":{"rendered":"<p>DIFFERENT CITIES TELL DIFFERENT STORIES<\/p>\n<p style=\"text-align: center;\"><a href=\"http:\/\/www.decisionsciencenews.com\/wp-content\/uploads\/2011\/03\/all.cit_.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-2404 aligncenter\" title=\"all.cit\" src=\"http:\/\/www.decisionsciencenews.com\/wp-content\/uploads\/2011\/03\/all.cit_.png\" alt=\"\" width=\"490\" height=\"490\" \/><\/a><\/p>\n<p>Inspired by a tutorial called <a href=\"http:\/\/stotastic.com\/wordpress\/2010\/04\/case-shiller\/\">5 Minute Analysis in R: Case-Shiller Indices<\/a>, we decided to redo the analysis with 1) More up to date data and 2) <a href=\"http:\/\/had.co.nz\">Hadley Wickham&#8217;s<\/a> super <a href=\"http:\/\/had.co.nz\/ggplot2\/\">ggplot2<\/a> graphics package.<\/p>\n<p>The above plot shows the general trend in home prices, relative to January 2000, in various cities, but is otherwise a mess.<\/p>\n<p>Much like Olympic sports coverage, we next focus in on a few exceptional stories. It is much easier to read.<\/p>\n<p style=\"text-align: center;\"><a href=\"http:\/\/www.decisionsciencenews.com\/wp-content\/uploads\/2011\/03\/sel.cit_.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-2405 aligncenter\" title=\"sel.cit\" src=\"http:\/\/www.decisionsciencenews.com\/wp-content\/uploads\/2011\/03\/sel.cit_.png\" alt=\"\" width=\"490\" height=\"490\" \/><\/a><\/p>\n<p>Miami sailed high and fell far. Detroit rose modestly and but dropped more than it went up.\u00a0 Dallas held steady. DC is enjoying a bit of renewed growth, but are it and New York yet to fall?<\/p>\n<p>The graphs were surprisingly easy to create in R, and the full code is below. If you&#8217;d like to do your own analysis, the <a title=\"Standard &amp; Poor's Web site has data that you can download yourself\" href=\"http:\/\/www.standardandpoors.com\/indices\/sp-case-shiller-home-price-indices\/en\/us\/?indexId=spusa-cashpidff--p-us----\">Standard &amp; Poor&#8217;s Web site has data that you can download yourself<\/a>. We chose the &#8220;seasonally adjusted&#8221; data set.<\/p>\n<p>New to us in the code below was the &#8220;<a href=\"http:\/\/stat.ethz.ch\/R-manual\/R-patched\/library\/base\/html\/droplevels.html\">droplevels<\/a>&#8216; command which was added to R&#8217;s version 12. It dispenses with unused factor levels that you sometimes end up with when subsetting data. Extra levels are often harmless, but in ggplot2 they show up in the legend.\u00a0 Without droplevels, the second graph would have the legend of the first graph.<\/p>\n<p><code><br \/>\nlibrary(ggplot2)<br \/>\n## Read in data, available from:<br \/>\n#www.standardandpoors.com\/indices\/sp-case-shiller-home-price-indices\/en\/us\/?indexId=spusa-cashpidff--p-us----<br \/>\ndat=read.csv(\"CSHomePrice_History.csv\")<br \/>\nmdf=melt(dat,id.vars=\"YEAR\")<br \/>\nmdf$Date=as.Date(paste(\"01-\",mdf$YEAR,sep=\"\"),\"%d-%b-%y\")<br \/>\nnames(mdf)=c(\"MonthYear\",\"City\",\"IndexValue\",\"Date\")<br \/>\nggplot(data=mdf,aes(x=Date,y=IndexValue)) + geom_line(aes(color=City),size=1.25) +<br \/>\nscale_x_date(\"Year\", minor=\"years\")  + scale_y_continuous(\"Case Schiller Index\")<br \/>\nsm=subset(mdf,City %in% c('NY.New.York','FL.Miami','CA.Los Angeles','MI.Detroit',<br \/>\n'TX.Dallas','IL.Chicago','DC.Washington'))<br \/>\nsm$City=droplevels(sm$City)<br \/>\nggplot(data=sm,aes(x=Date,y=IndexValue)) + geom_line(aes(color=City),size=1.5) +<br \/>\nscale_x_date(\"Year\", minor=\"years\")  + scale_y_continuous(\"Case Schiller Index\")<br \/>\n<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The housing bubble by city. Miami sailed high and fell far. Detroit rose modestly and but dropped more than it went up.  Dallas held steady. DC is enjoying a bit of renewed growth, but are in and New York yet to fall?<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false}}},"categories":[16,74,15],"tags":[27,169,107,103,1208,170],"class_list":["post-2403","post","type-post","status-publish","format-standard","hentry","category-ideas","category-r","category-tools","tag-economics","tag-ggplot","tag-ggplot2","tag-graphics","tag-r","tag-time-series"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p4LKj-CL","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.decisionsciencenews.com\/index.php?rest_route=\/wp\/v2\/posts\/2403","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.decisionsciencenews.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.decisionsciencenews.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.decisionsciencenews.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.decisionsciencenews.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2403"}],"version-history":[{"count":10,"href":"https:\/\/www.decisionsciencenews.com\/index.php?rest_route=\/wp\/v2\/posts\/2403\/revisions"}],"predecessor-version":[{"id":2415,"href":"https:\/\/www.decisionsciencenews.com\/index.php?rest_route=\/wp\/v2\/posts\/2403\/revisions\/2415"}],"wp:attachment":[{"href":"https:\/\/www.decisionsciencenews.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2403"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.decisionsciencenews.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2403"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.decisionsciencenews.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2403"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}