Research Publication Writing

Costs to Rent Versus Own in Canada: A Fun Analysis Using R

Research Publication Writing

Paying for somewhere to live is an unavoidable expense. Whether you rent or own it is recommended that no more than 30% of your income be spent on shelter costs. Is this 30% figure attainable for Canadians? In this post, we perform an analysis using r to find out, and make predictions for the future.


We collected Census Data from the last National Household Survey, published in 2011 for this analysis. Data from the most recent Census is not available until later this year. Each result is presented as a map of Canada and embedded below are pdfs that can be zoomed in to highlight specific regions. The shelter costs as a % of gross income are white at 0% and become progressively redder as the costs increase up to 60%.


Getting the Data

We used the data available here. This Census data is split into 13 csv files, and covers an enormous amount of data. Here is information from one of the 13 csv files, the file for Ontario:

 

str(cen.data)
## 'data.frame':    411840 obs. of  15 variables:
##  $ Geo_Code      : int  3501005 3501005 3501005 3501005 3501005 3501005 3501005 3501005 3501005 3501005 ...
##  $ Prov_Name     : Factor w/ 1 level "Ontario": 1 1 1 1 1 1 1 1 1 1 ...
##  $ CD_Name       : Factor w/ 49 levels "Algoma","Brant",..: 42 42 42 42 42 42 42 42 42 42 ...
##  $ CSD_Name      : Factor w/ 427 levels "Adelaide-Metcalfe",..: 343 343 343 343 343 343 343 343 343 343 ...
##  $ CSD_type      : Factor w/ 8 levels "City","Indian reserve",..: 6 6 6 6 6 6 6 6 6 6 ...
##  $ GNR           : num  35 35 35 35 35 35 35 35 35 35 ...
##  $ Topic         : Factor w/ 29 levels "Aboriginal population",..: 3 3 3 3 3 10 10 10 10 10 ...
##  $ Characteristic: Factor w/ 889 levels "        Interprovincial migrants",..: 879 713 366 365 780 882 773 737 346 277 ...
##  $ Note          : int  1 NA NA NA 2 3 4 5 NA NA ...
##  $ Total         : num  12890 12730 2430 10300 165 ...
##  $ Flag_Total    : Factor w/ 3 levels "","...","x": 1 1 1 1 1 1 1 1 1 1 ...
##  $ Male          : num  6450 6390 1250 5135 55 ...
##  $ Flag_Male     : Factor w/ 3 levels "","...","x": 1 1 1 1 1 1 1 1 1 1 ...
##  $ Female        : num  6440 6340 1180 5160 105 ...
##  $ Flag_Female   : Factor w/ 3 levels "","...","x": 1 1 1 1 1 1 1 1 1 1 ...
head(cen.data)
##   Geo_Code Prov_Name                        CD_Name        CSD_Name
## 1  3501005   Ontario Stormont, Dundas and Glengarry South Glengarry
## 2  3501005   Ontario Stormont, Dundas and Glengarry South Glengarry
## 3  3501005   Ontario Stormont, Dundas and Glengarry South Glengarry
## 4  3501005   Ontario Stormont, Dundas and Glengarry South Glengarry
## 5  3501005   Ontario Stormont, Dundas and Glengarry South Glengarry
## 6  3501005   Ontario Stormont, Dundas and Glengarry South Glengarry
##   CSD_type GNR                                      Topic
## 1 Township  35                                Citizenship
## 2 Township  35                                Citizenship
## 3 Township  35                                Citizenship
## 4 Township  35                                Citizenship
## 5 Township  35                                Citizenship
## 6 Township  35 Immigrant status and period of immigration
##                                                                         Characteristic
## 1                                Total population in private households by citizenship
## 2                                                                    Canadian citizens
## 3                                                      Canadian citizens aged under 18
## 4                                                   Canadian citizens aged 18 and over
## 5                                                                Not Canadian citizens
## 6 Total population in private households by immigrant status and period of immigration
##   Note Total Flag_Total Male Flag_Male Female Flag_Female
## 1    1 12890            6450             6440            
## 2   NA 12730            6390             6340            
## 3   NA  2430            1250             1180            
## 4   NA 10300            5135             5160            
## 5    2   165              55              105            
## 6    3 12890            6450             6445


The data is organized by Census division (CD_Name), Topics (such as Citizenship), and Characteristics of each topic. The first thing we want to do is pull out only the information we are interested in from each of the 13 files, and combine it in R. We can write our own function for that.


imprt.prov.info <- function(location, queries){
        filelist <- list.files(path=location)
        
        tot.cen.data <- NULL
        for(j in 1:length(queries)){
                cen.data <- NULL
                for(i in 1:length(filelist)){
                        print(paste("Loop", j, i, sep="-"))
                        temp <- read.csv(filelist[i], header=T)
                        temp.inc <- subset(temp,temp$Characteristic == queries[j])
                        cen.data <- rbind(cen.data, temp.inc)
                        }
                cen.data <- cen.data[,c("Prov_Name","CD_Name", "Total")]
                colnames(cen.data)[3] <- queries[j]
                if(j == 1){
                        tot.cen.data <- cen.data
                        }
                else{
                        tot.cen.data[j+2] <- cen.data[3]
                        }
                }
        tot.cen.data
        }
#vector of desired data labels
q <- c("  Average household total income ($)", "  Average value of dwellings ($)",
" % of owner households with a mortgage", " Average monthly shelter costs for owned dwellings ($)",
" Average monthly shelter costs for rented dwellings ($)") #run script useful.info <- imprt.prov.info(".", q)

Steps to Create the Maps

To create the maps shown below, we calculated the data of interest, combined it with our map data frame, then created the maps using ggplot2.

library(rgeos)
library(rgdal)
library(maptools)
library(sp)
library(ggplot2)
library(maps)
library(plyr)
library(dplyr)
library(tidyr)
library(forecast)

#read the mapfile
canada <- readShapeSpatial("your.mapfile")
canada_map <- fortify(canada, region="CDNAME") #centroids for labels centroids <- as.data.frame(coordinates(canada)) colnames(centroids) <- c("long", "lat") #gathering ids working.list <- canada@data split.lang <- data.frame(do.call('rbind', strsplit(as.character(working.list$PRNAME), " / ", useBytes=T))) split.lang[] <- lapply(split.lang, as.character) split.lang[c(149,277,286),1] <- "Prince Edward Island" working.list$Prov_Name <- split.lang$X1 #map with centroids for labels map.df <- data.frame(working.list[,c(2,6)], centroids)

#merge data with map file
your.merged.df <- merge(map.df, your.data, by=c("Prov_Name", "CDNAME"))

#ggplot
gg <- ggplot(your.merged.df, aes(map_id=CDNAME))
gg <- gg + geom_map(aes(fill=Cost),color="gray", size=0.05, map=canada_map)
gg <- gg + scale_fill_continuous(low="white", high="red", name="% of Yearly Income Cost", lim=c(0,60), guide=F)
gg <- gg + coord_map()
gg <- gg + theme_map()
gg <- gg + geom_text(aes(label = CDNAME, x = long, y = lat), size=0.2) #label names
gg
Rental Cost in 2010

With the data we imported, let’s look at the cost to rent in Canada, based on census division. For this analysis using r, we need to compare the “Average household income” and “Average shelter costs for rented dwellings” for each Census division. The results are shown on the map below.


To rent in 2010, generally Canadian families spent less than 30% of their incomes. Unsurprisingly some regions are more expensive to rent than others (Toronto, Muskoka, and Sunshine Coast).

 

Ownership Cost 2010

Now let’s do the same for “Average household income” and “Average shelter costs for owned dwellings”, again for each Census division. The results are shown on the map below.


Compared to the cost of renting a place to live, owning is more expensive in general. Here we are overall much closer to the 30% ‘accepted’ income cost. Keep in mind though that equity build-up is not taken into account.

 

Ownership Cost Continued

The ownership cost from the Census is somewhat misleading, as it includes both mortgaged and mortgage free shelter. It obviously is much more expensive to own if a mortgage is being payed monthly. Let’s use the “Average value of dwelling” and “Average household income” for this analysis using r.


Let’s assume the mortgage is 95% of the dwelling value, amortized over 25 years. This next figure demonstrates the cost just to cover the mortgage, as a percentage of household income.




The costs are much more expensive in regions such as Sunshine Coast, Toronto, Greater Vancouver, and Columbia-Shuswap.

 

Home Purchase: Predictions 2016

This Census data was collected in 2010, and data from the 2016 Census will be presented later this year. For interest sake, we built a model to predict the cost to buy a home in Canada, based on Census division. Our model is uses available housing and wage data from previous years to predict future years. We will revisit this 2016 prediction later this year when the Census data is released.



Has the situation improved at all? Generally it has gotten worse. We are predicting that in 2016 a lot of regions will require greater than 30% of family income just to cover the mortgage when purchasing shelter. This model predicts that the cost will remain high regions mentioned above (Sunshine Coast, Greater Vancouver, and Toronto). The general rise is predicted to be caused by increasing housing costs and stagnant wages.

Home Purchase: Predictions 2020

There may be a small bit of relief by 2020 as wages catch up slightly in some regions, but compared to 2010 we predict that the cost of buying shelter will remain out of control through 2020.



 

Conclusions

Until wages increase significantly or there is a major housing correction, in many regions in Canada it may be better to rent than to buy or own a home.

Author


Avatar