Breadlines

Regions of Deprivation

Introduction

In addition to obvious networks, we can also use graph theory to think though some non-obvious application. One place this often crops up in planning is to think about adjacency/proximity as a graph. See my post on employment centers and paper on delineating areas.

In this post, I will demonstrate how to use networks for other spatial analysis. We can think of polygons as nodes and two nodes are connected if they share some part of the boundary

Acquire data

I also want to demonstrate Kyle Walker’s excellent tigris and tidycensus packages that allow us to conveniently download Census data.

First you need to acquire an API key from census.

We will use the API key to access American Community Survey (ACS) data.The American Community Survey (ACS) is an ongoing survey by the U.S. Census Bureau. It regularly gathers information previously contained only in the long form of the decennial census, such as ancestry, educational attainment, income, language proficiency, migration, disability, employment, and housing characteristics. About 3.5 million people are surveyed every year and multi-year summaries are provided at different levels of geography (not at block level).

Because it is a survey, each variable comes with a margin of error. These are widely ignored in practise and there is a tendency to take the estimates at face value. This practise is problematic.

library(tidycensus)
library(sf)
library(tidyverse)
library(mapview)
library(RColorBrewer)
library(igraph)
library(tigris)

census_api_key(census_apikey)
varnames <- load_variables(2016, "acs5", cache = TRUE)
write_csv(varnames, path="/Users/kaza/Desktop/acs_varnames.csv")

It is useful to write the variables and their descriptions into an external file that you can use in other programs and this is usually handy for finding variables of interest. In this post, I am going to use poverty rate and unemployment rate as examples. The choice of these variables is arbitrary.

Poverty rate

For example, to find the poverty rate in Carolinas’ census tracts, you can use B17001_01 (persons for whom poverty level is tracked) and B17001_002 (persons whose income in the last 12 months was below poverty level).

NC_SC <- c('37', '45') # FIPS code for NC and SC.

# Download CBSAs and MSAs for reference.

cbsa <- core_based_statistical_areas() %>% st_as_sf()  # Download Core Based Statistical Areas file
states_shps <- states() %>% 
               st_as_sf() %>%
               filter(GEOID %in% NC_SC) # Limit to the Carolinas
 
MSA <- cbsa[states_shps,] %>%  # Filter CBSA that is intersected/touched by the state boundary.
            filter(LSAD=="M1")  # Limit to Metropolitan areas
pov <- reduce(
  map(NC_SC, function(x) {
    get_acs(geography = "tract", variables = "B17001_002",  summary_var = 'B17001_001',
            state = x, geometry = TRUE, year = 2016)
  }), 
  rbind
) ## read up on these map and reduce functions in purrr. They are key to functional programming paradigm
nrow(pov)
# [1] 3298

pov_rate <- pov %>%
  rename(population = summary_est) %>%
  filter(population>0)%>%
  mutate(pov_rate = estimate/population) %>%
  select(GEOID, NAME, population, pov_rate)

library(mapview)
mapview(pov_rate, 
        zcol=c('pov_rate'),
        col.regions = brewer.pal(5, "Reds"),
        at=quantile(pov_rate$pov_rate, seq(0,1,.2)),
        lwd=0
        )