Bay Area Real Estate (cont.)

September 8, 2014
By

(This article was first published on Analyst At Large » R, and kindly contributed to R-bloggers)

Previously, I posted a short post about recent detached single house prices in San Leandro and Hayward areas.  I received a little more data (sales data from the past month), so I thought it would be a good time for an update.  I’d like to investigate which way the housing market in these areas is moving.

First, I started by looking at prices across the past 6 months.

SLHousePrices

HaywardHousePrices The plots above show that housing prices rose substantially in San Leandro from January through May before cooling down slightly.  House prices in Hayward seem to have been steady or even slightly declining over the past 6 months.

This is the highest level look, but it neglects many details (house size, # of sales, quality of home, neighborhood, etc.).  I wanted to drill down one more level and look at cost per square foot (which should help us look across house sizes).

SLSqFt

HaywardSqFtSan Leandro cost per square foot has risen significantly since January, but has been flat since April.  The cost of Hayward houses per square foot has been more or less stable with median prices in the $325-$350 / sq. ft. range most months.

There is a lot more analysis to do, but I have wedding planning to do.  Here is the code…

###### Settings
options(scipen=10)
setwd("C:/Blog/SFHousing")
library(RColorBrewer)
col.9<-brewer.pal(9,"Oranges")
 
###### Loading data
sl1<-read.csv("SanLeandro.csv")
sl2<-read.csv("SanLeandro2.csv")
hay1<-read.csv("Hayward.csv")
hay2<-read.csv("Hayward2.csv")
sl<-rbind(sl1,sl2)
hay<-rbind(hay1,hay2)
 
###### Formatting data
sl$Sold.Price<-as.numeric(gsub('[[:punct:]]','',sl$Sold.Price))
sl$List.Price<-as.numeric(gsub('[[:punct:]]','',sl$List.Price))
 
hay$Sold.Price<-as.numeric(gsub('[[:punct:]]','',hay$Sold.Price))
hay$List.Price<-as.numeric(gsub('[[:punct:]]','',hay$List.Price))
 
sl$Baths.Partial[is.na(sl$Baths.Partial)]<-0
sl$Baths2<-sl$Baths+sl$Baths.Partial*.5
sl<-sl[order(sl$Bedrooms,sl$Baths2),]
sl$Title<-paste0(sl$Bedrooms,"BD,",sl$Baths2,"BA")
# Remove house types only listed once
sl<-sl[sl$Title %in% names(table(sl$Title))[as.numeric(which(table(sl$Title)>1))],]
sllev<-unique(sl$Title)
sl$Title<-factor(sl$Title,levels=sllev)
 
hay$Baths.Partial[is.na(hay$Baths.Partial)]<-0
hay$Baths2<-hay$Baths+hay$Baths.Partial*.5
hay<-hay[order(hay$Bedrooms,hay$Baths2),]
hay$Title<-paste0(hay$Bedrooms,"BD,",hay$Baths2,"BA")
# Remove house types only listed once
hay<-hay[hay$Title %in% names(table(hay$Title))[as.numeric(which(table(hay$Title)>1))],]
haylev<-unique(hay$Title)
hay$Title<-factor(hay$Title,levels=haylev)
 
minmin<-floor(min(sl$Sold.Price)/50000)*50000
maxmax<-ceiling(max(sl$Sold.Price)/50000)*50000
 
par(mar=c(6,5,5,5))
boxplot(sl$Sold.Price~sl$Title,main="San Leandro - Sold Price",col="skyblue",ylim=c(minmin,maxmax),
	yaxt="n")
axis(2,at=seq(minmin,maxmax,by=50000),labels=paste0("$",prettyNum(seq(minmin,maxmax,by=50000),big.mark=",")),las=2)
axis(4,at=seq(minmin,maxmax,by=50000),labels=paste0("$",prettyNum(seq(minmin,maxmax,by=50000),big.mark=",")),las=2)
for (i in seq(minmin,maxmax,by=25000))
	{abline(h=i,lty=3,col="lightgray")}
 
minmin2<-floor(min(hay$Sold.Price)/50000)*50000
maxmax2<-ceiling(max(hay$Sold.Price)/50000)*50000
 
par(mar=c(6,5,5,5))
boxplot(hay$Sold.Price~hay$Title,main="Hayward - Sold Price",col="lightgreen",ylim=c(minmin,maxmax),
	yaxt="n")
axis(2,at=seq(minmin,maxmax2,by=50000),labels=paste0("$",prettyNum(seq(minmin2,maxmax2,by=50000),big.mark=",")),las=2)
axis(4,at=seq(minmin,maxmax2,by=50000),labels=paste0("$",prettyNum(seq(minmin2,maxmax2,by=50000),big.mark=",")),las=2)
for (i in seq(minmin,maxmax2,by=25000))
	{abline(h=i,lty=3,col="lightgray")}
 
###### Sale Price by Month
sl$Closing.Date<-as.Date(sl$Closing.Date,format="%m/%d/%Y")
hay$Closing.Date<-as.Date(hay$Closing.Date,format="%m/%d/%Y")
 
sl$MONTH<-substr(sl$Closing.Date,0,7)
hay$MONTH<-substr(hay$Closing.Date,0,7)
 
par(mar=c(6,5,5,5))
boxplot(sl$Sold.Price~sl$MONTH,col=col.9[4],main="San Leandro Sale Prices by Month",yaxt="n")
axis(2,at=seq(300000,450000,by=25000),labels=paste0("$",gsub(" ","",prettyNum(seq(300000,450000,by=25000),big.mark=","))),las=2)
axis(4,at=seq(300000,450000,by=25000),labels=paste0("$",gsub(" ","",prettyNum(seq(300000,450000,by=25000),big.mark=","))),las=2)
for (i in seq(300000,450000,by=25000))
	{abline(h=i,lty=3,col="lightgray")}
 
par(mar=c(6,5,5,5))
boxplot(hay$Sold.Price~hay$MONTH,col=col.9[7],main="Hayward Sale Prices by Month",yaxt="n")
axis(2,at=seq(300000,450000,by=25000),labels=paste0("$",gsub(" ","",prettyNum(seq(300000,450000,by=25000),big.mark=","))),las=2)
axis(4,at=seq(300000,450000,by=25000),labels=paste0("$",gsub(" ","",prettyNum(seq(300000,450000,by=25000),big.mark=","))),las=2)
for (i in seq(300000,450000,by=25000))
	{abline(h=i,lty=3,col="lightgray")}
 
###### Sale/sqft price by month
sl$PriceSQFT<-sl$List.Price/sl$Sq.Ft.Apx
hay$PriceSQFT<-hay$List.Price/hay$Sq.Ft.Apx
 
par(mar=c(6,5,5,5))
boxplot(sl$PriceSQFT~sl$MONTH,col=col.9[4],main="San Leandro Sale Prices by Month",yaxt="n")
axis(2,at=seq(150,500,by=25),labels=paste0("$",gsub(" ","",prettyNum(seq(150,500,by=25),big.mark=","))),las=2)
axis(4,at=seq(150,500,by=25),labels=paste0("$",gsub(" ","",prettyNum(seq(150,500,by=25),big.mark=","))),las=2)
for (i in seq(150,500,by=25))
	{abline(h=i,lty=3,col="lightgray")}
 
par(mar=c(6,5,5,5))
boxplot(hay$PriceSQFT~hay$MONTH,col=col.9[7],main="Hayward Sale Prices by Month",yaxt="n")
axis(2,at=seq(150,500,by=25),labels=paste0("$",gsub(" ","",prettyNum(seq(150,500,by=25),big.mark=","))),las=2)
axis(4,at=seq(150,500,by=25),labels=paste0("$",gsub(" ","",prettyNum(seq(150,500,by=25),big.mark=","))),las=2)
for (i in seq(150,500,by=25))
	{abline(h=i,lty=3,col="lightgray")}
 
###### Sale-List Price by Month
sl$CHANGE<-sl$Sold.Price-sl$List.Price
hay$CHANGE<-hay$Sold.Price-hay$List.Price
 
par(mar=c(6,5,5,5))
boxplot(sl$CHANGE~sl$MONTH,col=col.9[4],ylim=c(-50000,50000),
	main="San Leandro Sale Price - List Price by Month",yaxt="n")
axis(2,at=seq(-50000,50000,by=10000),labels=paste0("$",gsub(" ","",prettyNum(seq(-50000,50000,by=10000),big.mark=","))),las=2)
axis(4,at=seq(-50000,50000,by=10000),labels=paste0("$",gsub(" ","",prettyNum(seq(-50000,50000,by=10000),big.mark=","))),las=2)
for (i in seq(-50000,50000,by=10000))
	{abline(h=i,lty=3,col="lightgray")}
 
par(mar=c(6,5,5,5))
boxplot(hay$CHANGE~hay$MONTH,col=col.9[7],ylim=c(-50000,50000),
	main="Hayward Sale Price - List Price by Month",yaxt="n")
axis(2,at=seq(-50000,50000,by=10000),labels=paste0("$",gsub(" ","",prettyNum(seq(-50000,50000,by=10000),big.mark=","))),las=2)
axis(4,at=seq(-50000,50000,by=10000),labels=paste0("$",gsub(" ","",prettyNum(seq(-50000,50000,by=10000),big.mark=","))),las=2)
for (i in seq(-50000,50000,by=10000))
	{abline(h=i,lty=3,col="lightgray")}
 
###### Days on Market by Month
par(mar=c(6,5,5,5))
boxplot(sl$Days.On.Market~sl$MONTH,col=col.9[4],main="San Leandro DOM by Month",ylim=c(0,70),yaxt="n")
axis(2,at=seq(0,70,by=10),labels=seq(0,70,by=10),las=2)
axis(4,at=seq(0,70,by=10),labels=seq(0,70,by=10),las=2)
for (i in seq(0,70,by=10))
	{abline(h=i,lty=3,col="lightgray")}
 
par(mar=c(6,5,5,5))
boxplot(hay$Days.On.Market~hay$MONTH,col=col.9[7],main="Hayward DOM by Month",ylim=c(0,70),yaxt="n")
axis(2,at=seq(0,70,by=10),labels=seq(0,70,by=10),las=2)
axis(4,at=seq(0,70,by=10),labels=seq(0,70,by=10),las=2)
for (i in seq(0,70,by=10))
	{abline(h=i,lty=3,col="lightgray")}

 

 

 

To leave a comment for the author, please follow the link and comment on their blog: Analyst At Large » R.

R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...



If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.

Search R-bloggers


Sponsors

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)