About

Census data was acquired via the United States Census Bureau’s APIs. In this analyses we pull data from the 5-year American Community Census Data Profiles data.

This document outlines how to obtain the data from the API using R and the required information to do so successfully. Additionally, we pulled county-level hospital data from American Hospital Association data. Currently have set all counties with NA for hospital as None for ICU beds.

#bring in 3 versions county hospital data
# From Erin
aha_acs_aspatial <- readRDS("C:/Users/jkempke/OneDrive - Emory University/AHA Critical Care Areas/Data/prepared_data/aha_acs_aspatial.Rds")

#Jordan averaged over 2016 to 2018
aha2016_2018.4 <- readRDS("C:/Users/jkempke/OneDrive - Emory University/AHA Critical Care Areas/Data/prepared_data/aha2016_2018.4.Rds" )

#Jordan, just 2018
aha2018.4 <- readRDS("C:/Users/jkempke/OneDrive - Emory University/AHA Critical Care Areas/Data/prepared_data/aha2018.4.Rds" )

Acquiring the data from the API

API key setup

Sign up for an API key here.

Setup for censusapi

Then, if you’re on a non-shared computer, add your Census API key to your .Renviron profile and call it CENSUS_KEY. The censusapi package, if you use this, will use it by default without any extra work on your part. Within R run:

# Add key to .Renviron
 Sys.setenv(CENSUS_KEY= "<YOURKEYHERE>")
# Reload .Renviron
 readRenviron("~/.Renviron")
# Check to see that the expected key is output in your R console
 Sys.getenv("CENSUS_KEY")

Setup for tidycensus

Need to define a sys env var called “CENSUS_API_KEY”

If you are on a shared computer (e.g. a library or school computer), you may not want to put your key in your .Renviron profile. For censusapi, you can specify your key within getCensus instead.

Package options

censusapi

censusapi is a wrapper for the United States Census Bureau’s APIs. This package is designed to get data from all those APIs using the same main function — getCensus — and the same syntax for each dataset.

censusapi generally uses the APIs’ original parameter names so that users can easily transition between Census’s documentation and examples and this package. It also includes metadata functions to return data frames of available APIs, variables, and geographies.

Identifying census variables

#get a variable table
acs5_2018 <- load_variables(2018, "acs5", cache = TRUE)
#view and search table
#View(acs5_2018)

Custom approach

I created a list of desired variables by searching through Census data tables on there website. In this particular analyses I specifically search through the variable 2018 Data Profiles data. I created config file of variable ACS names and their labels to be used below.

names <- read.csv("C:/Users/jkempke/Documents/GitHub/aha_cc_resources/prep_data/acs_data/config.csv", header = T)
#Bring in config file with new variable names and labels
#This will be used to create a labels list now and rename variables later.

# turn labels into list object.
# pre-allocate a list and fill it with human-readable var names a loop
acs.labels.list <- vector("list", nrow(names))

for (i in 1:nrow(names)) {
  acs.labels.list[[i]] <- names[i,2]
}
#name elements using var name
acs.labels.list <- setNames(acs.labels.list, names[,1])

Resources

Below are some resources that proved helpful in using the Census API

Data Pull and Cleaning

# all population characteristics
acs0 <- get_acs(geography = "county",
                variables = c(
                  "DP05_0001E", #Total pop
                  "DP05_0021E", # total pop 18+
                  "DP05_0021PE", # %pop 18+
                  "DP05_0024PE", # %pop 65%
                  "DP05_0019PE", # %pop < 18
                  "DP05_0003P", # %female
                  "DP05_0037PE", # %White
                  "DP05_0038PE", # %Black
                  "DP05_0039PE", # %AI/AN
                  "DP05_0044PE", # %Asian
                  "DP05_0052PE", # %NH/PI
                  "DP05_0057PE", # %Other
                  "DP05_0058PE", # 2+ races
                  "DP05_0071PE", # %Hispanic
                  "DP02_0059PE", # %25yr+ and <9th grade
                  "DP02_0066PE", # %25yr+ and at least HS graduate
                  "DP03_0027PE", # %16yr+ white collar jobs
                  "DP03_0099PE", # %wo health insurance
                  "DP03_0088E", # $per capita income
                  "DP03_0086E", # $median family income
                  "DP03_0062E", # $mean household income
                  "DP03_0052PE", # %household income <10K
                  "DP03_0053PE", # %household income 10-14K
                  "DP03_0054PE", # %household income 15-24K
                  "DP03_0055PE", # %household income 25-34K
                  "DP03_0056PE", # %household income 35-49K
                  "DP03_0057PE", # %household income 50-74K
                  "DP03_0058PE", # %household income 75-99K
                  "DP03_0059PE", # %household income 100-149K
                  "DP03_0060PE", # %household income 150-199K
                  "DP03_0061PE", # %household income 200K+
                  "DP04_0089E", # $Median home value
                  "DP04_0109E", # $Median rent
                  "DP04_0101E", # $Median mortgage
                  "DP04_0046PE", # %owner occupied
                  "DP03_0005PE", # %civilian labor force 16yr+ unemployed
                  "DP03_0119PE", # % families below poverty
                  "DP03_0128PE", # % individuals below poverty
                  "DP02_0007PE", # % male single parent family
                  "DP02_0009PE", # % female single parent family
                  "DP04_0058PE", # % households no car
                  "DP04_0075PE", # % households no phone service (inc cell)
                  "DP04_0073PE", # % households no plumbing
                  "DP04_0077PE", # % households 1 or less people per room
                  "DP05_0024PE", # % 65yr+
                  "DP05_0019PE", # % < 18yr
                  "DP02_0071PE", # % with a disability
                  "DP02_0113PE", # % 5yr+ speak English < very well
                  "DP04_0009PE", # % houses 2 units
                  "DP04_0010PE", # % houses 3-4 units
                  "DP04_0011PE", # % houses 5-9 units
                  "DP04_0012PE", # % houses 10-19 units
                  "DP04_0013PE", # % houses 20+ units
                  "DP04_0014PE", # % mobile homes
                  "DP02_0151PE" # % houses with computer
                ),
                year = 2018,
                survey = "acs5",
                geometry = FALSE
) 

acs1 <- left_join(acs0, names, by = "variable")
acs2 <- pivot_wider(acs1, id_cols = c(GEOID, NAME), names_from = name, values_from = estimate)

## Population characteristics that need wrangling
# % Minority - the complement of %White

acs3 <- acs2 %>% 
  group_by(NAME) %>%
  mutate(
    over50k = sum(perc.house.50_74k,
                  perc.house.75_99k,
                  perc.house.100_149k,
                  perc.house.150_199k,
                  perc.house.ge.200k), #Income disparity, create %under 50K
    perc.singleparent = sum(perc.fam.singlemale,
                            perc.fam.singlefemale),# single parent households - add up male and female single parent homes
    perc.multiunithouse = sum(perc.house.2unit,
                              perc.house.3_4unit,
                              perc.house.5_9unit,
                              perc.house.10_19unit,
                              perc.house.ge.20unit)#Multi unit housing, sum % of all relevant categories
  )%>%
  ungroup()%>%
  mutate(
    perc.minority = (100-perc.white), # % Minority - the complement of %White
    perc.l.highschool = (100-perc.ge.highschool),# less than HS diploma - complement of %25yr+ and at least HS graduate
    perc.house.g.1perroom = (100-perc.house.le.1perroom), # Houses >1 person per room - complement of 1 or less person per room
    income.disparity = log(100*perc.house.l.10k/over50k),# Income disparity=log of 100 x ratio <10K/>50K
    total.thousands = total/1000,#simple division for presentation
    mean.indi.income.thousands = mean.indi.income/1000,
    median.fam.income.thousands = median.fam.income/1000,
    median.house.income.thousands = median.house.income/1000,
    median.house.value.thousands = median.house.value/1000,
    median.mortgage.thousands = median.mortgage/1000)

#Join with hospital data
#Dichotomize each adult_icubeds_per1k at median from Jordan's versions
final.0 <- left_join(acs3, aha_acs_aspatial, by = "GEOID")
final.0 <- final.0 %>%
  mutate(adult_icubeds_per1k_median =
           if_else(is.na(adult_icubeds_per1k) == T, "None",
                   if_else(adult_icubeds_per1k<0.17, "low",
                           if_else(adult_icubeds_per1k >= 0.17, "high",
                                   NA_character_))))


final.1 <- left_join(acs3, aha2016_2018.4, by = "GEOID")
final.1 <- final.1 %>%
  mutate(adult_icubeds_per1k = 1000*mean.adult.icu.beds/total.ge.18,
        adult_icubeds_per1k_median =
           if_else(is.na(adult_icubeds_per1k) == T, "None",
                   if_else(percent.missing>0, "unreliable",
                   if_else(adult_icubeds_per1k<0.17, "low",
                           if_else(adult_icubeds_per1k >= 0.17, "high",
                                   NA_character_)))))


final.2 <- left_join(acs3, aha2018.4, by = "GEOID")
final.2 <- final.2 %>%
  mutate(adult_icubeds_per1k = 1000*adult.icu.beds/total.ge.18,
         adult_icubeds_per1k_median =
           if_else(is.na(adult_icubeds_per1k) == T, "None",   
                   if_else(percent.missing>0, "unreliable",
                   if_else(adult_icubeds_per1k<0.17, "low",
                           if_else(adult_icubeds_per1k >= 0.17, "high",
                                    NA_character_)))))

National Characteristics Summary

Here we describe national-level summary of county characteristics. We have excluded counties with less than 1000 persons.

Erin’s 2018 results

Overall (N=3184)
adult_icubeds_per1k
- Min 0.0
- Max 14.2
- Mean (SD) 0.3 (0.5)
- Median (Q1, Q3) 0.3 (0.2, 0.4)

Jordan’s 2018 results

Difference here is that Jordan’s method introduces more zeroes where there were NAs.

Overall (N=3184)
adult_icubeds_per1k
- Min 0.0
- Max 14.2
- Mean (SD) 0.2 (0.4)
- Median (Q1, Q3) 0.1 (0.0, 0.3)

Jordan’s 2016-2018 results

Overall (N=3184)
adult_icubeds_per1k
- Min 0.0
- Max 14.2
- Mean (SD) 0.2 (0.4)
- Median (Q1, Q3) 0.2 (0.0, 0.3)

County Characteristics Summary

Here we describe county-level characteristics by per capita density of ICU beds. Specifically we dichotomize the number of Adult ICU beds per 1000 adults at the national median of 0.17 Adult beds per 1000 adults which was the median in Jordan’s data (from Erin’s data median 0.25). We have excluded counties with less than 1000 persons.

Erin’s 2018 results

high (N=1036) low (N=371) None (N=1777) Total (N=3184)
Total population, thousands
- Mean (SD) 210.7 (517.3) 184.7 (317.4) 22.2 (30.3) 102.5 (327.8)
- Range 1.3 - 10098.1 11.1 - 2600.7 1.1 - 455.1 1.1 - 10098.1

Jordan’s 2018 Results

This is just with 2018 AHA data. I also created a category of “unreliable”. Counties where the percent of general hospitals with no survey response 2018 was greater than zero I marked county statistics as unreliable.

high (N=837) low (N=868) None (N=707) unreliable (N=772) Total (N=3184)
Total population, thousands
- Mean (SD) 118.5 (202.0) 45.9 (78.7) 18.2 (20.9) 225.9 (605.2) 102.5 (327.8)
- Range 1.3 - 2020.0 1.2 - 827.6 1.1 - 209.1 1.1 - 10098.1 1.1 - 10098.1

Jordan’s 2016-2018 Results

Here, I average the ICU bed totals for each hospital 0ver 2016 to 2018. I also created a category of “unreliable”. For this, I categorized each hospital by whether they had any AHA survey response over the 3 years. Counties where the percent of general hospitals with no survey response over 3 years was greater than zero I marked county statistics as unreliable.

high (N=985) low (N=1014) None (N=687) unreliable (N=498) Total (N=3184)
Total population, thousands
- Mean (SD) 127.5 (218.0) 46.7 (105.7) 17.9 (20.6) 283.2 (721.4) 102.5 (327.8)
- Range 1.3 - 2020.0 1.1 - 2298.5 1.1 - 209.1 1.9 - 10098.1 1.1 - 10098.1

A Full County Characteristics Table for Show

high (N=985) low (N=1014) None (N=723) unreliable (N=498) Total (N=3220)
Total population, thousands
- Mean (SD) 127.5 (218.0) 46.7 (105.7) 17.0 (20.4) 283.2 (721.4) 101.3 (326.1)
- Range 1.3 - 2020.0 1.1 - 2298.5 0.1 - 209.1 1.9 - 10098.1 0.1 - 10098.1
Population 18+, %
- Mean (SD) 77.7 (2.9) 77.4 (3.5) 78.4 (4.0) 77.2 (3.4) 77.7 (3.5)
- Range 65.9 - 87.5 63.6 - 87.4 59.5 - 94.7 59.7 - 86.6 59.5 - 94.7
Persons 65+, %
- Mean (SD) 17.6 (4.0) 18.7 (4.4) 19.7 (5.0) 17.2 (4.6) 18.4 (4.5)
- Range 7.9 - 39.0 6.4 - 35.9 5.6 - 55.6 3.8 - 37.9 3.8 - 55.6
Female, %
- Mean (SD) 50.5 (1.7) 49.7 (2.3) 49.5 (3.2) 50.2 (2.1) 50.0 (2.4)
- Range 37.1 - 55.1 33.7 - 55.7 21.0 - 58.6 33.4 - 56.0 21.0 - 58.6
White, %
- Mean (SD) 82.7 (14.8) 85.9 (15.2) 82.0 (19.8) 76.8 (19.1) 82.6 (17.1)
- Range 17.3 - 99.1 11.0 - 99.9 3.9 - 100.0 9.4 - 99.2 3.9 - 100.0
Black, %
- Mean (SD) 10.0 (13.9) 6.8 (13.2) 9.8 (16.3) 11.0 (15.3) 9.1 (14.6)
- Range 0.0 - 77.5 0.0 - 87.4 0.0 - 82.6 0.0 - 72.3 0.0 - 87.4
Asian, %
- Mean (SD) 1.6 (2.2) 1.0 (2.0) 0.7 (2.4) 2.4 (4.7) 1.3 (2.8)
- Range 0.0 - 23.9 0.0 - 28.1 0.0 - 40.0 0.0 - 42.5 0.0 - 42.5
American Indian/Alaskan Native, %
- Mean (SD) 1.1 (3.3) 1.9 (6.6) 2.2 (9.8) 3.3 (11.2) 1.9 (7.6)
- Range 0.0 - 42.0 0.0 - 82.7 0.0 - 92.5 0.0 - 83.7 0.0 - 92.5
Native Hawaiian/Pacific Islander, %
- Mean (SD) 0.1 (0.2) 0.1 (0.1) 0.1 (1.0) 0.2 (1.0) 0.1 (0.6)
- Range 0.0 - 1.4 0.0 - 1.4 0.0 - 25.3 0.0 - 12.4 0.0 - 25.3
Other Race, %
- Mean (SD) 2.1 (3.4) 2.1 (4.3) 3.0 (7.7) 3.3 (5.6) 2.5 (5.2)
- Range 0.0 - 38.8 0.0 - 57.0 0.0 - 69.4 0.0 - 65.7 0.0 - 69.4
2+ Races, %
- Mean (SD) 2.4 (1.6) 2.3 (1.9) 2.2 (2.7) 3.0 (2.8) 2.4 (2.2)
- Range 0.0 - 19.7 0.0 - 19.0 0.0 - 32.1 0.0 - 28.7 0.0 - 32.1
Any racial minority, %
- Mean (SD) 17.3 (14.8) 14.1 (15.2) 18.0 (19.8) 23.2 (19.1) 17.4 (17.1)
- Range 0.9 - 82.7 0.1 - 89.0 0.0 - 96.1 0.8 - 90.6 0.0 - 96.1
Hispanic, %
- Mean (SD) 9.6 (14.4) 9.6 (14.2) 15.2 (28.4) 13.4 (19.9) 11.4 (19.4)
- Range 0.0 - 99.7 0.1 - 99.1 0.0 - 100.0 0.1 - 99.6 0.0 - 100.0
Mean individual income, $1000
- N-Miss 0 1 0 0 1
- Mean (SD) 27.5 (6.5) 27.0 (6.2) 24.5 (7.6) 27.3 (7.5) 26.6 (6.9)
- Range 8.3 - 72.8 13.2 - 69.3 6.0 - 69.8 8.6 - 64.2 6.0 - 72.8
Median family income, $1000
- N-Miss 0 1 0 0 1
- Mean (SD) 64.7 (15.5) 64.7 (15.7) 57.9 (18.5) 64.1 (18.1) 63.1 (16.9)
- Range 19.5 - 154.2 21.8 - 153.5 14.4 - 178.5 17.7 - 140.4 14.4 - 178.5
Median household income, $1000
- N-Miss 0 1 0 0 1
- Mean (SD) 51.5 (12.9) 52.4 (13.9) 46.8 (15.6) 51.9 (15.6) 50.8 (14.5)
- Range 15.0 - 117.4 20.2 - 136.3 12.8 - 124.8 14.1 - 121.1 12.8 - 136.3
Income Disparity
- N-Miss 0 1 0 0 1
- Mean (SD) 2.6 (0.6) 2.5 (0.6) -Inf (NaN) 2.7 (0.8) -Inf (NaN)
- Range 0.8 - 5.9 0.3 - 4.8 -Inf - 7.3 0.8 - 5.9 -Inf - 7.3
Population below poverty level, %
- N-Miss 0 1 0 0 1
- Mean (SD) 16.0 (6.2) 14.7 (6.2) 18.7 (11.8) 17.2 (8.2) 16.4 (8.2)
- Range 3.5 - 52.2 2.3 - 49.7 2.6 - 64.2 3.7 - 57.2 2.3 - 64.2
Families below poverty level, %
- N-Miss 0 1 0 0 1
- Mean (SD) 11.5 (5.7) 10.5 (5.4) 14.4 (11.4) 12.8 (7.6) 12.0 (7.7)
- Range 0.4 - 48.7 0.7 - 42.7 0.0 - 60.8 1.8 - 53.8 0.0 - 60.8
Owner-occupied housing units, %
- Mean (SD) 68.8 (7.7) 73.8 (6.3) 74.4 (8.3) 67.3 (9.4) 71.4 (8.2)
- Range 19.6 - 84.0 43.1 - 89.7 4.3 - 92.4 26.0 - 84.2 4.3 - 92.4
Median home value, $1000
- N-Miss 0 0 2 0 2
- Mean (SD) 155.1 (86.2) 140.2 (85.2) 125.8 (67.5) 169.9 (119.4) 146.1 (89.4)
- Range 33.8 - 944.6 34.1 - 1056.5 20.7 - 757.3 33.5 - 1009.5 20.7 - 1056.5
Median monthly mortgage, $1000
- N-Miss 0 0 4 0 4
- Mean (SD) 1.2 (0.3) 1.2 (0.3) 1.1 (0.3) 1.3 (0.4) 1.2 (0.3)
- Range 0.7 - 3.4 0.7 - 3.5 0.6 - 3.3 0.7 - 3.5 0.6 - 3.5
Median gross rent, $
- N-Miss 0 0 1 0 1
- Mean (SD) 438.6 (131.7) 423.1 (103.5) 370.1 (105.4) 437.1 (153.9) 418.1 (124.6)
- Range 119.0 - 1426.0 192.0 - 1161.0 102.0 - 1171.0 127.0 - 1360.0 102.0 - 1426.0
Households without a motor vehicle, %
- Mean (SD) 6.9 (3.9) 5.6 (3.4) 6.7 (5.8) 7.7 (6.1) 6.6 (4.7)
- Range 1.3 - 77.0 0.0 - 56.5 0.0 - 87.8 0.7 - 65.7 0.0 - 87.8
Households without a telephone, %
- N-Miss 2 2 0 0 4
- Mean (SD) 2.5 (1.2) 2.5 (1.9) 2.7 (2.2) 2.5 (1.4) 2.6 (1.7)
- Range 0.0 - 11.4 0.0 - 27.9 0.0 - 21.9 0.0 - 12.1 0.0 - 27.9
Households without computer, %
- N-Miss 6 0 58 14 78
- Mean (SD) 84.7 (6.0) 83.5 (6.5) 80.8 (7.9) 84.4 (7.3) 83.4 (6.9)
- Range 50.4 - 98.0 50.7 - 97.0 38.3 - 98.6 39.7 - 97.2 38.3 - 98.6
Housing units without complete plumbing, %
- Mean (SD) 0.5 (0.5) 0.6 (1.3) 0.9 (2.1) 0.7 (1.6) 0.7 (1.4)
- Range 0.0 - 6.8 0.0 - 34.8 0.0 - 35.4 0.0 - 22.2 0.0 - 35.4
Without health insurance, %
- Mean (SD) 9.5 (4.2) 10.1 (5.3) 10.5 (5.9) 9.9 (5.0) 10.0 (5.1)
- Range 2.0 - 35.4 1.8 - 39.5 1.7 - 45.6 2.0 - 38.2 1.7 - 45.6
Population 25+ with < 9 years of education, %
- N-Miss 6 0 58 14 78
- Mean (SD) 4.7 (3.1) 5.0 (3.9) 5.5 (4.2) 5.0 (3.1) 5.0 (3.6)
- Range 0.5 - 26.4 0.5 - 35.1 0.0 - 39.6 0.6 - 24.8 0.0 - 39.6
Population 25+ with < high school diploma, %
- N-Miss 6 0 58 14 78
- Mean (SD) 12.7 (5.6) 13.2 (6.5) 14.8 (7.2) 13.3 (5.7) 13.4 (6.3)
- Range 2.0 - 40.3 2.8 - 48.5 1.2 - 66.3 3.3 - 35.4 1.2 - 66.3
Population 25+ with at least high school diploma, %
- N-Miss 6 0 58 14 78
- Mean (SD) 87.3 (5.6) 86.8 (6.5) 85.2 (7.2) 86.7 (5.7) 86.6 (6.3)
- Range 59.7 - 98.0 51.5 - 97.2 33.7 - 98.8 64.6 - 96.7 33.7 - 98.8
Employed persons 16+ in white collar occupations, %
- N-Miss 0 1 0 0 1
- Mean (SD) 32.5 (6.3) 31.6 (6.4) 30.4 (7.1) 33.0 (6.7) 31.8 (6.6)
- Range 13.7 - 69.2 14.5 - 60.7 11.8 - 68.0 17.1 - 62.3 11.8 - 69.2
Civilian labor force population16+ unemployed, %
- N-Miss 0 1 0 0 1
- Mean (SD) 3.4 (1.1) 3.0 (1.4) 3.5 (2.4) 3.7 (1.7) 3.4 (1.7)
- Range 0.2 - 10.2 0.0 - 15.0 0.0 - 16.5 0.4 - 14.9 0.0 - 16.5
Civilian population not in an institution, 5+ and with a disability, %
- N-Miss 6 0 58 14 78
- Mean (SD) 15.5 (3.9) 15.8 (4.4) 17.3 (4.9) 15.1 (4.1) 15.9 (4.4)
- Range 3.8 - 32.6 4.3 - 31.6 5.1 - 33.6 6.9 - 33.7 3.8 - 33.7
Individuals speak English < “very well”, %
- N-Miss 6 0 58 14 78
- Mean (SD) 3.4 (4.3) 3.2 (4.4) 2.7 (5.2) 4.6 (5.5) 3.4 (4.8)
- Range 0.0 - 37.6 0.0 - 47.7 0.0 - 48.8 0.0 - 34.8 0.0 - 48.8
Single-parent households with children <18, %
- N-Miss 6 0 58 14 78
- Mean (SD) 8.8 (2.2) 7.9 (2.5) 7.6 (3.4) 9.0 (2.8) 8.3 (2.8)
- Range 2.9 - 19.1 0.0 - 21.4 0.0 - 25.6 1.5 - 25.5 0.0 - 25.6
Households > 1 person per room, %
- Mean (SD) 2.3 (1.5) 2.3 (2.1) 2.5 (3.0) 3.0 (3.3) 2.4 (2.4)
- Range 0.0 - 12.6 0.0 - 35.4 0.0 - 49.3 0.0 - 35.8 0.0 - 49.3
Population in multi-unit housing, %
- Mean (SD) 16.4 (9.5) 10.3 (6.5) 7.5 (6.6) 17.4 (12.3) 12.6 (9.4)
- Range 3.5 - 98.0 0.1 - 72.3 0.0 - 61.6 1.3 - 86.1 0.0 - 98.0
Mobile homes, %
- Mean (SD) 10.9 (8.2) 12.7 (9.0) 15.7 (11.4) 11.3 (10.0) 12.6 (9.7)
- Range 0.0 - 43.4 0.1 - 51.8 0.0 - 59.3 0.1 - 52.6 0.0 - 59.3