Diabetes, Obesity, and Income
Contributed by William Aiken. William took NYC Data Science Academy 12 week full time Data Science Bootcamp program between Sept 23 to Dec 18, 2015. The post was based on his second class project(due at 4th week of the program).
This was my first data science project associated with the bootcamp. The goal of this project was a visualization and explorations of New York state diabetic incidence data. I wanted to look at data sets where there existed previously established relationships. I chose a public health issue of diabetic rates and obesity, it has been shown that there is a strong link between these two issues. I thought it would be of interest to see how this relationship played out in New York state. The data used were part of the 1,250 freely available data sets on the ny.gov website, an amazing resource for public health issues. Four different sets were utilized: an income data set; a diabetic rate set; a diabetic mortality rate and an obesity rate data set(all from 2009). All of these data sets provided granularity at the county level. The inclusion of the last three data sets are very straight forward. Income data was included in this analysis for two reasons, first there is a long established relationship between income and diabetic rates. Secondly, New York is the only state where the poorest county(Bronx) is directly adjacent to the most affluent county(Manhattan/New York County). I was curious to see what relationships existed alongside this economic disparity. New York state contains fifty-two counties so I wanted to find a way to represent this data that made comparisons between counties easy and also retained spacial relations. Choropleth maps were ideal for this task. These maps use color intensity to represent aggregated data within a geographic region, either intensive or extensive. Luckily for me, the R programming language had several libraries to aid in this mapping, choroplethR had the shallowest learning curve. Rather than just bury the reader in plots, I will present only the most interesting plots in the post. But here is a link to a Shiny application that I created that will allow you to explore with all the data. Shiny App
Before my data could be mapped with choroplethR library it required some manipulation. Thankfully the data was complete, if anything there was more data than I required. Several of the data sets contained information years beyond 2009, my year of interest. Some data sets included aggregations of regions that required exclusion. Lastly all of the data sets contained formating that required adjusting so they joined with the FIPs dataset required by choroplethR.
Here is the code for the for my loading and data munging.
library(choroplethr) library(choroplethrMaps) library(dplyr) library(ggplot2) data("county.regions") Income <- read.csv("AverageIncome.csv",stringsAsFactors = FALSE) Mortality <- read.csv("Mortality2009-2011.csv",stringsAsFactors = FALSE) Obese <- read.csv("Obese08-09.csv",stringsAsFactors = FALSE) Diagnosed <- read.csv("Diagnosed.csv",stringsAsFactors = FALSE) Diagnosed <- rename(Diagnosed, County = County.Name) Income <- rename(Income, County = Place.of.Residence) Obese <- rename(Obese, County = County.Name) Mortality <- rename(Mortality, County = County.Name) Income$County <- as.character(Income$County) Income <-mutate(Income, County=ifelse(County=="New York City - Bronx", "Bronx", County)) Income <-mutate(Income, County=ifelse(County=="New York City - Kings", "Kings", County)) Income <-mutate(Income, County=ifelse(County=="New York City - Manhattan", "New York", County)) Income <-mutate(Income, County=ifelse(County=="New York City - Queens", "Queens", County)) Income <-mutate(Income, County=ifelse(County=="New York City - Richmond", "Richmond", County)) Income09 <- filter(Income, Tax.Year %in% 2009) Income09 <- mutate(Income09, County = ifelse(County == "new york city", "new york", County)) Obese$County <- tolower(Obese$County) Income$County <- tolower(Income$County) Mortality$County <- tolower(Mortality$County) Diagnosed$County <- tolower(Diagnosed$County) DiaDiagnosed <- filter(Diagnosed, Diagnosed$Health.Topic %in% "Cirrhosis/Diabetes Indicators") DiaDiagnosed <- rename(DiaDiagnosed, value = Percent.Rate) Mortality <- rename(Mortality, value = Percentage.Rate) Income09 <- rename(Income09, value = Average.NY.AGI.of.All.Returns) Obese <- rename(Obese, value = Percentage.Rate) Test <- filter(county.region, state.name %in% "new york") Test2 <- left_join(Test, Obese, by = c("county.name" = "County")) Test3 <- left_join(Test, Income09, by = c("county.name" = "County")) Test4 <- left_join(Test, DiaDiagnosed, by = c("county.name" = "County")) Test5 <- left_join(Test, Mortality, by = c("county.name" = "County"))
Here is the choropleth map of diabetic rates for all the counties in New York state in 2009. The values represent all the percent of the population that has been diagnosed by a doctor as being diabetic.
Here is a choropleth map of all the average incomes within the five New York City counties. The disparity between Manhattan and the other four counties is striking.
After the data sets had been joined to the FIPs county data set they could be visualized with choroplethR. The code for the plots is listed here.
county_choropleth(Test2, title = "2009 New York State Obesity Rates", legend = "% Population Obese", num_colors = 1, state_zoom = c("new york")) new_york_city = c(36005, 36047, 36061, 36081, 36085) county_choropleth(Test2, title = "2009 New York City Obesity Rates", legend = "% Population Obese", num_colors = 1, county_zoom = new_york_city) county_choropleth(Test3, title = "2009 Average Incomes by County", legend = "Average Income in Thousands of $", num_colors = 9, state_zoom = c("new york")) + scale_fill_brewer(palette=2) new_york_city = c(36005, 36047, 36061, 36081, 36085) county_choropleth(Test3, title = "2009 Average Income", legend = "Income in Thousands", num_colors = 9, county_zoom = new_york_city)+scale_fill_brewer(palette=2) county_choropleth(Test4, title = "Diabetic Rates per County", legend = "Percent of population with Diabetes", num_colors = 9, state_zoom = c("new york")) + scale_fill_brewer(palette=3) new_york_city = c(36005, 36047, 36061, 36081, 36085) county_choropleth(Test4, title = "Diabetic Rates per County", legend = "Percent of population with Diabetes", num_colors = 9, county_zoom = new_york_city)+scale_fill_brewer(palette=3) county_choropleth(Test5, title = "Diabetic Deaths per County 2009-2011", legend = "Percent of Deaths Caused by Diabetes", num_colors = 9, state_zoom = c("new york")) + scale_fill_brewer(palette=4) new_york_city = c(36005, 36047, 36061, 36081, 36085) county_choropleth(Test4, title = "Percent of Diabetic Deaths per County", legend = "Percent of Deaths Caused by Diabetes", num_colors = 9, county_zoom = new_york_city)+scale_fill_brewer(palette=4)
Here is a scatterplot exploring the relationship between the diabetic rates for each county and their corresponding obesity rate. It's worth noting that this data is inherently normalized due of it's ratio nature (incidence per 100,000 residents).
The data was also plotted in scatterplots to better visualize some of the non-spacial relationships within the data sets. The code for the scatterplots is listed below.
qplot(Test3$value, Test4$value, xlab = "Income in Thousands", ylab = "Percent Diabetic", main = "Average Income vs Diabetic Rate in New York Counties") + (geom_smooth()) qplot(Test3$value, Test5$value, xlab = "Income in Thousands", ylab = "Percent of Deaths attributed to Diabetes", main = "Average Income vs Diabetic Mortality Rate in New York Counties") + (geom_smooth()) qplot(Test3$value, Test2$value, xlab = "Income in Thousands", ylab = "Percent Obese",main = "Average Income vs Obese Rate in New York Counties") + (geom_smooth()) qplot(Test4$value, Test2$value, xlab = "Percent Diabetic", ylab = "Percent Obese",main = "Percent Diabetic vs Percent Obese") + (geom_smooth())
Conclusion:
The data substantiated the already established relationships between income, obesity and diabetes. Counties with the highest average incomes had the lowest incidence of diabetes. The link between obesity and diabetes was also shown. Interestingly, counties with high incomes and high obesity rates had low rates of diabetes. The link between income and diabetes may be as strong as the relationship between diabetes and obesity. I haven't included my Shiny app code for the sake of space put it can be found on my Github here.My Github