Author

library(data.table)
library(plyr) #join
library(ggplot2) #fortify, ggplot
library(sp) #used by rgdal
library(rgdal) #readOGR
library(ggmap) #theme_nothing
library(rgeos) #gCentroids
library(scales) #scale_fill_distiller
library(viridisLite)
library(viridis)

Wellbeing Toronto

Wellbeing Toronto - Economics

“WB-Economics.xlsx”

Wellbeing Toronto - Maps - City of Toronto

TransUnion Debt Load Risk Score

Methodological Notes: The Risk Score is a proprietary index value provided by TransUnion Canada that indicates the likelihood of missing three consecutive loan payments. Low-value scores (\(<707\)) indicate a High Risk of missing 3 consecutive loan payments; High-value scores (769+) indicate a low risk. These risk scores are calculated for non-mortgage consumer debt such as lines of credit, credit cards, automobile loans and installment loans. TransUnion data is provided by postal code and covers approximately 92% of all Canadians with credit files. For privacy reasons, postal codes with fewer than 15 credit files are suppressed. TransUnion dataset provided by the Community Data Program (www.communitydata.ca).

Source: For Reference Period 2011: TransUnion 2012 via the Community Data Program.

Exported to CSV “Debt_Risk_Score.csv”

Thomas Higgins, TransUnion Risk Score: Make smarter, more strategic decisions, Wednesday, December 12, 2012.

(p. 3) Performance Definition

90+ Days Past Due or Worse including Public Record Bankruptcy and Write-Off

12mth Performance Window

(p. 10) Scoring Output

Score range: 299 to 884

TransUnion Risk Score delivers three (3) reason codes and a scorecard indicator with every score

Financial Consumer Agency of Canada, Credit report and score basics

Your credit score is a three-digit number that comes from the information in your credit report. It shows how well you manage credit and how risky it would be for a lender to lend you money.

Your credit score is calculated using a formula based on your credit report.

Note that:

  • you get points for actions that show you use credit responsibly
  • you lose points for things that show you have difficulty managing credit

Your credit score will change over time as your credit report is updated

How a credit score is calculated

It’s not possible to know exactly how many points your score will go up or down based on the actions you take. Credit bureaus and lenders don’t share the actual formulas they use to calculate credit scores.

Factors that may affect your credit score include:

  • how long you’ve had credit
  • if you carry a balance on your credit cards
  • if you regularly miss payments
  • the amount of your outstanding debts
  • being close to your credit limit
  • the number of times you try to get more credit
  • the types of credit you’re using
  • if your debts have been sent to a collection agency
  • any record of insolvency or bankruptcy
Debt_Risk_Score <- fread("Debt_Risk_Score.csv")
str(Debt_Risk_Score)
Classes ‘data.table’ and 'data.frame':  140 obs. of  3 variables:
 $ Neighbourhood   : chr  "West Humber-Clairville" "Mount Olive-Silverstone-Jamestown" "Thistletown-Beaumond Heights" "Rexdale-Kipling" ...
 $ Neighbourhood Id: num  1 2 3 4 5 6 7 8 9 10 ...
 $ Debt Risk Score : num  719 687 718 721 692 717 750 753 761 791 ...
 - attr(*, ".internal.selfref")=<externalptr> 
Debt_Risk_Score <- Debt_Risk_Score[,.(id = `Neighbourhood Id`, SCORE = `Debt Risk Score`)]

Debt_Risk_Score$id <- as.integer(Debt_Risk_Score$id)
str(Debt_Risk_Score)
Classes ‘data.table’ and 'data.frame':  140 obs. of  2 variables:
 $ id   : int  1 2 3 4 5 6 7 8 9 10 ...
 $ SCORE: num  719 687 718 721 692 717 750 753 761 791 ...
 - attr(*, ".internal.selfref")=<externalptr> 
summary(Debt_Risk_Score$SCORE)
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
  661.0   720.5   741.0   739.2   759.0   793.0 
nbds.sh <- readOGR("C:/Users/14165/Desktop/Shapefiles/neighbourhoods_planning_areas_wgs84", "NEIGHBORHOODS_WGS84")
OGR data source with driver: ESRI Shapefile 
Source: "C:\Users\14165\Desktop\Shapefiles\neighbourhoods_planning_areas_wgs84", layer: "NEIGHBORHOODS_WGS84"
with 140 features
It has 2 fields
str(nbds.sh@data)
'data.frame':   140 obs. of  2 variables:
 $ AREA_S_CD: Factor w/ 140 levels "001","002","003",..: 97 27 38 31 16 118 63 3 55 59 ...
 $ AREA_NAME: Factor w/ 140 levels "Agincourt North (129)",..: 138 139 68 140 114 115 117 118 119 30 ...
nbds.sh@data$id <- as.integer(nbds.sh@data$AREA_S_CD)
nbds.centroids  <- as.data.frame(gCentroid(nbds.sh, byid = TRUE))
nbds.centroids$SCORE <- Debt_Risk_Score$SCORE
nbds.df = fortify(nbds.sh, region = "id")

# nbds.df = join(nbds.points, nbds.sh@data, by = "id")
nbds.Debt_Risk_Score <- merge(nbds.df, Debt_Risk_Score, by = "id")

Using viridis

ggplot() +
  geom_polygon(data = nbds.Debt_Risk_Score, 
               aes(x = long, y = lat, group = group, fill = SCORE), 
               color = "white", size = 0.1) + 
  theme_nothing(legend = TRUE) +
  scale_fill_viridis(option="magma", name="SCORE") +
  geom_text(aes(x=x,y=y, group=NULL, label=SCORE), data = nbds.centroids, size = 1.9, color = "Black") +
  labs(title="TransUnion Debt Load Risk Scores by Neighbourhood, 2011")

Using scales

p.Debt_Risk_Score <- ggplot() +
  geom_polygon(data = nbds.Debt_Risk_Score, 
               aes(x = long, y = lat, group = group, fill = SCORE), 
               color = "black", size = 0.2) + 
  coord_map() + 
  scale_fill_distiller(name="SCORE", palette = "RdYlGn", trans = "reverse", breaks = pretty_breaks(n = 8)) + 
  theme_nothing(legend = TRUE) + 
  labs(title="TransUnion Debt Load Risk Scores by Neighbourhood, 2011") + 
  geom_text(aes(x=x,y=y, group=NULL, label=SCORE), data = nbds.centroids, size = 2)

p.Debt_Risk_Score+guides(fill = guide_legend(reverse = TRUE))

LS0tDQp0aXRsZTogIlRyYW5zVW5pb24gRGVidCBMb2FkIFJpc2sgU2NvcmVzIGluIFRvcm9udG8iDQpvdXRwdXQ6IGh0bWxfbm90ZWJvb2sNCi0tLQ0KDQojIEF1dGhvcg0KDQoqIEpvcmRhbiBCZWxsDQoqIEp1bHkgMTMsIDIwMTkNCiogPGh0dHBzOi8vam9yZGFuYmVsbDIzNTcuZ2l0aHViLmlvL1RyYW5zVW5pb24ubmIuaHRtbD4NCg0KDQoNCmBgYHtyfQ0KbGlicmFyeShkYXRhLnRhYmxlKQ0KbGlicmFyeShwbHlyKSAjam9pbg0KbGlicmFyeShnZ3Bsb3QyKSAjZm9ydGlmeSwgZ2dwbG90DQpsaWJyYXJ5KHNwKSAjdXNlZCBieSByZ2RhbA0KbGlicmFyeShyZ2RhbCkgI3JlYWRPR1INCmxpYnJhc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