Code
# Load packages
library(here) # relative filepaths for reproducibility
library(tidyverse) # data wrangling
library(stringi) # string wrangling
library(kableExtra) # table formatting
library(tidycensus) # census data
Now that we have learned about the importance of utilizing reproducible tools for data-oriented projects, we will spend the next few weeks putting these tools into practice by managing a project of our own from start-to-finish.
The project that we will be completing will take the form of a web-based report on the most socially vulnerable areas in the United States broadly as well as within specific US Census Divisions and whether or not we believe that the New Market and Low Income Housing Tax Credit programs which are aimed at community development have had an impact on reducing social vulnerability from 2010 to 2020. As a team, you will summarize your findings and each individual team member will provide specifics on a census division of their choosing.
For Lab 02 and Lab 03 we will be focusing on building a customized version of the CDC’s Social Vulnerability Index for our report and visualizing the indices across our region of interest.
Before we explore the data, let’s gain an overview of the CDC Social Vulnerability Index (CDC SVI):
As detailed in the video above, US Census data is divided into a variety of geographies, starting with census blocks as the smallest units of analysis that are then aggregated up to state, divisional, and regional level data.
Recall from the previous section that we have two datasets for this course where we’ve pulled US Census Data to compare across 2010 and 2020. In order to do this, we pulled Census-Tract level data for 2010 and Census Block Group level data for 2020.
Why two different levels of data?
Well, as explained in the video, the boundaries of Census Tracts change every decade. Thus, we cannot directly compare 2010 and 2020 Census Tracts.
Look at the example below from GIS software company Esri:
[This] area represented by a single San Diego County Census Tract from the 2010 Census is now represented by seven (7) new Census Tracts in 2020. Additionally, only a portion of new Census Tract 133.16 covers area originally contained in Census Tract 133.1.
When comparing population changes for an area across a span of time, we want to be sure that we are actually comparing the same geographic boundaries. Thus, in order to see how people in an area defined in 2010 are functioning in 2020, we must convert our 2020 to data to ensure that it falls within the same boundaries as those specified in 2010.
To accomplish this, we can tighten our geographic boundaries in 2020 to pull data on Census Block Groups. Remember from the video, Census Block Groups (CBGs) are small chunks of geography that represent neighborhoods and fall within the bounds of Census Tracts. We can then utilize methodologies employed by GIS and population experts to calculate what percentage of these Census Block Groups fall within a broader boundary and create a more accurate comparison across time.
Thus to create the data for this project, CBG-level data for 2020 was pulled from the US Census Bureau. This data was then weighted using a crosswalk file from the IPUMS National Historical Geographic Information System (NHGIS) to determine which blocks belong to the 2010 census tracts. Once the 2020 Census Block Groups data was assigned to 2010 Census Tracts, it was aggregated to find counts within the geographic boundaries of the 2010 Census Tract data.
Because of this crosswalk, we are now able to equitably compare 2010 and 2020 changes within a reasonable margin of error. We can also aggregate our 2010 and 2020 data even further to find calculations on county, state, divisional, regional, and national-level issues as highlighted in the map below:
Recall from Lab 01 that to complete your work for the course, each member of your group will select a different division of interest and conduct your analyses on that specific division.
Then as a group, you will compare your findings across the different divisions and highlight whether you believe the Tax Credit Programs were effective for all of your divisions, some of them, none of them, or in certain divisions versus others.
All of the tutorials throughout the course will use the Middle Atlantic Division for examples. Thus, students can not pick this division. However, all other divisions are available for selection with the limitation that each member of a group must select a unique division within their group. This selection should have been made during week 1. If you do not have a division for some reason, check with your teammates before beginning this lab.
Now that we have a general overview of the CDC’s SVI Program and the intricacies of US Census Geography, feel free to review the following resources for more details.
Once you feel comfortable with the material, we can then embark on creating the reusable functions we will cite throughout the course to create our SVI indices and examine our division of interest.
CDC Social Vulnerability Index:
Overview:
CDC SVI Calculation Methodology:
US Census Data:
US Census Regions and Divisions: - https://www2.census.gov/geo/pdfs/maps-data/maps/reference/us_regdiv.pdf
US Census Geography: - https://learn.arcgis.com/en/related-concepts/united-states-census-geography.htm
Census API Documentation: - https://www.census.gov/data/developers/data-sets/acs-5year.html
Census API Guide: - https://www.census.gov/data/developers/guidance/api-user-guide.html
Census GEOIDs Documentation: - https://www.census.gov/programs-surveys/geography/guidance/geo-identifiers.html
Census Regions: - https://www2.census.gov/geo/pdfs/maps-data/maps/reference/us_regdiv.pdf
NHGIS Data Crosswalk 2020 Block Group to 2010 Census Tract: - https://www.nhgis.org/geographic-crosswalks
Functions in R and Related Topics:
Functions in R:
String/Character Manipulation in the tidyverse:
String/Character Manipulation with stringi:
Grepl/Regular Expressions in R:
https://bookdown.org/rdpeng/rprogdatascience/regular-expressions.html
https://www.r-bloggers.com/2019/05/demystifying-regular-expressions-in-r/
https://github.com/Watts-College/cpp-528-fall-2021/blob/main/lectures/RegExCheatsheetInR.pdf
If/Else Statements:
For Loop:
Injection Operator with environment variables in R:
To begin this week’s lab we need to load up our R libraries:
# Load packages
library(here) # relative filepaths for reproducibility
library(tidyverse) # data wrangling
library(stringi) # string wrangling
library(kableExtra) # table formatting
library(tidycensus) # census data
Next, as we learned last week in our introduction to reproducibility for data project management, we can import constants and functions from separate .R files.
Remember that your API key is a password, so all results of this chunk should be set to ‘hide’.
If for some reason you have not yet requested an API key, visit https://api.census.gov/data/key_signup.html
# Load API key, assign to TidyCensus Package
source(here::here("analysis/password.R"))
census_api_key(census_api_key)
Recall that last week we created a R file called project_data_steps_[your initials].R (for example, my file labeled with my intials would be project_data_steps_CS.R
).
In this file, you should have a library section with the libraries above and a variable called author
that has your name assigned to it:
#
# Author: Courtney Stowers
# Date: December 11, 2023
# Purpose: Create custom functions to process data for SVI Tax Credit Project
#
# Library ----
library(here)
library(tidyverse)
library(stringi)
library(kableExtra)
library(tidycensus)
# Variables ----
author <- "Courtney Stowers"
census_division <- "Middle Atlantic Division"
Next, we can import our author variable from our project_data_steps.R file to ensure that it works. Note this is different from the source() function used for our API key because it imports specific items from the file instead of the complete file.
Recall that we should use the here::here()
function for relative file paths. We also use double colons ::
to indicate both the specific library and function name we want to use to avoid any overriding.
Once we have our functions loaded, we can load in the data sets we will need and preview them:
#Load US Census region data
census_regions <- readxl::read_excel(here::here("data/raw/Census_Data_SVI/census_regions.xlsx"))
# Load SVI data sets
svi_2010 <- readRDS(here::here("data/raw/Census_Data_SVI/svi_2010_trt10.rds"))
svi_2020 <- readRDS(here::here("data/raw/Census_Data_SVI/svi_2020_trt10.rds"))
# Load FIPS codes from TidyCensus
fips <- tidycensus::fips_codes
fips %>% head() %>% kbl() %>% kable_styling() %>% scroll_box(width = "100%")
state | state_code | state_name | county_code | county |
---|---|---|---|---|
AL | 01 | Alabama | 001 | Autauga County |
AL | 01 | Alabama | 003 | Baldwin County |
AL | 01 | Alabama | 005 | Barbour County |
AL | 01 | Alabama | 007 | Bibb County |
AL | 01 | Alabama | 009 | Blount County |
AL | 01 | Alabama | 011 | Bullock County |
[1] "Region_Number" "Region" "Division_Number" "Division"
[5] "State"
region_number | region | division_number | division | state |
---|---|---|---|---|
4 | West Region | 9 | Pacific Division | AK |
3 | South Region | 6 | East South Central Division | AL |
3 | South Region | 7 | West South Central Division | AR |
4 | West Region | 8 | Mountain Division | AZ |
4 | West Region | 9 | Pacific Division | CA |
4 | West Region | 8 | Mountain Division | CO |
# Join FIPS codes to regions data
fips_census_regions <- left_join(fips, census_regions, join_by("state" == "state"))
fips_census_regions %>% head() %>% kbl() %>% kable_styling() %>% scroll_box(width = "100%")
state | state_code | state_name | county_code | county | region_number | region | division_number | division |
---|---|---|---|---|---|---|---|---|
AL | 01 | Alabama | 001 | Autauga County | 3 | South Region | 6 | East South Central Division |
AL | 01 | Alabama | 003 | Baldwin County | 3 | South Region | 6 | East South Central Division |
AL | 01 | Alabama | 005 | Barbour County | 3 | South Region | 6 | East South Central Division |
AL | 01 | Alabama | 007 | Bibb County | 3 | South Region | 6 | East South Central Division |
AL | 01 | Alabama | 009 | Blount County | 3 | South Region | 6 | East South Central Division |
AL | 01 | Alabama | 011 | Bullock County | 3 | South Region | 6 | East South Central Division |
[1] "GEOID_2010_trt" "E_TOTPOP_10" "E_HU_10"
[4] "E_HH_10" "E_POV150_10" "ET_POVSTATUS_10"
[7] "EP_POV150_10" "EPL_POV150_10" "E_UNEMP_10"
[10] "ET_EMPSTATUS_10" "EP_UNEMP_10" "EPL_UNEMP_10"
[13] "E_HBURD_OWN_10" "ET_HOUSINGCOST_OWN_10" "EP_HBURD_OWN_10"
[16] "EPL_HBURD_OWN_10" "E_HBURD_RENT_10" "ET_HOUSINGCOST_RENT_10"
[19] "EP_HBURD_RENT_10" "EPL_HBURD_RENT_10" "E_HBURD_10"
[22] "ET_HOUSINGCOST_10" "EP_HBURD_10" "EPL_HBURD_10"
[25] "E_NOHSDP_10" "ET_EDSTATUS_10" "EP_NOHSDP_10"
[28] "EPL_NOHSDP_10" "E_UNINSUR_12" "ET_INSURSTATUS_12"
[31] "EP_UNINSUR_12" "EPL_UNINSUR_12" "E_AGE65_10"
[34] "EP_AGE65_10" "EPL_AGE65_10" "E_AGE17_10"
[37] "EP_AGE17_10" "EPL_AGE17_10" "E_DISABL_12"
[40] "ET_DISABLSTATUS_12" "EP_DISABL_12" "EPL_DISABL_12"
[43] "E_SNGPNT_10" "ET_FAMILIES_10" "EP_SNGPNT_10"
[46] "EPL_SNGPNT_10" "E_LIMENG_10" "ET_POPAGE5UP_10"
[49] "EP_LIMENG_10" "EPL_LIMENG_10" "E_MINRTY_10"
[52] "ET_POPETHRACE_10" "EP_MINRTY_10" "EPL_MINRTY_10"
[55] "E_STRHU_10" "E_MUNIT_10" "EP_MUNIT_10"
[58] "EPL_MUNIT_10" "E_MOBILE_10" "EP_MOBILE_10"
[61] "EPL_MOBILE_10" "E_CROWD_10" "ET_OCCUPANTS_10"
[64] "EP_CROWD_10" "EPL_CROWD_10" "E_NOVEH_10"
[67] "ET_KNOWNVEH_10" "EP_NOVEH_10" "EPL_NOVEH_10"
[70] "E_GROUPQ_10" "ET_HHTYPE_10" "EP_GROUPQ_10"
[73] "EPL_GROUPQ_10"
svi_2010 %>% head() %>% kbl() %>% kable_styling() %>% scroll_box(width = "100%")
GEOID_2010_trt | E_TOTPOP_10 | E_HU_10 | E_HH_10 | E_POV150_10 | ET_POVSTATUS_10 | EP_POV150_10 | EPL_POV150_10 | E_UNEMP_10 | ET_EMPSTATUS_10 | EP_UNEMP_10 | EPL_UNEMP_10 | E_HBURD_OWN_10 | ET_HOUSINGCOST_OWN_10 | EP_HBURD_OWN_10 | EPL_HBURD_OWN_10 | E_HBURD_RENT_10 | ET_HOUSINGCOST_RENT_10 | EP_HBURD_RENT_10 | EPL_HBURD_RENT_10 | E_HBURD_10 | ET_HOUSINGCOST_10 | EP_HBURD_10 | EPL_HBURD_10 | E_NOHSDP_10 | ET_EDSTATUS_10 | EP_NOHSDP_10 | EPL_NOHSDP_10 | E_UNINSUR_12 | ET_INSURSTATUS_12 | EP_UNINSUR_12 | EPL_UNINSUR_12 | E_AGE65_10 | EP_AGE65_10 | EPL_AGE65_10 | E_AGE17_10 | EP_AGE17_10 | EPL_AGE17_10 | E_DISABL_12 | ET_DISABLSTATUS_12 | EP_DISABL_12 | EPL_DISABL_12 | E_SNGPNT_10 | ET_FAMILIES_10 | EP_SNGPNT_10 | EPL_SNGPNT_10 | E_LIMENG_10 | ET_POPAGE5UP_10 | EP_LIMENG_10 | EPL_LIMENG_10 | E_MINRTY_10 | ET_POPETHRACE_10 | EP_MINRTY_10 | EPL_MINRTY_10 | E_STRHU_10 | E_MUNIT_10 | EP_MUNIT_10 | EPL_MUNIT_10 | E_MOBILE_10 | EP_MOBILE_10 | EPL_MOBILE_10 | E_CROWD_10 | ET_OCCUPANTS_10 | EP_CROWD_10 | EPL_CROWD_10 | E_NOVEH_10 | ET_KNOWNVEH_10 | EP_NOVEH_10 | EPL_NOVEH_10 | E_GROUPQ_10 | ET_HHTYPE_10 | EP_GROUPQ_10 | EPL_GROUPQ_10 |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
01001020100 | 1809 | 771 | 696 | 297 | 1809 | 16.41791 | NA | 36 | 889 | 4.049494 | NA | 127 | 598 | 21.23746 | NA | 47 | 98 | 47.95918 | NA | 174 | 696 | 25.00000 | NA | 196 | 1242 | 15.780998 | NA | 186 | 1759 | 10.574190 | NA | 222 | 12.271973 | NA | 445 | 24.59923 | NA | 298 | 1335 | 22.32210 | NA | 27 | 545 | 4.954128 | NA | 36 | 1705 | 2.1114370 | NA | 385 | 1809 | 21.282477 | NA | 771 | 0 | 0.0000000 | NA | 92 | 11.9325551 | NA | 0 | 696 | 0.0000000 | NA | 50 | 696 | 7.183908 | NA | 0 | 1809 | 0 | NA |
01001020200 | 2020 | 816 | 730 | 495 | 1992 | 24.84940 | NA | 68 | 834 | 8.153477 | NA | 49 | 439 | 11.16173 | NA | 105 | 291 | 36.08247 | NA | 154 | 730 | 21.09589 | NA | 339 | 1265 | 26.798419 | NA | 313 | 2012 | 15.556660 | NA | 204 | 10.099010 | NA | 597 | 29.55446 | NA | 359 | 1515 | 23.69637 | NA | 132 | 456 | 28.947368 | NA | 15 | 1890 | 0.7936508 | NA | 1243 | 2020 | 61.534653 | NA | 816 | 0 | 0.0000000 | NA | 34 | 4.1666667 | NA | 13 | 730 | 1.7808219 | NA | 115 | 730 | 15.753425 | NA | 0 | 2020 | 0 | NA |
01001020300 | 3543 | 1403 | 1287 | 656 | 3533 | 18.56779 | NA | 93 | 1552 | 5.992268 | NA | 273 | 957 | 28.52665 | NA | 178 | 330 | 53.93939 | NA | 451 | 1287 | 35.04274 | NA | 346 | 2260 | 15.309734 | NA | 252 | 3102 | 8.123791 | NA | 487 | 13.745413 | NA | 998 | 28.16822 | NA | 371 | 2224 | 16.68165 | NA | 126 | 913 | 13.800657 | NA | 0 | 3365 | 0.0000000 | NA | 637 | 3543 | 17.979114 | NA | 1403 | 10 | 0.7127584 | NA | 2 | 0.1425517 | NA | 0 | 1287 | 0.0000000 | NA | 101 | 1287 | 7.847708 | NA | 0 | 3543 | 0 | NA |
01001020400 | 4840 | 1957 | 1839 | 501 | 4840 | 10.35124 | NA | 101 | 2129 | 4.744011 | NA | 310 | 1549 | 20.01291 | NA | 89 | 290 | 30.68966 | NA | 399 | 1839 | 21.69657 | NA | 274 | 3280 | 8.353658 | NA | 399 | 4293 | 9.294200 | NA | 955 | 19.731405 | NA | 1195 | 24.69008 | NA | 625 | 3328 | 18.78005 | NA | 152 | 1374 | 11.062591 | NA | 10 | 4537 | 0.2204100 | NA | 297 | 4840 | 6.136364 | NA | 1957 | 33 | 1.6862545 | NA | 25 | 1.2774655 | NA | 14 | 1839 | 0.7612833 | NA | 19 | 1839 | 1.033170 | NA | 0 | 4840 | 0 | NA |
01001020500 | 9938 | 3969 | 3741 | 1096 | 9938 | 11.02838 | NA | 188 | 4937 | 3.807981 | NA | 426 | 2406 | 17.70574 | NA | 528 | 1335 | 39.55056 | NA | 954 | 3741 | 25.50120 | NA | 293 | 5983 | 4.897209 | NA | 740 | 10110 | 7.319486 | NA | 837 | 8.422218 | NA | 3012 | 30.30791 | NA | 759 | 7155 | 10.60797 | NA | 476 | 2529 | 18.821669 | NA | 78 | 9297 | 0.8389803 | NA | 1970 | 9938 | 19.822902 | NA | 3969 | 306 | 7.7097506 | NA | 0 | 0.0000000 | NA | 7 | 3741 | 0.1871157 | NA | 223 | 3741 | 5.960973 | NA | 0 | 9938 | 0 | NA |
01001020600 | 3402 | 1456 | 1308 | 735 | 3402 | 21.60494 | NA | 134 | 1720 | 7.790698 | NA | 242 | 1032 | 23.44961 | NA | 62 | 276 | 22.46377 | NA | 304 | 1308 | 23.24159 | NA | 301 | 2151 | 13.993491 | NA | 355 | 3445 | 10.304790 | NA | 386 | 11.346267 | NA | 931 | 27.36626 | NA | 440 | 2439 | 18.04018 | NA | 143 | 924 | 15.476190 | NA | 4 | 3254 | 0.1229256 | NA | 723 | 3402 | 21.252205 | NA | 1456 | 18 | 1.2362637 | NA | 433 | 29.7390110 | NA | 16 | 1308 | 1.2232416 | NA | 28 | 1308 | 2.140673 | NA | 0 | 3402 | 0 | NA |
We can then repeat these steps for our 2020 data:
[1] "GEOID_2010_trt" "E_TOTPOP_20" "E_HU_20"
[4] "E_HH_20" "E_POV150_20" "ET_POVSTATUS_20"
[7] "EP_POV150_20" "EPL_POV150_20" "E_UNEMP_20"
[10] "ET_EMPSTATUS_20" "EP_UNEMP_20" "EPL_UNEMP_20"
[13] "E_HBURD_OWN_20" "ET_HOUSINGCOST_OWN_20" "EP_HBURD_OWN_20"
[16] "EPL_HBURD_OWN_20" "E_HBURD_RENT_20" "ET_HOUSINGCOST_RENT_20"
[19] "EP_HBURD_RENT_20" "EPL_HBURD_RENT_20" "E_HBURD_20"
[22] "ET_HOUSINGCOST_20" "EP_HBURD_20" "EPL_HBURD_20"
[25] "E_NOHSDP_20" "ET_EDSTATUS_20" "EP_NOHSDP_20"
[28] "EPL_NOHSDP_20" "E_UNINSUR_20" "ET_INSURSTATUS_20"
[31] "EP_UNINSUR_20" "EPL_UNINSUR_20" "E_AGE65_20"
[34] "EP_AGE65_20" "EPL_AGE65_20" "E_AGE17_20"
[37] "EP_AGE17_20" "EPL_AGE17_20" "E_DISABL_20"
[40] "ET_DISABLSTATUS_20" "EP_DISABL_20" "EPL_DISABL_20"
[43] "E_SNGPNT_20" "ET_FAMILIES_20" "EP_SNGPNT_20"
[46] "EPL_SNGPNT_20" "E_LIMENG_20" "ET_POPAGE5UP_20"
[49] "EP_LIMENG_20" "EPL_LIMENG_20" "E_MINRTY_20"
[52] "ET_POPETHRACE_20" "EP_MINRTY_20" "EPL_MINRTY_20"
[55] "E_STRHU_20" "E_MUNIT_20" "EP_MUNIT_20"
[58] "EPL_MUNIT_20" "E_MOBILE_20" "EP_MOBILE_20"
[61] "EPL_MOBILE_20" "E_CROWD_20" "ET_OCCUPANTS_20"
[64] "EP_CROWD_20" "EPL_CROWD_20" "E_NOVEH_20"
[67] "ET_KNOWNVEH_20" "EP_NOVEH_20" "EPL_NOVEH_20"
[70] "E_GROUPQ_20" "ET_HHTYPE_20" "EP_GROUPQ_20"
[73] "EPL_GROUPQ_20"
svi_2020 %>% head() %>% kbl() %>% kable_styling() %>% scroll_box(width = "100%")
GEOID_2010_trt | E_TOTPOP_20 | E_HU_20 | E_HH_20 | E_POV150_20 | ET_POVSTATUS_20 | EP_POV150_20 | EPL_POV150_20 | E_UNEMP_20 | ET_EMPSTATUS_20 | EP_UNEMP_20 | EPL_UNEMP_20 | E_HBURD_OWN_20 | ET_HOUSINGCOST_OWN_20 | EP_HBURD_OWN_20 | EPL_HBURD_OWN_20 | E_HBURD_RENT_20 | ET_HOUSINGCOST_RENT_20 | EP_HBURD_RENT_20 | EPL_HBURD_RENT_20 | E_HBURD_20 | ET_HOUSINGCOST_20 | EP_HBURD_20 | EPL_HBURD_20 | E_NOHSDP_20 | ET_EDSTATUS_20 | EP_NOHSDP_20 | EPL_NOHSDP_20 | E_UNINSUR_20 | ET_INSURSTATUS_20 | EP_UNINSUR_20 | EPL_UNINSUR_20 | E_AGE65_20 | EP_AGE65_20 | EPL_AGE65_20 | E_AGE17_20 | EP_AGE17_20 | EPL_AGE17_20 | E_DISABL_20 | ET_DISABLSTATUS_20 | EP_DISABL_20 | EPL_DISABL_20 | E_SNGPNT_20 | ET_FAMILIES_20 | EP_SNGPNT_20 | EPL_SNGPNT_20 | E_LIMENG_20 | ET_POPAGE5UP_20 | EP_LIMENG_20 | EPL_LIMENG_20 | E_MINRTY_20 | ET_POPETHRACE_20 | EP_MINRTY_20 | EPL_MINRTY_20 | E_STRHU_20 | E_MUNIT_20 | EP_MUNIT_20 | EPL_MUNIT_20 | E_MOBILE_20 | EP_MOBILE_20 | EPL_MOBILE_20 | E_CROWD_20 | ET_OCCUPANTS_20 | EP_CROWD_20 | EPL_CROWD_20 | E_NOVEH_20 | ET_KNOWNVEH_20 | EP_NOVEH_20 | EPL_NOVEH_20 | E_GROUPQ_20 | ET_HHTYPE_20 | EP_GROUPQ_20 | EPL_GROUPQ_20 |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
01001020100 | 1941 | 710 | 693 | 352 | 1941 | 18.13498 | NA | 18 | 852 | 2.112676 | NA | 81 | 507 | 15.976331 | NA | 63 | 186 | 33.87097 | NA | 144 | 693 | 20.77922 | NA | 187 | 1309 | 14.285714 | NA | 187 | 1941 | 9.634209 | NA | 295 | 15.19835 | NA | 415 | 21.38073 | NA | 391 | 1526 | 25.62254 | NA | 58 | 555 | 10.45045 | NA | 0 | 1843 | 0.0000000 | NA | 437 | 1941 | 22.51417 | NA | 710 | 0 | 0.0000000 | NA | 88 | 12.3943662 | NA | 0 | 693 | 0.0000000 | NA | 10 | 693 | 1.443001 | NA | 0 | 1941 | 0.000000 | NA |
01001020200 | 1757 | 720 | 573 | 384 | 1511 | 25.41363 | NA | 29 | 717 | 4.044630 | NA | 33 | 392 | 8.418367 | NA | 116 | 181 | 64.08840 | NA | 149 | 573 | 26.00349 | NA | 139 | 1313 | 10.586443 | NA | 91 | 1533 | 5.936073 | NA | 284 | 16.16392 | NA | 325 | 18.49744 | NA | 164 | 1208 | 13.57616 | NA | 42 | 359 | 11.69916 | NA | 0 | 1651 | 0.0000000 | NA | 1116 | 1757 | 63.51736 | NA | 720 | 3 | 0.4166667 | NA | 5 | 0.6944444 | NA | 9 | 573 | 1.5706806 | NA | 57 | 573 | 9.947644 | NA | 212 | 1757 | 12.066022 | NA |
01001020300 | 3694 | 1464 | 1351 | 842 | 3694 | 22.79372 | NA | 53 | 1994 | 2.657974 | NA | 117 | 967 | 12.099276 | NA | 147 | 384 | 38.28125 | NA | 264 | 1351 | 19.54108 | NA | 317 | 2477 | 12.797739 | NA | 127 | 3673 | 3.457664 | NA | 464 | 12.56091 | NA | 929 | 25.14889 | NA | 473 | 2744 | 17.23761 | NA | 263 | 975 | 26.97436 | NA | 128 | 3586 | 3.5694367 | NA | 1331 | 3694 | 36.03140 | NA | 1464 | 26 | 1.7759563 | NA | 14 | 0.9562842 | NA | 35 | 1351 | 2.5906736 | NA | 42 | 1351 | 3.108808 | NA | 0 | 3694 | 0.000000 | NA |
01001020400 | 3539 | 1741 | 1636 | 503 | 3539 | 14.21305 | NA | 39 | 1658 | 2.352232 | NA | 219 | 1290 | 16.976744 | NA | 74 | 346 | 21.38728 | NA | 293 | 1636 | 17.90954 | NA | 173 | 2775 | 6.234234 | NA | 169 | 3529 | 4.788892 | NA | 969 | 27.38062 | NA | 510 | 14.41085 | NA | 670 | 3019 | 22.19278 | NA | 148 | 1137 | 13.01671 | NA | 89 | 3409 | 2.6107363 | NA | 454 | 3539 | 12.82848 | NA | 1741 | 143 | 8.2136703 | NA | 0 | 0.0000000 | NA | 10 | 1636 | 0.6112469 | NA | 72 | 1636 | 4.400978 | NA | 0 | 3539 | 0.000000 | NA |
01001020500 | 10674 | 4504 | 4424 | 1626 | 10509 | 15.47245 | NA | 81 | 5048 | 1.604596 | NA | 321 | 2299 | 13.962592 | NA | 711 | 2125 | 33.45882 | NA | 1032 | 4424 | 23.32731 | NA | 531 | 6816 | 7.790493 | NA | 301 | 10046 | 2.996217 | NA | 1613 | 15.11149 | NA | 2765 | 25.90407 | NA | 1124 | 7281 | 15.43744 | NA | 342 | 2912 | 11.74451 | NA | 52 | 9920 | 0.5241935 | NA | 2603 | 10674 | 24.38636 | NA | 4504 | 703 | 15.6083481 | NA | 29 | 0.6438721 | NA | 37 | 4424 | 0.8363472 | NA | 207 | 4424 | 4.679023 | NA | 176 | 10674 | 1.648866 | NA |
01001020600 | 3536 | 1464 | 1330 | 1279 | 3523 | 36.30429 | NA | 34 | 1223 | 2.780049 | NA | 321 | 1111 | 28.892889 | NA | 67 | 219 | 30.59361 | NA | 388 | 1330 | 29.17293 | NA | 306 | 2380 | 12.857143 | NA | 415 | 3496 | 11.870709 | NA | 547 | 15.46946 | NA | 982 | 27.77149 | NA | 729 | 2514 | 28.99761 | NA | 95 | 880 | 10.79545 | NA | 0 | 3394 | 0.0000000 | NA | 985 | 3536 | 27.85633 | NA | 1464 | 0 | 0.0000000 | NA | 364 | 24.8633880 | NA | 0 | 1330 | 0.0000000 | NA | 17 | 1330 | 1.278196 | NA | 0 | 3536 | 0.000000 | NA |
Once we have our data loaded, we can now begin creating our functions to generate our SVI percentile ranks. For our study, we will want to be able to generate SVI percentile ranks on 5 different Census geographic levels:
As we discussed in week one, when embarking on a large, reproducible data project it is important to always consider ways that we can write code that can be reused multiple times and for various purposes. Thus, when we create functions, we want to conscientiously consider what information should be a hard coded value in our code and what information should be a variable (meaning, something that we can easily change without rewriting our code).
Fortunately the R language has a lot of flexibility to allow for us to create functions with variable components. A few key elements to allow for this are the following:
While you should be familiar with the basics of function creation, string/character manipulation, regular expressions, if statements and for loops from previous courses in the PEDA program, Injection Operators may be an entirely new concept. No worries! We will learn how to utilize these tools together in the following step-by-step code. You can also refer back to the Additional Readings.
We can work directly in RMarkdown to create our functions and then copy them over to our project_data_steps.R file so we can re-import our functions later.
In order to assign our data to their respective divisions/regions, we need to have a function that will create FIPS codes columns and allow us to link our Census Data with our fips_census_regions data set.
We can look back at the US Census Bureau’s GeoIdentifier structure to understand how to breakdown the GEOID into state, county, and tract identifiers.
We can then translate this to a function called fips_region_assignment
:
fips_region_assignment <- function(df) {
# Create columns with fips codes for df
df <- df %>% mutate(FIPS_st = substr(GEOID_2010_trt, 1, 2),
FIPS_county = substr(GEOID_2010_trt, 3, 5),
FIPS_tract = substr(GEOID_2010_trt, 6, 11)) %>%
relocate(c(FIPS_st, FIPS_county, FIPS_tract),.after = GEOID_2010_trt)
# Join region data
df <- left_join(df, fips_census_regions, join_by("FIPS_st" == "state_code",
"FIPS_county" == "county_code")) %>%
relocate(c(state, state_name, county, region_number, region, division_number, division),.after = FIPS_tract)
# Output data frame
return(df)
}
2010:
svi_2010 <- fips_region_assignment(svi_2010)
svi_2010 %>% head() %>% kbl() %>% kable_styling() %>% scroll_box(width = "100%")
GEOID_2010_trt | FIPS_st | FIPS_county | FIPS_tract | state | state_name | county | region_number | region | division_number | division | E_TOTPOP_10 | E_HU_10 | E_HH_10 | E_POV150_10 | ET_POVSTATUS_10 | EP_POV150_10 | EPL_POV150_10 | E_UNEMP_10 | ET_EMPSTATUS_10 | EP_UNEMP_10 | EPL_UNEMP_10 | E_HBURD_OWN_10 | ET_HOUSINGCOST_OWN_10 | EP_HBURD_OWN_10 | EPL_HBURD_OWN_10 | E_HBURD_RENT_10 | ET_HOUSINGCOST_RENT_10 | EP_HBURD_RENT_10 | EPL_HBURD_RENT_10 | E_HBURD_10 | ET_HOUSINGCOST_10 | EP_HBURD_10 | EPL_HBURD_10 | E_NOHSDP_10 | ET_EDSTATUS_10 | EP_NOHSDP_10 | EPL_NOHSDP_10 | E_UNINSUR_12 | ET_INSURSTATUS_12 | EP_UNINSUR_12 | EPL_UNINSUR_12 | E_AGE65_10 | EP_AGE65_10 | EPL_AGE65_10 | E_AGE17_10 | EP_AGE17_10 | EPL_AGE17_10 | E_DISABL_12 | ET_DISABLSTATUS_12 | EP_DISABL_12 | EPL_DISABL_12 | E_SNGPNT_10 | ET_FAMILIES_10 | EP_SNGPNT_10 | EPL_SNGPNT_10 | E_LIMENG_10 | ET_POPAGE5UP_10 | EP_LIMENG_10 | EPL_LIMENG_10 | E_MINRTY_10 | ET_POPETHRACE_10 | EP_MINRTY_10 | EPL_MINRTY_10 | E_STRHU_10 | E_MUNIT_10 | EP_MUNIT_10 | EPL_MUNIT_10 | E_MOBILE_10 | EP_MOBILE_10 | EPL_MOBILE_10 | E_CROWD_10 | ET_OCCUPANTS_10 | EP_CROWD_10 | EPL_CROWD_10 | E_NOVEH_10 | ET_KNOWNVEH_10 | EP_NOVEH_10 | EPL_NOVEH_10 | E_GROUPQ_10 | ET_HHTYPE_10 | EP_GROUPQ_10 | EPL_GROUPQ_10 |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
01001020100 | 01 | 001 | 020100 | AL | Alabama | Autauga County | 3 | South Region | 6 | East South Central Division | 1809 | 771 | 696 | 297 | 1809 | 16.41791 | NA | 36 | 889 | 4.049494 | NA | 127 | 598 | 21.23746 | NA | 47 | 98 | 47.95918 | NA | 174 | 696 | 25.00000 | NA | 196 | 1242 | 15.780998 | NA | 186 | 1759 | 10.574190 | NA | 222 | 12.271973 | NA | 445 | 24.59923 | NA | 298 | 1335 | 22.32210 | NA | 27 | 545 | 4.954128 | NA | 36 | 1705 | 2.1114370 | NA | 385 | 1809 | 21.282477 | NA | 771 | 0 | 0.0000000 | NA | 92 | 11.9325551 | NA | 0 | 696 | 0.0000000 | NA | 50 | 696 | 7.183908 | NA | 0 | 1809 | 0 | NA |
01001020200 | 01 | 001 | 020200 | AL | Alabama | Autauga County | 3 | South Region | 6 | East South Central Division | 2020 | 816 | 730 | 495 | 1992 | 24.84940 | NA | 68 | 834 | 8.153477 | NA | 49 | 439 | 11.16173 | NA | 105 | 291 | 36.08247 | NA | 154 | 730 | 21.09589 | NA | 339 | 1265 | 26.798419 | NA | 313 | 2012 | 15.556660 | NA | 204 | 10.099010 | NA | 597 | 29.55446 | NA | 359 | 1515 | 23.69637 | NA | 132 | 456 | 28.947368 | NA | 15 | 1890 | 0.7936508 | NA | 1243 | 2020 | 61.534653 | NA | 816 | 0 | 0.0000000 | NA | 34 | 4.1666667 | NA | 13 | 730 | 1.7808219 | NA | 115 | 730 | 15.753425 | NA | 0 | 2020 | 0 | NA |
01001020300 | 01 | 001 | 020300 | AL | Alabama | Autauga County | 3 | South Region | 6 | East South Central Division | 3543 | 1403 | 1287 | 656 | 3533 | 18.56779 | NA | 93 | 1552 | 5.992268 | NA | 273 | 957 | 28.52665 | NA | 178 | 330 | 53.93939 | NA | 451 | 1287 | 35.04274 | NA | 346 | 2260 | 15.309734 | NA | 252 | 3102 | 8.123791 | NA | 487 | 13.745413 | NA | 998 | 28.16822 | NA | 371 | 2224 | 16.68165 | NA | 126 | 913 | 13.800657 | NA | 0 | 3365 | 0.0000000 | NA | 637 | 3543 | 17.979114 | NA | 1403 | 10 | 0.7127584 | NA | 2 | 0.1425517 | NA | 0 | 1287 | 0.0000000 | NA | 101 | 1287 | 7.847708 | NA | 0 | 3543 | 0 | NA |
01001020400 | 01 | 001 | 020400 | AL | Alabama | Autauga County | 3 | South Region | 6 | East South Central Division | 4840 | 1957 | 1839 | 501 | 4840 | 10.35124 | NA | 101 | 2129 | 4.744011 | NA | 310 | 1549 | 20.01291 | NA | 89 | 290 | 30.68966 | NA | 399 | 1839 | 21.69657 | NA | 274 | 3280 | 8.353658 | NA | 399 | 4293 | 9.294200 | NA | 955 | 19.731405 | NA | 1195 | 24.69008 | NA | 625 | 3328 | 18.78005 | NA | 152 | 1374 | 11.062591 | NA | 10 | 4537 | 0.2204100 | NA | 297 | 4840 | 6.136364 | NA | 1957 | 33 | 1.6862545 | NA | 25 | 1.2774655 | NA | 14 | 1839 | 0.7612833 | NA | 19 | 1839 | 1.033170 | NA | 0 | 4840 | 0 | NA |
01001020500 | 01 | 001 | 020500 | AL | Alabama | Autauga County | 3 | South Region | 6 | East South Central Division | 9938 | 3969 | 3741 | 1096 | 9938 | 11.02838 | NA | 188 | 4937 | 3.807981 | NA | 426 | 2406 | 17.70574 | NA | 528 | 1335 | 39.55056 | NA | 954 | 3741 | 25.50120 | NA | 293 | 5983 | 4.897209 | NA | 740 | 10110 | 7.319486 | NA | 837 | 8.422218 | NA | 3012 | 30.30791 | NA | 759 | 7155 | 10.60797 | NA | 476 | 2529 | 18.821669 | NA | 78 | 9297 | 0.8389803 | NA | 1970 | 9938 | 19.822902 | NA | 3969 | 306 | 7.7097506 | NA | 0 | 0.0000000 | NA | 7 | 3741 | 0.1871157 | NA | 223 | 3741 | 5.960973 | NA | 0 | 9938 | 0 | NA |
01001020600 | 01 | 001 | 020600 | AL | Alabama | Autauga County | 3 | South Region | 6 | East South Central Division | 3402 | 1456 | 1308 | 735 | 3402 | 21.60494 | NA | 134 | 1720 | 7.790698 | NA | 242 | 1032 | 23.44961 | NA | 62 | 276 | 22.46377 | NA | 304 | 1308 | 23.24159 | NA | 301 | 2151 | 13.993491 | NA | 355 | 3445 | 10.304790 | NA | 386 | 11.346267 | NA | 931 | 27.36626 | NA | 440 | 2439 | 18.04018 | NA | 143 | 924 | 15.476190 | NA | 4 | 3254 | 0.1229256 | NA | 723 | 3402 | 21.252205 | NA | 1456 | 18 | 1.2362637 | NA | 433 | 29.7390110 | NA | 16 | 1308 | 1.2232416 | NA | 28 | 1308 | 2.140673 | NA | 0 | 3402 | 0 | NA |
2020:
svi_2020 <- fips_region_assignment(svi_2020)
svi_2020 %>% head() %>% kbl() %>% kable_styling() %>% scroll_box(width = "100%")
GEOID_2010_trt | FIPS_st | FIPS_county | FIPS_tract | state | state_name | county | region_number | region | division_number | division | E_TOTPOP_20 | E_HU_20 | E_HH_20 | E_POV150_20 | ET_POVSTATUS_20 | EP_POV150_20 | EPL_POV150_20 | E_UNEMP_20 | ET_EMPSTATUS_20 | EP_UNEMP_20 | EPL_UNEMP_20 | E_HBURD_OWN_20 | ET_HOUSINGCOST_OWN_20 | EP_HBURD_OWN_20 | EPL_HBURD_OWN_20 | E_HBURD_RENT_20 | ET_HOUSINGCOST_RENT_20 | EP_HBURD_RENT_20 | EPL_HBURD_RENT_20 | E_HBURD_20 | ET_HOUSINGCOST_20 | EP_HBURD_20 | EPL_HBURD_20 | E_NOHSDP_20 | ET_EDSTATUS_20 | EP_NOHSDP_20 | EPL_NOHSDP_20 | E_UNINSUR_20 | ET_INSURSTATUS_20 | EP_UNINSUR_20 | EPL_UNINSUR_20 | E_AGE65_20 | EP_AGE65_20 | EPL_AGE65_20 | E_AGE17_20 | EP_AGE17_20 | EPL_AGE17_20 | E_DISABL_20 | ET_DISABLSTATUS_20 | EP_DISABL_20 | EPL_DISABL_20 | E_SNGPNT_20 | ET_FAMILIES_20 | EP_SNGPNT_20 | EPL_SNGPNT_20 | E_LIMENG_20 | ET_POPAGE5UP_20 | EP_LIMENG_20 | EPL_LIMENG_20 | E_MINRTY_20 | ET_POPETHRACE_20 | EP_MINRTY_20 | EPL_MINRTY_20 | E_STRHU_20 | E_MUNIT_20 | EP_MUNIT_20 | EPL_MUNIT_20 | E_MOBILE_20 | EP_MOBILE_20 | EPL_MOBILE_20 | E_CROWD_20 | ET_OCCUPANTS_20 | EP_CROWD_20 | EPL_CROWD_20 | E_NOVEH_20 | ET_KNOWNVEH_20 | EP_NOVEH_20 | EPL_NOVEH_20 | E_GROUPQ_20 | ET_HHTYPE_20 | EP_GROUPQ_20 | EPL_GROUPQ_20 |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
01001020100 | 01 | 001 | 020100 | AL | Alabama | Autauga County | 3 | South Region | 6 | East South Central Division | 1941 | 710 | 693 | 352 | 1941 | 18.13498 | NA | 18 | 852 | 2.112676 | NA | 81 | 507 | 15.976331 | NA | 63 | 186 | 33.87097 | NA | 144 | 693 | 20.77922 | NA | 187 | 1309 | 14.285714 | NA | 187 | 1941 | 9.634209 | NA | 295 | 15.19835 | NA | 415 | 21.38073 | NA | 391 | 1526 | 25.62254 | NA | 58 | 555 | 10.45045 | NA | 0 | 1843 | 0.0000000 | NA | 437 | 1941 | 22.51417 | NA | 710 | 0 | 0.0000000 | NA | 88 | 12.3943662 | NA | 0 | 693 | 0.0000000 | NA | 10 | 693 | 1.443001 | NA | 0 | 1941 | 0.000000 | NA |
01001020200 | 01 | 001 | 020200 | AL | Alabama | Autauga County | 3 | South Region | 6 | East South Central Division | 1757 | 720 | 573 | 384 | 1511 | 25.41363 | NA | 29 | 717 | 4.044630 | NA | 33 | 392 | 8.418367 | NA | 116 | 181 | 64.08840 | NA | 149 | 573 | 26.00349 | NA | 139 | 1313 | 10.586443 | NA | 91 | 1533 | 5.936073 | NA | 284 | 16.16392 | NA | 325 | 18.49744 | NA | 164 | 1208 | 13.57616 | NA | 42 | 359 | 11.69916 | NA | 0 | 1651 | 0.0000000 | NA | 1116 | 1757 | 63.51736 | NA | 720 | 3 | 0.4166667 | NA | 5 | 0.6944444 | NA | 9 | 573 | 1.5706806 | NA | 57 | 573 | 9.947644 | NA | 212 | 1757 | 12.066022 | NA |
01001020300 | 01 | 001 | 020300 | AL | Alabama | Autauga County | 3 | South Region | 6 | East South Central Division | 3694 | 1464 | 1351 | 842 | 3694 | 22.79372 | NA | 53 | 1994 | 2.657974 | NA | 117 | 967 | 12.099276 | NA | 147 | 384 | 38.28125 | NA | 264 | 1351 | 19.54108 | NA | 317 | 2477 | 12.797739 | NA | 127 | 3673 | 3.457664 | NA | 464 | 12.56091 | NA | 929 | 25.14889 | NA | 473 | 2744 | 17.23761 | NA | 263 | 975 | 26.97436 | NA | 128 | 3586 | 3.5694367 | NA | 1331 | 3694 | 36.03140 | NA | 1464 | 26 | 1.7759563 | NA | 14 | 0.9562842 | NA | 35 | 1351 | 2.5906736 | NA | 42 | 1351 | 3.108808 | NA | 0 | 3694 | 0.000000 | NA |
01001020400 | 01 | 001 | 020400 | AL | Alabama | Autauga County | 3 | South Region | 6 | East South Central Division | 3539 | 1741 | 1636 | 503 | 3539 | 14.21305 | NA | 39 | 1658 | 2.352232 | NA | 219 | 1290 | 16.976744 | NA | 74 | 346 | 21.38728 | NA | 293 | 1636 | 17.90954 | NA | 173 | 2775 | 6.234234 | NA | 169 | 3529 | 4.788892 | NA | 969 | 27.38062 | NA | 510 | 14.41085 | NA | 670 | 3019 | 22.19278 | NA | 148 | 1137 | 13.01671 | NA | 89 | 3409 | 2.6107363 | NA | 454 | 3539 | 12.82848 | NA | 1741 | 143 | 8.2136703 | NA | 0 | 0.0000000 | NA | 10 | 1636 | 0.6112469 | NA | 72 | 1636 | 4.400978 | NA | 0 | 3539 | 0.000000 | NA |
01001020500 | 01 | 001 | 020500 | AL | Alabama | Autauga County | 3 | South Region | 6 | East South Central Division | 10674 | 4504 | 4424 | 1626 | 10509 | 15.47245 | NA | 81 | 5048 | 1.604596 | NA | 321 | 2299 | 13.962592 | NA | 711 | 2125 | 33.45882 | NA | 1032 | 4424 | 23.32731 | NA | 531 | 6816 | 7.790493 | NA | 301 | 10046 | 2.996217 | NA | 1613 | 15.11149 | NA | 2765 | 25.90407 | NA | 1124 | 7281 | 15.43744 | NA | 342 | 2912 | 11.74451 | NA | 52 | 9920 | 0.5241935 | NA | 2603 | 10674 | 24.38636 | NA | 4504 | 703 | 15.6083481 | NA | 29 | 0.6438721 | NA | 37 | 4424 | 0.8363472 | NA | 207 | 4424 | 4.679023 | NA | 176 | 10674 | 1.648866 | NA |
01001020600 | 01 | 001 | 020600 | AL | Alabama | Autauga County | 3 | South Region | 6 | East South Central Division | 3536 | 1464 | 1330 | 1279 | 3523 | 36.30429 | NA | 34 | 1223 | 2.780049 | NA | 321 | 1111 | 28.892889 | NA | 67 | 219 | 30.59361 | NA | 388 | 1330 | 29.17293 | NA | 306 | 2380 | 12.857143 | NA | 415 | 3496 | 11.870709 | NA | 547 | 15.46946 | NA | 982 | 27.77149 | NA | 729 | 2514 | 28.99761 | NA | 95 | 880 | 10.79545 | NA | 0 | 3394 | 0.0000000 | NA | 985 | 3536 | 27.85633 | NA | 1464 | 0 | 0.0000000 | NA | 364 | 24.8633880 | NA | 0 | 1330 | 0.0000000 | NA | 17 | 1330 | 1.278196 | NA | 0 | 3536 | 0.000000 | NA |
First, notice that we are going to create a function called rank_variables and we’re going to list 4 separate variables:
Next, if we examine the code, we can find that we want to start by creating a list of column names that are relevant for ranking our SVI variables: the columns that start with EPL (indicated by the Caret symbol ^
in regex). As we noticed in our data above, these columns are currently empty and thus must be filled with the appropriate percentile rankings.
Once we create this list, we now can segment out our code using if statements to indicate how we want to calculate the percentile rankings for our data at different levels of measurement.
For example, on the regional level, we will filter our data to our regional location of interest. After that, we will go through a for loop to find each EPL_ column names in our data set, select the corresponding estimated percentage (EP) column, rank it, and then keep 4 significant digits (consistent with the CDC’s methodology).
In order to do this, we can use a for loop to cycle through all the column names and then the injection operator !! (called bang-bang) to allow us to insert the variable values epct and epl into our code and reuse it for each column name in the for loop. At the end of the loop, we merge our ranking back to our main data frame for our area of interest.
For county, we take these a step closer and require a state_abbr to complete our county ranking. This is because unlike our regional, divisional, and state levels of data which have unique names for all values, there are multiple states that have counties with the same names across the United States (If you’d like to see a fun example of this, type Jefferson County in Google and see how many county websites across different states appear!).
Finally, since we set the default value of rank_by to national, if we run the function with just a data set without specifying any other parameters, we will return all of our data with national rankings.
rank_variables <- function(df, rank_by="national", location=NULL, state_abbr=NULL) {
# Search column names for our estimated percentile columns
epl_cols <- colnames(df) %>% str_detect("^EPL_")
# Select these from all column names
epl_cols_names <- colnames(df)[epl_cols]
if (tolower(rank_by) == "regional") {
# Create estimated percentile rankings on a regional level, with 4 significant digits
location <- tolower(location)
for (epl in epl_cols_names) {
epct <- str_replace(epl, "EPL_", "EP_")
df2 <- df %>%
filter(tolower(region) == location) %>%
filter(!is.na(!!as.name(epct))) %>%
mutate(!!as.name(epl) := rank(!!as.name(epct))/length(!!as.name(epct))) %>%
mutate(!!as.name(epl) := signif(!!as.name(epl), 4)) %>% select(GEOID_2010_trt,
!!as.name(epl))
df3 <- df %>%
filter(tolower(region) == location) %>%
select(-quote(!!as.name(epl)))
df <- left_join(df3, df2, join_by("GEOID_2010_trt" == "GEOID_2010_trt")) %>%
relocate(c(!!as.name(epl)),.after = !!as.name(epct))
}
} else if (tolower(rank_by) == "divisional") {
# Create estimated percentile rankings on a divisional level, with 4 significant digits
location <- tolower(location)
for (epl in epl_cols_names) {
epct <- str_replace(epl, "EPL_", "EP_")
df2 <- df %>%
filter(tolower(division) == location) %>%
filter(!is.na(!!as.name(epct))) %>%
mutate(!!as.name(epl) := rank(!!as.name(epct))/length(!!as.name(epct))) %>%
mutate(!!as.name(epl) := signif(!!as.name(epl), 4)) %>% select(GEOID_2010_trt,
!!as.name(epl))
df3 <- df %>%
filter(tolower(division) == location) %>%
select(-quote(!!as.name(epl)))
df <- left_join(df3, df2, join_by("GEOID_2010_trt" == "GEOID_2010_trt")) %>%
relocate(c(!!as.name(epl)),.after = !!as.name(epct))
}
} else if (tolower(rank_by) == "state") {
# Create estimated percentile rankings on a state level, with 4 significant digits
location <- tolower(location)
for (epl in epl_cols_names) {
epct <- str_replace(epl, "EPL_", "EP_")
df2 <- df %>%
filter(tolower(state) == location) %>%
filter(!is.na(!!as.name(epct))) %>%
mutate(!!as.name(epl) := rank(!!as.name(epct))/length(!!as.name(epct))) %>%
mutate(!!as.name(epl) := signif(!!as.name(epl), 4)) %>% select(GEOID_2010_trt,
!!as.name(epl))
df3 <- df %>%
filter(tolower(state) == location) %>%
select(-quote(!!as.name(epl)))
df <- left_join(df3, df2, join_by("GEOID_2010_trt" == "GEOID_2010_trt")) %>%
relocate(c(!!as.name(epl)),.after = !!as.name(epct))
}
} else if (tolower(rank_by) == "county") {
# Create estimated percentile rankings on a county level, require a state selection as
# county names are not unique outside of states, with 4 significant digits
if (is.null(state_abbr)) {
print("Enter state abbreviation in function and re-try")
df <- NULL
} else {
location <- tolower(location)
state_abbr <- tolower(state_abbr)
for (epl in epl_cols_names) {
epct <- str_replace(epl, "EPL_", "EP_")
df2 <- df %>%
filter(tolower(state) == state_abbr) %>%
filter(tolower(county) == location) %>%
filter(!is.na(!!as.name(epct))) %>%
mutate(!!as.name(epl) := rank(!!as.name(epct))/length(!!as.name(epct))) %>%
mutate(!!as.name(epl) := signif(!!as.name(epl), 4)) %>% select(GEOID_2010_trt,
!!as.name(epl))
df3 <- df %>%
filter(tolower(state) == state_abbr) %>%
filter(tolower(county) == location) %>%
select(-quote(!!as.name(epl)))
df <- left_join(df3, df2, join_by("GEOID_2010_trt" == "GEOID_2010_trt")) %>%
relocate(c(!!as.name(epl)),.after = !!as.name(epct))
}
}
} else {
# If no lower level region is selected, create percentiles on a national level, with 4 significant digits
for (epl in epl_cols_names) {
epct <- str_replace(epl, "EPL_", "EP_")
df2 <- df %>%
filter(!is.na(!!as.name(epct))) %>%
mutate(!!as.name(epl) := rank(!!as.name(epct))/length(!!as.name(epct))) %>%
mutate(!!as.name(epl) := signif(!!as.name(epl), 4)) %>% select(GEOID_2010_trt,
!!as.name(epl))
df3 <- df %>%
select(-quote(!!as.name(epl)))
df <- left_join(df3, df2, join_by("GEOID_2010_trt" == "GEOID_2010_trt")) %>%
relocate(c(!!as.name(epl)),.after = !!as.name(epct))
}
}
# Output ranked df
return(df)
}
Recall for national data we only need to enter our data set:
# National
svi_2010_national <- rank_variables(svi_2010)
svi_2010_national %>% head() %>% kbl() %>% kable_styling() %>% scroll_box(width = "100%")
GEOID_2010_trt | FIPS_st | FIPS_county | FIPS_tract | state | state_name | county | region_number | region | division_number | division | E_TOTPOP_10 | E_HU_10 | E_HH_10 | E_POV150_10 | ET_POVSTATUS_10 | EP_POV150_10 | EPL_POV150_10 | E_UNEMP_10 | ET_EMPSTATUS_10 | EP_UNEMP_10 | EPL_UNEMP_10 | E_HBURD_OWN_10 | ET_HOUSINGCOST_OWN_10 | EP_HBURD_OWN_10 | EPL_HBURD_OWN_10 | E_HBURD_RENT_10 | ET_HOUSINGCOST_RENT_10 | EP_HBURD_RENT_10 | EPL_HBURD_RENT_10 | E_HBURD_10 | ET_HOUSINGCOST_10 | EP_HBURD_10 | EPL_HBURD_10 | E_NOHSDP_10 | ET_EDSTATUS_10 | EP_NOHSDP_10 | EPL_NOHSDP_10 | E_UNINSUR_12 | ET_INSURSTATUS_12 | EP_UNINSUR_12 | EPL_UNINSUR_12 | E_AGE65_10 | EP_AGE65_10 | EPL_AGE65_10 | E_AGE17_10 | EP_AGE17_10 | EPL_AGE17_10 | E_DISABL_12 | ET_DISABLSTATUS_12 | EP_DISABL_12 | EPL_DISABL_12 | E_SNGPNT_10 | ET_FAMILIES_10 | EP_SNGPNT_10 | EPL_SNGPNT_10 | E_LIMENG_10 | ET_POPAGE5UP_10 | EP_LIMENG_10 | EPL_LIMENG_10 | E_MINRTY_10 | ET_POPETHRACE_10 | EP_MINRTY_10 | EPL_MINRTY_10 | E_STRHU_10 | E_MUNIT_10 | EP_MUNIT_10 | EPL_MUNIT_10 | E_MOBILE_10 | EP_MOBILE_10 | EPL_MOBILE_10 | E_CROWD_10 | ET_OCCUPANTS_10 | EP_CROWD_10 | EPL_CROWD_10 | E_NOVEH_10 | ET_KNOWNVEH_10 | EP_NOVEH_10 | EPL_NOVEH_10 | E_GROUPQ_10 | ET_HHTYPE_10 | EP_GROUPQ_10 | EPL_GROUPQ_10 |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
01001020100 | 01 | 001 | 020100 | AL | Alabama | Autauga County | 3 | South Region | 6 | East South Central Division | 1809 | 771 | 696 | 297 | 1809 | 16.41791 | 0.3871 | 36 | 889 | 4.049494 | 0.1790 | 127 | 598 | 21.23746 | 0.20770 | 47 | 98 | 47.95918 | 0.5767 | 174 | 696 | 25.00000 | 0.18790 | 196 | 1242 | 15.780998 | 0.6093 | 186 | 1759 | 10.574190 | 0.3790 | 222 | 12.271973 | 0.4876 | 445 | 24.59923 | 0.5473 | 298 | 1335 | 22.32210 | 0.8454 | 27 | 545 | 4.954128 | 0.09275 | 36 | 1705 | 2.1114370 | 0.59040 | 385 | 1809 | 21.282477 | 0.4524 | 771 | 0 | 0.0000000 | 0.1224 | 92 | 11.9325551 | 0.8005 | 0 | 696 | 0.0000000 | 0.1238 | 50 | 696 | 7.183908 | 0.6134 | 0 | 1809 | 0 | 0.364 |
01001020200 | 01 | 001 | 020200 | AL | Alabama | Autauga County | 3 | South Region | 6 | East South Central Division | 2020 | 816 | 730 | 495 | 1992 | 24.84940 | 0.5954 | 68 | 834 | 8.153477 | 0.5754 | 49 | 439 | 11.16173 | 0.02067 | 105 | 291 | 36.08247 | 0.3019 | 154 | 730 | 21.09589 | 0.09312 | 339 | 1265 | 26.798419 | 0.8392 | 313 | 2012 | 15.556660 | 0.6000 | 204 | 10.099010 | 0.3419 | 597 | 29.55446 | 0.8192 | 359 | 1515 | 23.69637 | 0.8791 | 132 | 456 | 28.947368 | 0.83510 | 15 | 1890 | 0.7936508 | 0.40130 | 1243 | 2020 | 61.534653 | 0.7781 | 816 | 0 | 0.0000000 | 0.1224 | 34 | 4.1666667 | 0.6664 | 13 | 730 | 1.7808219 | 0.5406 | 115 | 730 | 15.753425 | 0.8382 | 0 | 2020 | 0 | 0.364 |
01001020300 | 01 | 001 | 020300 | AL | Alabama | Autauga County | 3 | South Region | 6 | East South Central Division | 3543 | 1403 | 1287 | 656 | 3533 | 18.56779 | 0.4443 | 93 | 1552 | 5.992268 | 0.3724 | 273 | 957 | 28.52665 | 0.45780 | 178 | 330 | 53.93939 | 0.7152 | 451 | 1287 | 35.04274 | 0.49930 | 346 | 2260 | 15.309734 | 0.5950 | 252 | 3102 | 8.123791 | 0.2596 | 487 | 13.745413 | 0.5868 | 998 | 28.16822 | 0.7606 | 371 | 2224 | 16.68165 | 0.6266 | 126 | 913 | 13.800657 | 0.46350 | 0 | 3365 | 0.0000000 | 0.09298 | 637 | 3543 | 17.979114 | 0.4049 | 1403 | 10 | 0.7127584 | 0.3015 | 2 | 0.1425517 | 0.4407 | 0 | 1287 | 0.0000000 | 0.1238 | 101 | 1287 | 7.847708 | 0.6443 | 0 | 3543 | 0 | 0.364 |
01001020400 | 01 | 001 | 020400 | AL | Alabama | Autauga County | 3 | South Region | 6 | East South Central Division | 4840 | 1957 | 1839 | 501 | 4840 | 10.35124 | 0.2177 | 101 | 2129 | 4.744011 | 0.2447 | 310 | 1549 | 20.01291 | 0.17080 | 89 | 290 | 30.68966 | 0.2044 | 399 | 1839 | 21.69657 | 0.10540 | 274 | 3280 | 8.353658 | 0.3205 | 399 | 4293 | 9.294200 | 0.3171 | 955 | 19.731405 | 0.8643 | 1195 | 24.69008 | 0.5530 | 625 | 3328 | 18.78005 | 0.7233 | 152 | 1374 | 11.062591 | 0.34710 | 10 | 4537 | 0.2204100 | 0.22560 | 297 | 4840 | 6.136364 | 0.1647 | 1957 | 33 | 1.6862545 | 0.3843 | 25 | 1.2774655 | 0.5516 | 14 | 1839 | 0.7612833 | 0.3564 | 19 | 1839 | 1.033170 | 0.1127 | 0 | 4840 | 0 | 0.364 |
01001020500 | 01 | 001 | 020500 | AL | Alabama | Autauga County | 3 | South Region | 6 | East South Central Division | 9938 | 3969 | 3741 | 1096 | 9938 | 11.02838 | 0.2364 | 188 | 4937 | 3.807981 | 0.1577 | 426 | 2406 | 17.70574 | 0.11050 | 528 | 1335 | 39.55056 | 0.3753 | 954 | 3741 | 25.50120 | 0.20140 | 293 | 5983 | 4.897209 | 0.1655 | 740 | 10110 | 7.319486 | 0.2211 | 837 | 8.422218 | 0.2408 | 3012 | 30.30791 | 0.8455 | 759 | 7155 | 10.60797 | 0.2668 | 476 | 2529 | 18.821669 | 0.63540 | 78 | 9297 | 0.8389803 | 0.41110 | 1970 | 9938 | 19.822902 | 0.4330 | 3969 | 306 | 7.7097506 | 0.6153 | 0 | 0.0000000 | 0.2198 | 7 | 3741 | 0.1871157 | 0.2535 | 223 | 3741 | 5.960973 | 0.5483 | 0 | 9938 | 0 | 0.364 |
01001020600 | 01 | 001 | 020600 | AL | Alabama | Autauga County | 3 | South Region | 6 | East South Central Division | 3402 | 1456 | 1308 | 735 | 3402 | 21.60494 | 0.5199 | 134 | 1720 | 7.790698 | 0.5436 | 242 | 1032 | 23.44961 | 0.28010 | 62 | 276 | 22.46377 | 0.1035 | 304 | 1308 | 23.24159 | 0.14070 | 301 | 2151 | 13.993491 | 0.5510 | 355 | 3445 | 10.304790 | 0.3656 | 386 | 11.346267 | 0.4232 | 931 | 27.36626 | 0.7200 | 440 | 2439 | 18.04018 | 0.6912 | 143 | 924 | 15.476190 | 0.52900 | 4 | 3254 | 0.1229256 | 0.19840 | 723 | 3402 | 21.252205 | 0.4519 | 1456 | 18 | 1.2362637 | 0.3507 | 433 | 29.7390110 | 0.9468 | 16 | 1308 | 1.2232416 | 0.4493 | 28 | 1308 | 2.140673 | 0.2298 | 0 | 3402 | 0 | 0.364 |
# National
svi_2020_national <- rank_variables(svi_2020)
svi_2020_national %>% head() %>% kbl() %>% kable_styling() %>% scroll_box(width = "100%")
GEOID_2010_trt | FIPS_st | FIPS_county | FIPS_tract | state | state_name | county | region_number | region | division_number | division | E_TOTPOP_20 | E_HU_20 | E_HH_20 | E_POV150_20 | ET_POVSTATUS_20 | EP_POV150_20 | EPL_POV150_20 | E_UNEMP_20 | ET_EMPSTATUS_20 | EP_UNEMP_20 | EPL_UNEMP_20 | E_HBURD_OWN_20 | ET_HOUSINGCOST_OWN_20 | EP_HBURD_OWN_20 | EPL_HBURD_OWN_20 | E_HBURD_RENT_20 | ET_HOUSINGCOST_RENT_20 | EP_HBURD_RENT_20 | EPL_HBURD_RENT_20 | E_HBURD_20 | ET_HOUSINGCOST_20 | EP_HBURD_20 | EPL_HBURD_20 | E_NOHSDP_20 | ET_EDSTATUS_20 | EP_NOHSDP_20 | EPL_NOHSDP_20 | E_UNINSUR_20 | ET_INSURSTATUS_20 | EP_UNINSUR_20 | EPL_UNINSUR_20 | E_AGE65_20 | EP_AGE65_20 | EPL_AGE65_20 | E_AGE17_20 | EP_AGE17_20 | EPL_AGE17_20 | E_DISABL_20 | ET_DISABLSTATUS_20 | EP_DISABL_20 | EPL_DISABL_20 | E_SNGPNT_20 | ET_FAMILIES_20 | EP_SNGPNT_20 | EPL_SNGPNT_20 | E_LIMENG_20 | ET_POPAGE5UP_20 | EP_LIMENG_20 | EPL_LIMENG_20 | E_MINRTY_20 | ET_POPETHRACE_20 | EP_MINRTY_20 | EPL_MINRTY_20 | E_STRHU_20 | E_MUNIT_20 | EP_MUNIT_20 | EPL_MUNIT_20 | E_MOBILE_20 | EP_MOBILE_20 | EPL_MOBILE_20 | E_CROWD_20 | ET_OCCUPANTS_20 | EP_CROWD_20 | EPL_CROWD_20 | E_NOVEH_20 | ET_KNOWNVEH_20 | EP_NOVEH_20 | EPL_NOVEH_20 | E_GROUPQ_20 | ET_HHTYPE_20 | EP_GROUPQ_20 | EPL_GROUPQ_20 |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
01001020100 | 01 | 001 | 020100 | AL | Alabama | Autauga County | 3 | South Region | 6 | East South Central Division | 1941 | 710 | 693 | 352 | 1941 | 18.13498 | 0.4630 | 18 | 852 | 2.112676 | 0.15070 | 81 | 507 | 15.976331 | 0.26320 | 63 | 186 | 33.87097 | 0.2913 | 144 | 693 | 20.77922 | 0.2230 | 187 | 1309 | 14.285714 | 0.6928 | 187 | 1941 | 9.634209 | 0.6617 | 295 | 15.19835 | 0.4601 | 415 | 21.38073 | 0.4681 | 391 | 1526 | 25.62254 | 0.9011 | 58 | 555 | 10.45045 | 0.3451 | 0 | 1843 | 0.0000000 | 0.09479 | 437 | 1941 | 22.51417 | 0.3902 | 710 | 0 | 0.0000000 | 0.1079 | 88 | 12.3943662 | 0.8263 | 0 | 693 | 0.0000000 | 0.09796 | 10 | 693 | 1.443001 | 0.1643 | 0 | 1941 | 0.000000 | 0.1831 |
01001020200 | 01 | 001 | 020200 | AL | Alabama | Autauga County | 3 | South Region | 6 | East South Central Division | 1757 | 720 | 573 | 384 | 1511 | 25.41363 | 0.6427 | 29 | 717 | 4.044630 | 0.41320 | 33 | 392 | 8.418367 | 0.03542 | 116 | 181 | 64.08840 | 0.9086 | 149 | 573 | 26.00349 | 0.4041 | 139 | 1313 | 10.586443 | 0.5601 | 91 | 1533 | 5.936073 | 0.4343 | 284 | 16.16392 | 0.5169 | 325 | 18.49744 | 0.2851 | 164 | 1208 | 13.57616 | 0.4127 | 42 | 359 | 11.69916 | 0.3998 | 0 | 1651 | 0.0000000 | 0.09479 | 1116 | 1757 | 63.51736 | 0.7591 | 720 | 3 | 0.4166667 | 0.2470 | 5 | 0.6944444 | 0.5106 | 9 | 573 | 1.5706806 | 0.46880 | 57 | 573 | 9.947644 | 0.7317 | 212 | 1757 | 12.066022 | 0.9549 |
01001020300 | 01 | 001 | 020300 | AL | Alabama | Autauga County | 3 | South Region | 6 | East South Central Division | 3694 | 1464 | 1351 | 842 | 3694 | 22.79372 | 0.5833 | 53 | 1994 | 2.657974 | 0.22050 | 117 | 967 | 12.099276 | 0.11370 | 147 | 384 | 38.28125 | 0.3856 | 264 | 1351 | 19.54108 | 0.1827 | 317 | 2477 | 12.797739 | 0.6460 | 127 | 3673 | 3.457664 | 0.2308 | 464 | 12.56091 | 0.3088 | 929 | 25.14889 | 0.7080 | 473 | 2744 | 17.23761 | 0.6211 | 263 | 975 | 26.97436 | 0.8234 | 128 | 3586 | 3.5694367 | 0.70770 | 1331 | 3694 | 36.03140 | 0.5515 | 1464 | 26 | 1.7759563 | 0.3675 | 14 | 0.9562842 | 0.5389 | 35 | 1351 | 2.5906736 | 0.60550 | 42 | 1351 | 3.108808 | 0.3415 | 0 | 3694 | 0.000000 | 0.1831 |
01001020400 | 01 | 001 | 020400 | AL | Alabama | Autauga County | 3 | South Region | 6 | East South Central Division | 3539 | 1741 | 1636 | 503 | 3539 | 14.21305 | 0.3472 | 39 | 1658 | 2.352232 | 0.17990 | 219 | 1290 | 16.976744 | 0.30880 | 74 | 346 | 21.38728 | 0.1037 | 293 | 1636 | 17.90954 | 0.1333 | 173 | 2775 | 6.234234 | 0.3351 | 169 | 3529 | 4.788892 | 0.3448 | 969 | 27.38062 | 0.9225 | 510 | 14.41085 | 0.1208 | 670 | 3019 | 22.19278 | 0.8194 | 148 | 1137 | 13.01671 | 0.4541 | 89 | 3409 | 2.6107363 | 0.64690 | 454 | 3539 | 12.82848 | 0.2364 | 1741 | 143 | 8.2136703 | 0.6028 | 0 | 0.0000000 | 0.2186 | 10 | 1636 | 0.6112469 | 0.28340 | 72 | 1636 | 4.400978 | 0.4538 | 0 | 3539 | 0.000000 | 0.1831 |
01001020500 | 01 | 001 | 020500 | AL | Alabama | Autauga County | 3 | South Region | 6 | East South Central Division | 10674 | 4504 | 4424 | 1626 | 10509 | 15.47245 | 0.3851 | 81 | 5048 | 1.604596 | 0.09431 | 321 | 2299 | 13.962592 | 0.17970 | 711 | 2125 | 33.45882 | 0.2836 | 1032 | 4424 | 23.32731 | 0.3109 | 531 | 6816 | 7.790493 | 0.4251 | 301 | 10046 | 2.996217 | 0.1894 | 1613 | 15.11149 | 0.4553 | 2765 | 25.90407 | 0.7494 | 1124 | 7281 | 15.43744 | 0.5253 | 342 | 2912 | 11.74451 | 0.4019 | 52 | 9920 | 0.5241935 | 0.35230 | 2603 | 10674 | 24.38636 | 0.4160 | 4504 | 703 | 15.6083481 | 0.7378 | 29 | 0.6438721 | 0.5037 | 37 | 4424 | 0.8363472 | 0.33420 | 207 | 4424 | 4.679023 | 0.4754 | 176 | 10674 | 1.648866 | 0.7598 |
01001020600 | 01 | 001 | 020600 | AL | Alabama | Autauga County | 3 | South Region | 6 | East South Central Division | 3536 | 1464 | 1330 | 1279 | 3523 | 36.30429 | 0.8215 | 34 | 1223 | 2.780049 | 0.23780 | 321 | 1111 | 28.892889 | 0.75870 | 67 | 219 | 30.59361 | 0.2305 | 388 | 1330 | 29.17293 | 0.5075 | 306 | 2380 | 12.857143 | 0.6480 | 415 | 3496 | 11.870709 | 0.7535 | 547 | 15.46946 | 0.4760 | 982 | 27.77149 | 0.8327 | 729 | 2514 | 28.99761 | 0.9488 | 95 | 880 | 10.79545 | 0.3601 | 0 | 3394 | 0.0000000 | 0.09479 | 985 | 3536 | 27.85633 | 0.4608 | 1464 | 0 | 0.0000000 | 0.1079 | 364 | 24.8633880 | 0.9300 | 0 | 1330 | 0.0000000 | 0.09796 | 17 | 1330 | 1.278196 | 0.1463 | 0 | 3536 | 0.000000 | 0.1831 |
Recall for regional data we need to enter our rank_by variables and location variable:
# Regional
svi_2010_regional <- rank_variables(svi_2010, rank_by = "regional", location = "Northeast Region")
svi_2010_regional %>% head() %>% kbl() %>% kable_styling() %>% scroll_box(width = "100%")
GEOID_2010_trt | FIPS_st | FIPS_county | FIPS_tract | state | state_name | county | region_number | region | division_number | division | E_TOTPOP_10 | E_HU_10 | E_HH_10 | E_POV150_10 | ET_POVSTATUS_10 | EP_POV150_10 | EPL_POV150_10 | E_UNEMP_10 | ET_EMPSTATUS_10 | EP_UNEMP_10 | EPL_UNEMP_10 | E_HBURD_OWN_10 | ET_HOUSINGCOST_OWN_10 | EP_HBURD_OWN_10 | EPL_HBURD_OWN_10 | E_HBURD_RENT_10 | ET_HOUSINGCOST_RENT_10 | EP_HBURD_RENT_10 | EPL_HBURD_RENT_10 | E_HBURD_10 | ET_HOUSINGCOST_10 | EP_HBURD_10 | EPL_HBURD_10 | E_NOHSDP_10 | ET_EDSTATUS_10 | EP_NOHSDP_10 | EPL_NOHSDP_10 | E_UNINSUR_12 | ET_INSURSTATUS_12 | EP_UNINSUR_12 | EPL_UNINSUR_12 | E_AGE65_10 | EP_AGE65_10 | EPL_AGE65_10 | E_AGE17_10 | EP_AGE17_10 | EPL_AGE17_10 | E_DISABL_12 | ET_DISABLSTATUS_12 | EP_DISABL_12 | EPL_DISABL_12 | E_SNGPNT_10 | ET_FAMILIES_10 | EP_SNGPNT_10 | EPL_SNGPNT_10 | E_LIMENG_10 | ET_POPAGE5UP_10 | EP_LIMENG_10 | EPL_LIMENG_10 | E_MINRTY_10 | ET_POPETHRACE_10 | EP_MINRTY_10 | EPL_MINRTY_10 | E_STRHU_10 | E_MUNIT_10 | EP_MUNIT_10 | EPL_MUNIT_10 | E_MOBILE_10 | EP_MOBILE_10 | EPL_MOBILE_10 | E_CROWD_10 | ET_OCCUPANTS_10 | EP_CROWD_10 | EPL_CROWD_10 | E_NOVEH_10 | ET_KNOWNVEH_10 | EP_NOVEH_10 | EPL_NOVEH_10 | E_GROUPQ_10 | ET_HHTYPE_10 | EP_GROUPQ_10 | EPL_GROUPQ_10 |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
09001010101 | 09 | 001 | 010101 | CT | Connecticut | Fairfield County | 1 | Northeast Region | 1 | New England Division | 4053 | 1608 | 1416 | 242 | 3851 | 6.284082 | 0.16010 | 52 | 1511 | 3.441429 | 0.1265 | 429 | 1240 | 34.59677 | 0.5194 | 24 | 176 | 13.63636 | 0.03745 | 453 | 1416 | 31.99153 | 0.29440 | 234 | 2778 | 8.423326 | 0.35790 | 150 | 3851 | 3.895092 | 0.17230 | 959 | 23.66149 | 0.9384 | 1115 | 27.51049 | 0.8155 | 252 | 2898 | 8.695652 | 0.1725 | 32 | 1041 | 3.073967 | 0.05352 | 96 | 3821 | 2.5124313 | 0.6127 | 175 | 4053 | 4.317789 | 0.1678 | 1608 | 46 | 2.8606965 | 0.38610 | 0 | 0.0000000 | 0.3204 | 11 | 1416 | 0.7768362 | 0.4311 | 43 | 1416 | 3.036723 | 0.22200 | 202 | 4053 | 4.983962 | 0.8725 |
09001010102 | 09 | 001 | 010102 | CT | Connecticut | Fairfield County | 1 | Northeast Region | 1 | New England Division | 4833 | 1538 | 1430 | 205 | 4815 | 4.257529 | 0.08309 | 78 | 1799 | 4.335742 | 0.2178 | 478 | 1352 | 35.35503 | 0.5437 | 37 | 78 | 47.43590 | 0.54680 | 515 | 1430 | 36.01399 | 0.42400 | 66 | 3159 | 2.089269 | 0.04865 | 156 | 4544 | 3.433099 | 0.14220 | 750 | 15.51831 | 0.6469 | 1419 | 29.36065 | 0.8840 | 290 | 3345 | 8.669656 | 0.1708 | 28 | 1235 | 2.267206 | 0.03553 | 131 | 4538 | 2.8867342 | 0.6395 | 1176 | 4833 | 24.332713 | 0.5919 | 1538 | 0 | 0.0000000 | 0.09502 | 0 | 0.0000000 | 0.3204 | 0 | 1430 | 0.0000000 | 0.1525 | 101 | 1430 | 7.062937 | 0.46710 | 237 | 4833 | 4.903786 | 0.8706 |
09001010201 | 09 | 001 | 010201 | CT | Connecticut | Fairfield County | 1 | Northeast Region | 1 | New England Division | 3550 | 1091 | 948 | 108 | 3346 | 3.227735 | 0.05048 | 53 | 950 | 5.578947 | 0.3654 | 246 | 903 | 27.24252 | 0.2833 | 8 | 45 | 17.77778 | 0.05548 | 254 | 948 | 26.79325 | 0.14380 | 99 | 2117 | 4.676429 | 0.15780 | 49 | 3217 | 1.523158 | 0.04121 | 672 | 18.92958 | 0.8255 | 1282 | 36.11268 | 0.9778 | 244 | 2146 | 11.369991 | 0.3628 | 71 | 894 | 7.941834 | 0.26130 | 25 | 3422 | 0.7305669 | 0.3653 | 300 | 3550 | 8.450704 | 0.3187 | 1091 | 0 | 0.0000000 | 0.09502 | 0 | 0.0000000 | 0.3204 | 0 | 948 | 0.0000000 | 0.1525 | 0 | 948 | 0.000000 | 0.01141 | 204 | 3550 | 5.746479 | 0.8862 |
09001010202 | 09 | 001 | 010202 | CT | Connecticut | Fairfield County | 1 | Northeast Region | 1 | New England Division | 4839 | 1928 | 1729 | 215 | 4826 | 4.455035 | 0.08982 | 79 | 2116 | 3.733459 | 0.1528 | 335 | 1413 | 23.70842 | 0.1771 | 64 | 316 | 20.25316 | 0.06942 | 399 | 1729 | 23.07692 | 0.06555 | 149 | 3374 | 4.416123 | 0.14510 | 92 | 5430 | 1.694291 | 0.04860 | 693 | 14.32114 | 0.5654 | 1304 | 26.94772 | 0.7899 | 332 | 3969 | 8.364827 | 0.1531 | 71 | 1323 | 5.366591 | 0.13510 | 123 | 4514 | 2.7248560 | 0.6284 | 837 | 4839 | 17.296962 | 0.5062 | 1928 | 9 | 0.4668050 | 0.20820 | 10 | 0.5186722 | 0.6707 | 0 | 1729 | 0.0000000 | 0.1525 | 10 | 1729 | 0.578369 | 0.03255 | 0 | 4839 | 0.000000 | 0.3433 |
09001010300 | 09 | 001 | 010300 | CT | Connecticut | Fairfield County | 1 | Northeast Region | 1 | New England Division | 3847 | 1632 | 1421 | 218 | 3847 | 5.666753 | 0.13480 | 106 | 1463 | 7.245386 | 0.5540 | 398 | 1125 | 35.37778 | 0.5447 | 116 | 296 | 39.18919 | 0.34300 | 514 | 1421 | 36.17171 | 0.42800 | 101 | 2762 | 3.656770 | 0.10950 | 215 | 3910 | 5.498721 | 0.28470 | 732 | 19.02781 | 0.8296 | 961 | 24.98050 | 0.6777 | 219 | 2898 | 7.556936 | 0.1061 | 24 | 1076 | 2.230483 | 0.03478 | 16 | 3668 | 0.4362050 | 0.2769 | 536 | 3847 | 13.932935 | 0.4482 | 1632 | 8 | 0.4901961 | 0.21090 | 0 | 0.0000000 | 0.3204 | 0 | 1421 | 0.0000000 | 0.1525 | 26 | 1421 | 1.829697 | 0.11950 | 0 | 3847 | 0.000000 | 0.3433 |
09001010400 | 09 | 001 | 010400 | CT | Connecticut | Fairfield County | 1 | Northeast Region | 1 | New England Division | 5181 | 2250 | 2108 | 365 | 5181 | 7.044972 | 0.18980 | 102 | 2379 | 4.287516 | 0.2118 | 764 | 1600 | 47.75000 | 0.8269 | 275 | 508 | 54.13386 | 0.70890 | 1039 | 2108 | 49.28842 | 0.79620 | 301 | 3682 | 8.174905 | 0.34450 | 473 | 5252 | 9.006093 | 0.52990 | 1035 | 19.97684 | 0.8601 | 1333 | 25.72862 | 0.7257 | 661 | 4151 | 15.923874 | 0.6668 | 197 | 1357 | 14.517318 | 0.55450 | 67 | 4767 | 1.4054961 | 0.4895 | 595 | 5181 | 11.484269 | 0.3994 | 2250 | 123 | 5.4666667 | 0.49320 | 10 | 0.4444444 | 0.6594 | 26 | 2108 | 1.2333966 | 0.5267 | 63 | 2108 | 2.988615 | 0.21810 | 0 | 5181 | 0.000000 | 0.3433 |
# Regional
svi_2020_regional <- rank_variables(svi_2020, rank_by = "regional", location = "Northeast Region")
svi_2020_regional %>% head() %>% kbl() %>% kable_styling() %>% scroll_box(width = "100%")
GEOID_2010_trt | FIPS_st | FIPS_county | FIPS_tract | state | state_name | county | region_number | region | division_number | division | E_TOTPOP_20 | E_HU_20 | E_HH_20 | E_POV150_20 | ET_POVSTATUS_20 | EP_POV150_20 | EPL_POV150_20 | E_UNEMP_20 | ET_EMPSTATUS_20 | EP_UNEMP_20 | EPL_UNEMP_20 | E_HBURD_OWN_20 | ET_HOUSINGCOST_OWN_20 | EP_HBURD_OWN_20 | EPL_HBURD_OWN_20 | E_HBURD_RENT_20 | ET_HOUSINGCOST_RENT_20 | EP_HBURD_RENT_20 | EPL_HBURD_RENT_20 | E_HBURD_20 | ET_HOUSINGCOST_20 | EP_HBURD_20 | EPL_HBURD_20 | E_NOHSDP_20 | ET_EDSTATUS_20 | EP_NOHSDP_20 | EPL_NOHSDP_20 | E_UNINSUR_20 | ET_INSURSTATUS_20 | EP_UNINSUR_20 | EPL_UNINSUR_20 | E_AGE65_20 | EP_AGE65_20 | EPL_AGE65_20 | E_AGE17_20 | EP_AGE17_20 | EPL_AGE17_20 | E_DISABL_20 | ET_DISABLSTATUS_20 | EP_DISABL_20 | EPL_DISABL_20 | E_SNGPNT_20 | ET_FAMILIES_20 | EP_SNGPNT_20 | EPL_SNGPNT_20 | E_LIMENG_20 | ET_POPAGE5UP_20 | EP_LIMENG_20 | EPL_LIMENG_20 | E_MINRTY_20 | ET_POPETHRACE_20 | EP_MINRTY_20 | EPL_MINRTY_20 | E_STRHU_20 | E_MUNIT_20 | EP_MUNIT_20 | EPL_MUNIT_20 | E_MOBILE_20 | EP_MOBILE_20 | EPL_MOBILE_20 | E_CROWD_20 | ET_OCCUPANTS_20 | EP_CROWD_20 | EPL_CROWD_20 | E_NOVEH_20 | ET_KNOWNVEH_20 | EP_NOVEH_20 | EPL_NOVEH_20 | E_GROUPQ_20 | ET_HHTYPE_20 | EP_GROUPQ_20 | EPL_GROUPQ_20 |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
09001010101 | 09 | 001 | 010101 | CT | Connecticut | Fairfield County | 1 | Northeast Region | 1 | New England Division | 4192 | 1591 | 1347 | 241 | 3922 | 6.144824 | 0.144600 | 76 | 1947 | 3.903441 | 0.3806 | 554 | 1108 | 50.00000 | 0.9397 | 86 | 239 | 35.98326 | 0.29250 | 640 | 1347 | 47.51299 | 0.8415 | 93 | 3061 | 3.038223 | 0.14930 | 7 | 3922 | 0.1784804 | 0.014040 | 1238 | 29.53244 | 0.9500 | 908 | 21.66031 | 0.6033 | 259 | 3014.000 | 8.593232 | 0.15340 | 65 | 1033.000 | 6.2923524 | 0.20440 | 63 | 4022 | 1.5663849 | 0.50770 | 453 | 4192.000 | 10.80630 | 0.2732 | 1591 | 25 | 1.5713388 | 0.29150 | 0 | 0.000000 | 0.3172 | 25 | 1347 | 1.8559762 | 0.5608 | 33 | 1347.000 | 2.4498886 | 0.17820 | 275 | 4192 | 6.5601145 | 0.9107 |
09001010102 | 09 | 001 | 010102 | CT | Connecticut | Fairfield County | 1 | Northeast Region | 1 | New England Division | 4419 | 1602 | 1362 | 60 | 4419 | 1.357773 | 0.007698 | 67 | 2032 | 3.297244 | 0.2916 | 363 | 1231 | 29.48822 | 0.6387 | 29 | 131 | 22.13740 | 0.08811 | 392 | 1362 | 28.78120 | 0.3840 | 33 | 2827 | 1.167315 | 0.03804 | 4 | 4419 | 0.0905182 | 0.011050 | 828 | 18.73727 | 0.6218 | 1208 | 27.33650 | 0.8876 | 239 | 3211.000 | 7.443164 | 0.09654 | 8 | 1255.000 | 0.6374502 | 0.01594 | 17 | 4186 | 0.4061156 | 0.27980 | 539 | 4419.000 | 12.19733 | 0.3037 | 1602 | 0 | 0.0000000 | 0.08313 | 0 | 0.000000 | 0.3172 | 9 | 1362 | 0.6607930 | 0.3515 | 17 | 1362.000 | 1.2481645 | 0.08452 | 20 | 4419 | 0.4525911 | 0.5565 |
09001010201 | 09 | 001 | 010201 | CT | Connecticut | Fairfield County | 1 | Northeast Region | 1 | New England Division | 3429 | 1255 | 1119 | 181 | 3277 | 5.523345 | 0.120100 | 76 | 1201 | 6.328060 | 0.6691 | 255 | 978 | 26.07362 | 0.5312 | 24 | 141 | 17.02128 | 0.05272 | 279 | 1119 | 24.93298 | 0.2590 | 44 | 2207 | 1.993656 | 0.07981 | 0 | 3277 | 0.0000000 | 0.004705 | 741 | 21.60980 | 0.7671 | 964 | 28.11315 | 0.9053 | 158 | 2313.000 | 6.830955 | 0.07420 | 21 | 871.000 | 2.4110218 | 0.04849 | 10 | 3218 | 0.3107520 | 0.24640 | 561 | 3429.000 | 16.36045 | 0.3846 | 1255 | 24 | 1.9123506 | 0.31520 | 0 | 0.000000 | 0.3172 | 0 | 1119 | 0.0000000 | 0.1244 | 24 | 1119.000 | 2.1447721 | 0.15360 | 251 | 3429 | 7.3199183 | 0.9178 |
09001010202 | 09 | 001 | 010202 | CT | Connecticut | Fairfield County | 1 | Northeast Region | 1 | New England Division | 5262 | 1917 | 1811 | 647 | 5245 | 12.335558 | 0.390800 | 169 | 2620 | 6.450382 | 0.6798 | 346 | 1294 | 26.73879 | 0.5524 | 272 | 517 | 52.61122 | 0.68900 | 618 | 1811 | 34.12479 | 0.5544 | 175 | 3433 | 5.097582 | 0.29890 | 83 | 5263 | 1.5770473 | 0.158300 | 883 | 16.78069 | 0.5027 | 1550 | 29.45648 | 0.9311 | 383 | 3713.163 | 10.314657 | 0.26320 | 136 | 1483.018 | 9.1704909 | 0.34670 | 157 | 5042 | 3.1138437 | 0.64660 | 1339 | 5261.892 | 25.44712 | 0.5154 | 1917 | 7 | 0.3651539 | 0.18520 | 0 | 0.000000 | 0.3172 | 0 | 1811 | 0.0000000 | 0.1244 | 42 | 1811.390 | 2.3186617 | 0.16720 | 8 | 5262 | 0.1520334 | 0.3711 |
09001010300 | 09 | 001 | 010300 | CT | Connecticut | Fairfield County | 1 | Northeast Region | 1 | New England Division | 3815 | 1664 | 1457 | 89 | 3810 | 2.335958 | 0.020850 | 81 | 1839 | 4.404568 | 0.4541 | 293 | 1038 | 28.22736 | 0.6002 | 75 | 419 | 17.89976 | 0.05786 | 368 | 1457 | 25.25738 | 0.2693 | 35 | 2698 | 1.297257 | 0.04371 | 38 | 3809 | 0.9976372 | 0.083710 | 742 | 19.44954 | 0.6605 | 881 | 23.09305 | 0.6986 | 124 | 2928.576 | 4.234140 | 0.01599 | 31 | 1164.582 | 2.6618993 | 0.05612 | 0 | 3612 | 0.0000000 | 0.07348 | 502 | 3815.450 | 13.15703 | 0.3245 | 1664 | 51 | 3.0649038 | 0.37610 | 13 | 0.781250 | 0.7117 | 13 | 1457 | 0.8922443 | 0.4053 | 13 | 1456.744 | 0.8924009 | 0.05999 | 58 | 3815 | 1.5203145 | 0.7278 |
09001010400 | 09 | 001 | 010400 | CT | Connecticut | Fairfield County | 1 | Northeast Region | 1 | New England Division | 5846 | 2131 | 1978 | 352 | 5846 | 6.021211 | 0.139600 | 171 | 3470 | 4.927954 | 0.5229 | 259 | 1285 | 20.15564 | 0.3169 | 339 | 693 | 48.91775 | 0.59620 | 598 | 1978 | 30.23256 | 0.4314 | 169 | 4282 | 3.946754 | 0.21520 | 342 | 5846 | 5.8501540 | 0.656600 | 948 | 16.21622 | 0.4662 | 1144 | 19.56894 | 0.4424 | 590 | 4702.000 | 12.547852 | 0.41400 | 187 | 1561.000 | 11.9795003 | 0.47280 | 72 | 5567 | 1.2933357 | 0.47110 | 946 | 5846.000 | 16.18200 | 0.3817 | 2131 | 92 | 4.3172220 | 0.42850 | 23 | 1.079306 | 0.7367 | 76 | 1978 | 3.8422649 | 0.7360 | 15 | 1978.000 | 0.7583418 | 0.04981 | 23 | 5846 | 0.3934314 | 0.5304 |
For divisional we need to enter our divisional variable and our location:
# Divisional
svi_2010_divisional <- rank_variables(svi_2010, rank_by = "divisional", location = "Middle Atlantic Division")
svi_2010_divisional %>% head() %>% kbl() %>% kable_styling() %>% scroll_box(width = "100%")
GEOID_2010_trt | FIPS_st | FIPS_county | FIPS_tract | state | state_name | county | region_number | region | division_number | division | E_TOTPOP_10 | E_HU_10 | E_HH_10 | E_POV150_10 | ET_POVSTATUS_10 | EP_POV150_10 | EPL_POV150_10 | E_UNEMP_10 | ET_EMPSTATUS_10 | EP_UNEMP_10 | EPL_UNEMP_10 | E_HBURD_OWN_10 | ET_HOUSINGCOST_OWN_10 | EP_HBURD_OWN_10 | EPL_HBURD_OWN_10 | E_HBURD_RENT_10 | ET_HOUSINGCOST_RENT_10 | EP_HBURD_RENT_10 | EPL_HBURD_RENT_10 | E_HBURD_10 | ET_HOUSINGCOST_10 | EP_HBURD_10 | EPL_HBURD_10 | E_NOHSDP_10 | ET_EDSTATUS_10 | EP_NOHSDP_10 | EPL_NOHSDP_10 | E_UNINSUR_12 | ET_INSURSTATUS_12 | EP_UNINSUR_12 | EPL_UNINSUR_12 | E_AGE65_10 | EP_AGE65_10 | EPL_AGE65_10 | E_AGE17_10 | EP_AGE17_10 | EPL_AGE17_10 | E_DISABL_12 | ET_DISABLSTATUS_12 | EP_DISABL_12 | EPL_DISABL_12 | E_SNGPNT_10 | ET_FAMILIES_10 | EP_SNGPNT_10 | EPL_SNGPNT_10 | E_LIMENG_10 | ET_POPAGE5UP_10 | EP_LIMENG_10 | EPL_LIMENG_10 | E_MINRTY_10 | ET_POPETHRACE_10 | EP_MINRTY_10 | EPL_MINRTY_10 | E_STRHU_10 | E_MUNIT_10 | EP_MUNIT_10 | EPL_MUNIT_10 | E_MOBILE_10 | EP_MOBILE_10 | EPL_MOBILE_10 | E_CROWD_10 | ET_OCCUPANTS_10 | EP_CROWD_10 | EPL_CROWD_10 | E_NOVEH_10 | ET_KNOWNVEH_10 | EP_NOVEH_10 | EPL_NOVEH_10 | E_GROUPQ_10 | ET_HHTYPE_10 | EP_GROUPQ_10 | EPL_GROUPQ_10 |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
34001000100 | 34 | 001 | 000100 | NJ | New Jersey | Atlantic County | 1 | Northeast Region | 2 | Middle Atlantic Division | 2907 | 1088 | 983 | 1127 | 2907 | 38.76849 | 0.8482 | 144 | 1433 | 10.048849 | 0.7544 | 280 | 435 | 64.36782 | 0.9529 | 204 | 548 | 37.22628 | 0.2998 | 484 | 983 | 49.23703 | 0.7813 | 468 | 1759 | 26.60603 | 0.8634 | 532 | 2543 | 20.92017 | 0.8978 | 250 | 8.599931 | 0.1777 | 944 | 32.47334 | 0.94170 | 186 | 1851 | 10.04862 | 0.2706 | 266 | 678 | 39.233038 | 0.8981 | 177 | 2611 | 6.779012 | 0.7778 | 1928 | 2907 | 66.32267 | 0.7743 | 1088 | 113 | 10.386029 | 0.6229 | 9 | 0.8272059 | 0.7223 | 80 | 983 | 8.138352 | 0.8657 | 265 | 983 | 26.95829 | 0.7354 | 0 | 2907 | 0.000000 | 0.3512 |
34001000200 | 34 | 001 | 000200 | NJ | New Jersey | Atlantic County | 1 | Northeast Region | 2 | Middle Atlantic Division | 3189 | 2217 | 1473 | 519 | 3189 | 16.27469 | 0.4806 | 109 | 1558 | 6.996149 | 0.5179 | 573 | 955 | 60.00000 | 0.9323 | 199 | 518 | 38.41699 | 0.3261 | 772 | 1473 | 52.41005 | 0.8418 | 405 | 2579 | 15.70376 | 0.6491 | 484 | 3547 | 13.64533 | 0.7154 | 847 | 26.560050 | 0.9629 | 436 | 13.67200 | 0.08181 | 608 | 3005 | 20.23295 | 0.8466 | 42 | 857 | 4.900817 | 0.1204 | 422 | 3072 | 13.736979 | 0.8799 | 1792 | 3189 | 56.19316 | 0.7390 | 2217 | 901 | 40.640505 | 0.8693 | 0 | 0.0000000 | 0.3251 | 48 | 1473 | 3.258656 | 0.7064 | 250 | 1473 | 16.97217 | 0.6444 | 0 | 3189 | 0.000000 | 0.3512 |
34001000300 | 34 | 001 | 000300 | NJ | New Jersey | Atlantic County | 1 | Northeast Region | 2 | Middle Atlantic Division | 3997 | 1823 | 1357 | 1401 | 3968 | 35.30746 | 0.8164 | 382 | 2238 | 17.068811 | 0.9376 | 176 | 329 | 53.49544 | 0.8855 | 604 | 1028 | 58.75486 | 0.7947 | 780 | 1357 | 57.47973 | 0.9165 | 920 | 2677 | 34.36683 | 0.9346 | 1351 | 4149 | 32.56206 | 0.9811 | 314 | 7.855892 | 0.1437 | 937 | 23.44258 | 0.55900 | 319 | 3054 | 10.44532 | 0.3000 | 187 | 782 | 23.913044 | 0.7498 | 1080 | 3671 | 29.419777 | 0.9742 | 3357 | 3997 | 83.98799 | 0.8419 | 1823 | 363 | 19.912233 | 0.7535 | 0 | 0.0000000 | 0.3251 | 150 | 1357 | 11.053795 | 0.9136 | 651 | 1357 | 47.97347 | 0.8585 | 0 | 3997 | 0.000000 | 0.3512 |
34001000400 | 34 | 001 | 000400 | NJ | New Jersey | Atlantic County | 1 | Northeast Region | 2 | Middle Atlantic Division | 2902 | 2683 | 1401 | 1172 | 2902 | 40.38594 | 0.8615 | 190 | 1389 | 13.678906 | 0.8811 | 364 | 707 | 51.48515 | 0.8627 | 507 | 694 | 73.05476 | 0.9503 | 871 | 1401 | 62.16988 | 0.9572 | 481 | 1981 | 24.28067 | 0.8339 | 674 | 3204 | 21.03620 | 0.8998 | 434 | 14.955203 | 0.6083 | 596 | 20.53756 | 0.33980 | 426 | 2607 | 16.34062 | 0.6886 | 111 | 652 | 17.024540 | 0.6204 | 215 | 2736 | 7.858187 | 0.8008 | 1792 | 2902 | 61.75052 | 0.7584 | 2683 | 2049 | 76.369735 | 0.9401 | 0 | 0.0000000 | 0.3251 | 69 | 1401 | 4.925053 | 0.7847 | 511 | 1401 | 36.47395 | 0.7992 | 72 | 2902 | 2.481048 | 0.8114 |
34001000500 | 34 | 001 | 000500 | NJ | New Jersey | Atlantic County | 1 | Northeast Region | 2 | Middle Atlantic Division | 3483 | 1241 | 1027 | 1938 | 3483 | 55.64169 | 0.9533 | 124 | 1630 | 7.607362 | 0.5830 | 227 | 446 | 50.89686 | 0.8549 | 478 | 581 | 82.27194 | 0.9799 | 705 | 1027 | 68.64654 | 0.9863 | 733 | 2077 | 35.29129 | 0.9396 | 727 | 3258 | 22.31430 | 0.9149 | 377 | 10.824002 | 0.3081 | 1055 | 30.28998 | 0.90140 | 268 | 2401 | 11.16202 | 0.3549 | 209 | 763 | 27.391874 | 0.7940 | 911 | 3077 | 29.606760 | 0.9746 | 3036 | 3483 | 87.16624 | 0.8550 | 1241 | 52 | 4.190169 | 0.4505 | 4 | 0.3223207 | 0.6567 | 113 | 1027 | 11.002921 | 0.9128 | 422 | 1027 | 41.09056 | 0.8250 | 0 | 3483 | 0.000000 | 0.3512 |
34001001100 | 34 | 001 | 001100 | NJ | New Jersey | Atlantic County | 1 | Northeast Region | 2 | Middle Atlantic Division | 2204 | 1204 | 1204 | 1185 | 2204 | 53.76588 | 0.9457 | 219 | 927 | 23.624596 | 0.9830 | 97 | 172 | 56.39535 | 0.9094 | 462 | 1032 | 44.76744 | 0.4746 | 559 | 1204 | 46.42857 | 0.7197 | 346 | 1440 | 24.02778 | 0.8306 | 469 | 1942 | 24.15036 | 0.9360 | 363 | 16.470054 | 0.7020 | 578 | 26.22505 | 0.74410 | 442 | 1558 | 28.36970 | 0.9675 | 247 | 396 | 62.373737 | 0.9898 | 104 | 2051 | 5.070697 | 0.7260 | 2118 | 2204 | 96.09800 | 0.9204 | 1204 | 570 | 47.342193 | 0.8858 | 0 | 0.0000000 | 0.3251 | 14 | 1204 | 1.162791 | 0.4877 | 817 | 1204 | 67.85714 | 0.9413 | 0 | 2204 | 0.000000 | 0.3512 |
# Divisional
svi_2020_divisional <- rank_variables(svi_2020, rank_by = "divisional", location = "Middle Atlantic Division")
svi_2020_divisional %>% head() %>% kbl() %>% kable_styling() %>% scroll_box(width = "100%")
GEOID_2010_trt | FIPS_st | FIPS_county | FIPS_tract | state | state_name | county | region_number | region | division_number | division | E_TOTPOP_20 | E_HU_20 | E_HH_20 | E_POV150_20 | ET_POVSTATUS_20 | EP_POV150_20 | EPL_POV150_20 | E_UNEMP_20 | ET_EMPSTATUS_20 | EP_UNEMP_20 | EPL_UNEMP_20 | E_HBURD_OWN_20 | ET_HOUSINGCOST_OWN_20 | EP_HBURD_OWN_20 | EPL_HBURD_OWN_20 | E_HBURD_RENT_20 | ET_HOUSINGCOST_RENT_20 | EP_HBURD_RENT_20 | EPL_HBURD_RENT_20 | E_HBURD_20 | ET_HOUSINGCOST_20 | EP_HBURD_20 | EPL_HBURD_20 | E_NOHSDP_20 | ET_EDSTATUS_20 | EP_NOHSDP_20 | EPL_NOHSDP_20 | E_UNINSUR_20 | ET_INSURSTATUS_20 | EP_UNINSUR_20 | EPL_UNINSUR_20 | E_AGE65_20 | EP_AGE65_20 | EPL_AGE65_20 | E_AGE17_20 | EP_AGE17_20 | EPL_AGE17_20 | E_DISABL_20 | ET_DISABLSTATUS_20 | EP_DISABL_20 | EPL_DISABL_20 | E_SNGPNT_20 | ET_FAMILIES_20 | EP_SNGPNT_20 | EPL_SNGPNT_20 | E_LIMENG_20 | ET_POPAGE5UP_20 | EP_LIMENG_20 | EPL_LIMENG_20 | E_MINRTY_20 | ET_POPETHRACE_20 | EP_MINRTY_20 | EPL_MINRTY_20 | E_STRHU_20 | E_MUNIT_20 | EP_MUNIT_20 | EPL_MUNIT_20 | E_MOBILE_20 | EP_MOBILE_20 | EPL_MOBILE_20 | E_CROWD_20 | ET_OCCUPANTS_20 | EP_CROWD_20 | EPL_CROWD_20 | E_NOVEH_20 | ET_KNOWNVEH_20 | EP_NOVEH_20 | EPL_NOVEH_20 | E_GROUPQ_20 | ET_HHTYPE_20 | EP_GROUPQ_20 | EPL_GROUPQ_20 |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
34001000100 | 34 | 001 | 000100 | NJ | New Jersey | Atlantic County | 1 | Northeast Region | 2 | Middle Atlantic Division | 2157 | 941 | 784 | 1182 | 2157 | 54.79833 | 0.9571 | 242 | 1058 | 22.873346 | 0.9922 | 215 | 342 | 62.86550 | 0.9780 | 316 | 442 | 71.49321 | 0.9481 | 531 | 784 | 67.72959 | 0.9893 | 396 | 1274 | 31.08320 | 0.9497 | 266 | 2157 | 12.331943 | 0.9041 | 185 | 8.576727 | 0.09430 | 552 | 25.59110 | 0.8128 | 297 | 1605 | 18.504673 | 0.74880 | 83 | 510 | 16.27451 | 0.6090 | 251 | 2020 | 12.425743 | 0.8710 | 1852 | 2157 | 85.85999 | 0.8476 | 941 | 118 | 12.5398512 | 0.6385 | 0 | 0.0000000 | 0.3216 | 67 | 784 | 8.545918 | 0.8657 | 212 | 784 | 27.04082 | 0.7502 | 0 | 2157 | 0.0000000 | 0.1517 |
34001000200 | 34 | 001 | 000200 | NJ | New Jersey | Atlantic County | 1 | Northeast Region | 2 | Middle Atlantic Division | 3510 | 2046 | 1353 | 1021 | 3510 | 29.08832 | 0.7682 | 121 | 1852 | 6.533477 | 0.6717 | 343 | 696 | 49.28161 | 0.9273 | 416 | 657 | 63.31811 | 0.8696 | 759 | 1353 | 56.09756 | 0.9321 | 553 | 2338 | 23.65269 | 0.8871 | 354 | 3510 | 10.085470 | 0.8530 | 643 | 18.319088 | 0.60310 | 1002 | 28.54701 | 0.9055 | 450 | 2508 | 17.942584 | 0.72330 | 237 | 786 | 30.15267 | 0.8539 | 534 | 3375 | 15.822222 | 0.9062 | 2534 | 3510 | 72.19373 | 0.7818 | 2046 | 906 | 44.2815249 | 0.8690 | 0 | 0.0000000 | 0.3216 | 119 | 1353 | 8.795270 | 0.8711 | 324 | 1353 | 23.94678 | 0.7255 | 0 | 3510 | 0.0000000 | 0.1517 |
34001000300 | 34 | 001 | 000300 | NJ | New Jersey | Atlantic County | 1 | Northeast Region | 2 | Middle Atlantic Division | 3801 | 1640 | 1226 | 1857 | 3801 | 48.85556 | 0.9333 | 226 | 1800 | 12.555556 | 0.9267 | 111 | 280 | 39.64286 | 0.8339 | 608 | 946 | 64.27061 | 0.8842 | 719 | 1226 | 58.64600 | 0.9528 | 650 | 2275 | 28.57143 | 0.9337 | 1027 | 3801 | 27.019206 | 0.9914 | 380 | 9.997369 | 0.14040 | 1223 | 32.17574 | 0.9607 | 219 | 2578 | 8.494957 | 0.15680 | 268 | 909 | 29.48295 | 0.8456 | 940 | 3400 | 27.647059 | 0.9728 | 3318 | 3801 | 87.29282 | 0.8579 | 1640 | 262 | 15.9756098 | 0.6917 | 0 | 0.0000000 | 0.3216 | 124 | 1226 | 10.114192 | 0.8955 | 477 | 1226 | 38.90701 | 0.8258 | 0 | 3801 | 0.0000000 | 0.1517 |
34001000400 | 34 | 001 | 000400 | NJ | New Jersey | Atlantic County | 1 | Northeast Region | 2 | Middle Atlantic Division | 3178 | 2264 | 1390 | 1508 | 3176 | 47.48111 | 0.9246 | 172 | 1804 | 9.534368 | 0.8460 | 205 | 468 | 43.80342 | 0.8858 | 622 | 922 | 67.46204 | 0.9192 | 827 | 1390 | 59.49640 | 0.9587 | 364 | 2076 | 17.53372 | 0.8013 | 476 | 3178 | 14.977974 | 0.9390 | 483 | 15.198238 | 0.41220 | 539 | 16.96035 | 0.2484 | 319 | 2639 | 12.087912 | 0.38790 | 101 | 565 | 17.87611 | 0.6539 | 583 | 3022 | 19.291860 | 0.9349 | 2186 | 3178 | 68.78540 | 0.7658 | 2264 | 1609 | 71.0689046 | 0.9266 | 15 | 0.6625442 | 0.7078 | 226 | 1390 | 16.258993 | 0.9567 | 599 | 1390 | 43.09353 | 0.8474 | 20 | 3178 | 0.6293266 | 0.6292 |
34001000500 | 34 | 001 | 000500 | NJ | New Jersey | Atlantic County | 1 | Northeast Region | 2 | Middle Atlantic Division | 3385 | 1185 | 945 | 1682 | 3364 | 50.00000 | 0.9391 | 72 | 1577 | 4.565631 | 0.4586 | 185 | 468 | 39.52991 | 0.8332 | 362 | 477 | 75.89099 | 0.9703 | 547 | 945 | 57.88360 | 0.9477 | 592 | 1983 | 29.85376 | 0.9422 | 738 | 3385 | 21.802068 | 0.9817 | 240 | 7.090103 | 0.05988 | 1129 | 33.35303 | 0.9689 | 135 | 2256 | 5.984043 | 0.04817 | 110 | 717 | 15.34170 | 0.5822 | 721 | 3076 | 23.439532 | 0.9569 | 3029 | 3385 | 89.48301 | 0.8727 | 1185 | 9 | 0.7594937 | 0.2382 | 0 | 0.0000000 | 0.3216 | 103 | 945 | 10.899471 | 0.9072 | 263 | 945 | 27.83069 | 0.7560 | 0 | 3385 | 0.0000000 | 0.1517 |
34001001100 | 34 | 001 | 001100 | NJ | New Jersey | Atlantic County | 1 | Northeast Region | 2 | Middle Atlantic Division | 1950 | 1267 | 1096 | 1131 | 1950 | 58.00000 | 0.9678 | 66 | 706 | 9.348442 | 0.8395 | 42 | 101 | 41.58416 | 0.8612 | 309 | 995 | 31.05528 | 0.1959 | 351 | 1096 | 32.02555 | 0.4782 | 510 | 1379 | 36.98332 | 0.9763 | 155 | 1950 | 7.948718 | 0.7660 | 392 | 20.102564 | 0.69880 | 447 | 22.92308 | 0.6712 | 570 | 1503 | 37.924152 | 0.99200 | 143 | 374 | 38.23529 | 0.9167 | 109 | 1841 | 5.920695 | 0.7464 | 1909 | 1950 | 97.89744 | 0.9529 | 1267 | 479 | 37.8058406 | 0.8464 | 0 | 0.0000000 | 0.3216 | 33 | 1096 | 3.010949 | 0.6446 | 743 | 1096 | 67.79197 | 0.9414 | 0 | 1950 | 0.0000000 | 0.1517 |
For state we need to enter state and our state of interest:
# State
svi_2010_state <- rank_variables(svi_2010, rank_by = "state", location = "PA")
svi_2010_state %>% head() %>% kbl() %>% kable_styling() %>% scroll_box(width = "100%")
GEOID_2010_trt | FIPS_st | FIPS_county | FIPS_tract | state | state_name | county | region_number | region | division_number | division | E_TOTPOP_10 | E_HU_10 | E_HH_10 | E_POV150_10 | ET_POVSTATUS_10 | EP_POV150_10 | EPL_POV150_10 | E_UNEMP_10 | ET_EMPSTATUS_10 | EP_UNEMP_10 | EPL_UNEMP_10 | E_HBURD_OWN_10 | ET_HOUSINGCOST_OWN_10 | EP_HBURD_OWN_10 | EPL_HBURD_OWN_10 | E_HBURD_RENT_10 | ET_HOUSINGCOST_RENT_10 | EP_HBURD_RENT_10 | EPL_HBURD_RENT_10 | E_HBURD_10 | ET_HOUSINGCOST_10 | EP_HBURD_10 | EPL_HBURD_10 | E_NOHSDP_10 | ET_EDSTATUS_10 | EP_NOHSDP_10 | EPL_NOHSDP_10 | E_UNINSUR_12 | ET_INSURSTATUS_12 | EP_UNINSUR_12 | EPL_UNINSUR_12 | E_AGE65_10 | EP_AGE65_10 | EPL_AGE65_10 | E_AGE17_10 | EP_AGE17_10 | EPL_AGE17_10 | E_DISABL_12 | ET_DISABLSTATUS_12 | EP_DISABL_12 | EPL_DISABL_12 | E_SNGPNT_10 | ET_FAMILIES_10 | EP_SNGPNT_10 | EPL_SNGPNT_10 | E_LIMENG_10 | ET_POPAGE5UP_10 | EP_LIMENG_10 | EPL_LIMENG_10 | E_MINRTY_10 | ET_POPETHRACE_10 | EP_MINRTY_10 | EPL_MINRTY_10 | E_STRHU_10 | E_MUNIT_10 | EP_MUNIT_10 | EPL_MUNIT_10 | E_MOBILE_10 | EP_MOBILE_10 | EPL_MOBILE_10 | E_CROWD_10 | ET_OCCUPANTS_10 | EP_CROWD_10 | EPL_CROWD_10 | E_NOVEH_10 | ET_KNOWNVEH_10 | EP_NOVEH_10 | EPL_NOVEH_10 | E_GROUPQ_10 | ET_HHTYPE_10 | EP_GROUPQ_10 | EPL_GROUPQ_10 |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
42001030101 | 42 | 001 | 030101 | PA | Pennsylvania | Adams County | 1 | Northeast Region | 2 | Middle Atlantic Division | 2597 | 993 | 915 | 230 | 2597 | 8.856373 | 0.1950 | 51 | 1399 | 3.645461 | 0.14870 | 279 | 840 | 33.21429 | 0.7852 | 27 | 75 | 36.00000 | 0.3706 | 306 | 915 | 33.44262 | 0.6063 | 185 | 1784 | 10.36996 | 0.4372 | 172 | 2580 | 6.666667 | 0.3133 | 280 | 10.781671 | 0.1947 | 694 | 26.72314 | 0.8216 | 281 | 1963 | 14.31482 | 0.4013 | 36 | 808 | 4.455445 | 0.09445 | 16 | 2481 | 0.6449012 | 0.5528 | 120 | 2597 | 4.620716 | 0.3091 | 993 | 0 | 0.000000 | 0.1312 | 55 | 5.538771 | 0.7558 | 5 | 915 | 0.5464481 | 0.4989 | 9 | 915 | 0.9836066 | 0.06514 | 0 | 2597 | 0 | 0.3334 |
42001030102 | 42 | 001 | 030102 | PA | Pennsylvania | Adams County | 1 | Northeast Region | 2 | Middle Atlantic Division | 5709 | 2415 | 2220 | 675 | 5709 | 11.823437 | 0.2920 | 236 | 3176 | 7.430731 | 0.59030 | 595 | 1894 | 31.41499 | 0.7163 | 131 | 326 | 40.18405 | 0.4772 | 726 | 2220 | 32.70270 | 0.5744 | 645 | 3990 | 16.16541 | 0.7281 | 326 | 5717 | 5.702291 | 0.2461 | 703 | 12.313890 | 0.2850 | 1332 | 23.33158 | 0.6116 | 674 | 4490 | 15.01114 | 0.4460 | 185 | 1727 | 10.712218 | 0.41920 | 95 | 5461 | 1.7396081 | 0.7700 | 370 | 5709 | 6.480995 | 0.3994 | 2415 | 0 | 0.000000 | 0.1312 | 261 | 10.807453 | 0.8497 | 61 | 2220 | 2.7477477 | 0.8804 | 62 | 2220 | 2.7927928 | 0.21860 | 0 | 5709 | 0 | 0.3334 |
42001030200 | 42 | 001 | 030200 | PA | Pennsylvania | Adams County | 1 | Northeast Region | 2 | Middle Atlantic Division | 5656 | 2180 | 2111 | 983 | 5588 | 17.591267 | 0.4964 | 161 | 3170 | 5.078864 | 0.30640 | 481 | 1677 | 28.68217 | 0.6106 | 154 | 434 | 35.48387 | 0.3586 | 635 | 2111 | 30.08053 | 0.4666 | 771 | 3785 | 20.36988 | 0.8475 | 877 | 5471 | 16.029976 | 0.8743 | 664 | 11.739745 | 0.2453 | 1428 | 25.24752 | 0.7469 | 630 | 4135 | 15.23579 | 0.4586 | 247 | 1594 | 15.495608 | 0.61690 | 193 | 5363 | 3.5987321 | 0.8791 | 866 | 5656 | 15.311174 | 0.6466 | 2180 | 0 | 0.000000 | 0.1312 | 302 | 13.853211 | 0.8982 | 70 | 2111 | 3.3159640 | 0.9126 | 85 | 2111 | 4.0265277 | 0.31290 | 0 | 5656 | 0 | 0.3334 |
42001030300 | 42 | 001 | 030300 | PA | Pennsylvania | Adams County | 1 | Northeast Region | 2 | Middle Atlantic Division | 3932 | 1561 | 1438 | 522 | 3913 | 13.340148 | 0.3424 | 103 | 2127 | 4.842501 | 0.27670 | 357 | 1097 | 32.54330 | 0.7606 | 89 | 341 | 26.09971 | 0.1637 | 446 | 1438 | 31.01530 | 0.5089 | 452 | 2560 | 17.65625 | 0.7828 | 634 | 4125 | 15.369697 | 0.8549 | 380 | 9.664293 | 0.1431 | 1059 | 26.93286 | 0.8306 | 369 | 3011 | 12.25506 | 0.2787 | 176 | 1125 | 15.644444 | 0.62220 | 190 | 3617 | 5.2529721 | 0.9178 | 673 | 3932 | 17.115972 | 0.6756 | 1561 | 0 | 0.000000 | 0.1312 | 90 | 5.765535 | 0.7592 | 67 | 1438 | 4.6592490 | 0.9511 | 6 | 1438 | 0.4172462 | 0.03038 | 0 | 3932 | 0 | 0.3334 |
42001030400 | 42 | 001 | 030400 | PA | Pennsylvania | Adams County | 1 | Northeast Region | 2 | Middle Atlantic Division | 5661 | 2359 | 2218 | 765 | 5658 | 13.520679 | 0.3512 | 74 | 3122 | 2.370275 | 0.05383 | 577 | 1766 | 32.67271 | 0.7653 | 221 | 452 | 48.89381 | 0.6877 | 798 | 2218 | 35.97836 | 0.6846 | 520 | 3886 | 13.38137 | 0.5988 | 697 | 5692 | 12.245256 | 0.7295 | 688 | 12.153330 | 0.2731 | 1423 | 25.13690 | 0.7381 | 694 | 4338 | 15.99816 | 0.5052 | 320 | 1633 | 19.595836 | 0.71700 | 29 | 5276 | 0.5496588 | 0.5116 | 644 | 5661 | 11.376082 | 0.5712 | 2359 | 77 | 3.264095 | 0.5131 | 224 | 9.495549 | 0.8303 | 22 | 2218 | 0.9918846 | 0.6427 | 141 | 2218 | 6.3570784 | 0.47170 | 0 | 5661 | 0 | 0.3334 |
42001030500 | 42 | 001 | 030500 | PA | Pennsylvania | Adams County | 1 | Northeast Region | 2 | Middle Atlantic Division | 3676 | 1585 | 1541 | 568 | 3670 | 15.476839 | 0.4235 | 96 | 1952 | 4.918033 | 0.28480 | 275 | 1214 | 22.65239 | 0.2979 | 142 | 327 | 43.42508 | 0.5586 | 417 | 1541 | 27.06035 | 0.3301 | 477 | 2622 | 18.19222 | 0.7978 | 565 | 3711 | 15.225007 | 0.8483 | 631 | 17.165397 | 0.6422 | 737 | 20.04897 | 0.3312 | 566 | 3026 | 18.70456 | 0.6753 | 116 | 1013 | 11.451135 | 0.45280 | 87 | 3464 | 2.5115473 | 0.8356 | 500 | 3676 | 13.601741 | 0.6162 | 1585 | 39 | 2.460568 | 0.4703 | 160 | 10.094637 | 0.8406 | 22 | 1541 | 1.4276444 | 0.7285 | 59 | 1541 | 3.8286827 | 0.29970 | 0 | 3676 | 0 | 0.3334 |
# State
svi_2020_state <- rank_variables(svi_2020, rank_by = "state", location = "PA")
svi_2020_state %>% head() %>% kbl() %>% kable_styling() %>% scroll_box(width = "100%")
GEOID_2010_trt | FIPS_st | FIPS_county | FIPS_tract | state | state_name | county | region_number | region | division_number | division | E_TOTPOP_20 | E_HU_20 | E_HH_20 | E_POV150_20 | ET_POVSTATUS_20 | EP_POV150_20 | EPL_POV150_20 | E_UNEMP_20 | ET_EMPSTATUS_20 | EP_UNEMP_20 | EPL_UNEMP_20 | E_HBURD_OWN_20 | ET_HOUSINGCOST_OWN_20 | EP_HBURD_OWN_20 | EPL_HBURD_OWN_20 | E_HBURD_RENT_20 | ET_HOUSINGCOST_RENT_20 | EP_HBURD_RENT_20 | EPL_HBURD_RENT_20 | E_HBURD_20 | ET_HOUSINGCOST_20 | EP_HBURD_20 | EPL_HBURD_20 | E_NOHSDP_20 | ET_EDSTATUS_20 | EP_NOHSDP_20 | EPL_NOHSDP_20 | E_UNINSUR_20 | ET_INSURSTATUS_20 | EP_UNINSUR_20 | EPL_UNINSUR_20 | E_AGE65_20 | EP_AGE65_20 | EPL_AGE65_20 | E_AGE17_20 | EP_AGE17_20 | EPL_AGE17_20 | E_DISABL_20 | ET_DISABLSTATUS_20 | EP_DISABL_20 | EPL_DISABL_20 | E_SNGPNT_20 | ET_FAMILIES_20 | EP_SNGPNT_20 | EPL_SNGPNT_20 | E_LIMENG_20 | ET_POPAGE5UP_20 | EP_LIMENG_20 | EPL_LIMENG_20 | E_MINRTY_20 | ET_POPETHRACE_20 | EP_MINRTY_20 | EPL_MINRTY_20 | E_STRHU_20 | E_MUNIT_20 | EP_MUNIT_20 | EPL_MUNIT_20 | E_MOBILE_20 | EP_MOBILE_20 | EPL_MOBILE_20 | E_CROWD_20 | ET_OCCUPANTS_20 | EP_CROWD_20 | EPL_CROWD_20 | E_NOVEH_20 | ET_KNOWNVEH_20 | EP_NOVEH_20 | EPL_NOVEH_20 | E_GROUPQ_20 | ET_HHTYPE_20 | EP_GROUPQ_20 | EPL_GROUPQ_20 |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
42001030101 | 42 | 001 | 030101 | PA | Pennsylvania | Adams County | 1 | Northeast Region | 2 | Middle Atlantic Division | 2651 | 1160 | 1058 | 246 | 2651 | 9.279517 | 0.2243 | 12 | 1433 | 0.837404 | 0.02914 | 200 | 940 | 21.27660 | 0.6030 | 33 | 118 | 27.96610 | 0.20760 | 233 | 1058 | 22.02268 | 0.3198 | 167 | 1930 | 8.65285 | 0.5666 | 182 | 2652 | 6.862745 | 0.7413 | 521 | 19.65296 | 0.5860 | 601 | 22.67069 | 0.6889 | 262 | 2050.964 | 12.77448 | 0.2721 | 33 | 760.4212 | 4.339700 | 0.09897 | 42 | 2495 | 1.683367 | 0.7392 | 397 | 2650.619 | 14.977633 | 0.5194 | 1160 | 0 | 0.000000 | 0.1113 | 50 | 4.310345 | 0.7433 | 21 | 1058 | 1.984877 | 0.7410 | 8 | 1057.939 | 0.7561874 | 0.04917 | 0 | 2651 | 0.0000000 | 0.1546 |
42001030102 | 42 | 001 | 030102 | PA | Pennsylvania | Adams County | 1 | Northeast Region | 2 | Middle Atlantic Division | 5873 | 2397 | 2211 | 591 | 5837 | 10.125064 | 0.2547 | 138 | 3182 | 4.336895 | 0.46080 | 296 | 2028 | 14.59566 | 0.2304 | 75 | 183 | 40.98361 | 0.51510 | 371 | 2211 | 16.77974 | 0.1063 | 455 | 4273 | 10.64826 | 0.6904 | 337 | 5873 | 5.738124 | 0.6508 | 1256 | 21.38600 | 0.6876 | 1286 | 21.89682 | 0.6345 | 751 | 4587.000 | 16.37236 | 0.4975 | 130 | 1733.0000 | 7.501443 | 0.24150 | 0 | 5729 | 0.000000 | 0.1334 | 280 | 5873.000 | 4.767581 | 0.1981 | 2397 | 0 | 0.000000 | 0.1113 | 341 | 14.226116 | 0.9282 | 25 | 2211 | 1.130710 | 0.6043 | 33 | 2211.000 | 1.4925373 | 0.10300 | 0 | 5873 | 0.0000000 | 0.1546 |
42001030200 | 42 | 001 | 030200 | PA | Pennsylvania | Adams County | 1 | Northeast Region | 2 | Middle Atlantic Division | 5824 | 2189 | 2044 | 1054 | 5816 | 18.122421 | 0.5288 | 170 | 2876 | 5.910988 | 0.64130 | 341 | 1574 | 21.66455 | 0.6237 | 206 | 470 | 43.82979 | 0.59050 | 547 | 2044 | 26.76125 | 0.5394 | 718 | 4007 | 17.91864 | 0.8949 | 756 | 5808 | 13.016529 | 0.9439 | 976 | 16.75824 | 0.4081 | 1432 | 24.58791 | 0.7930 | 609 | 4376.036 | 13.91670 | 0.3447 | 130 | 1572.5788 | 8.266676 | 0.28590 | 266 | 5495 | 4.840764 | 0.8937 | 1357 | 5824.381 | 23.298614 | 0.6566 | 2189 | 0 | 0.000000 | 0.1113 | 393 | 17.953403 | 0.9602 | 55 | 2044 | 2.690802 | 0.8172 | 59 | 2044.061 | 2.8864106 | 0.22300 | 7 | 5824 | 0.1201923 | 0.3637 |
42001030300 | 42 | 001 | 030300 | PA | Pennsylvania | Adams County | 1 | Northeast Region | 2 | Middle Atlantic Division | 4306 | 1763 | 1620 | 324 | 4298 | 7.538390 | 0.1620 | 57 | 2528 | 2.254747 | 0.16040 | 245 | 1358 | 18.04124 | 0.4282 | 53 | 262 | 20.22901 | 0.09642 | 298 | 1620 | 18.39506 | 0.1703 | 359 | 3137 | 11.44405 | 0.7264 | 310 | 4299 | 7.210979 | 0.7670 | 666 | 15.46679 | 0.3333 | 824 | 19.13609 | 0.4109 | 473 | 3475.000 | 13.61151 | 0.3262 | 20 | 1173.0000 | 1.705030 | 0.02443 | 151 | 4119 | 3.665938 | 0.8624 | 813 | 4306.000 | 18.880632 | 0.5894 | 1763 | 0 | 0.000000 | 0.1113 | 182 | 10.323313 | 0.8665 | 59 | 1620 | 3.641975 | 0.8786 | 32 | 1620.000 | 1.9753086 | 0.14030 | 87 | 4306 | 2.0204366 | 0.7477 |
42001030400 | 42 | 001 | 030400 | PA | Pennsylvania | Adams County | 1 | Northeast Region | 2 | Middle Atlantic Division | 5798 | 2614 | 2271 | 967 | 5697 | 16.973846 | 0.4937 | 69 | 2979 | 2.316213 | 0.16920 | 444 | 1839 | 24.14356 | 0.7325 | 138 | 432 | 31.94444 | 0.28360 | 582 | 2271 | 25.62748 | 0.4917 | 696 | 4198 | 16.57932 | 0.8705 | 549 | 5697 | 9.636651 | 0.8697 | 1196 | 20.62780 | 0.6426 | 1192 | 20.55881 | 0.5253 | 871 | 4505.000 | 19.33407 | 0.6741 | 220 | 1721.0000 | 12.783266 | 0.49800 | 135 | 5437 | 2.482987 | 0.8093 | 513 | 5798.000 | 8.847879 | 0.3531 | 2614 | 61 | 2.333588 | 0.4313 | 283 | 10.826320 | 0.8752 | 91 | 2271 | 4.007045 | 0.8990 | 210 | 2271.000 | 9.2470277 | 0.60570 | 139 | 5798 | 2.3973784 | 0.7745 |
42001030500 | 42 | 001 | 030500 | PA | Pennsylvania | Adams County | 1 | Northeast Region | 2 | Middle Atlantic Division | 3879 | 1675 | 1531 | 771 | 3879 | 19.876257 | 0.5852 | 110 | 2120 | 5.188679 | 0.56360 | 189 | 1173 | 16.11253 | 0.3112 | 161 | 358 | 44.97207 | 0.61870 | 350 | 1531 | 22.86088 | 0.3590 | 418 | 2743 | 15.23879 | 0.8458 | 263 | 3879 | 6.780098 | 0.7376 | 815 | 21.01057 | 0.6679 | 796 | 20.52075 | 0.5235 | 513 | 3083.000 | 16.63964 | 0.5125 | 137 | 1139.0000 | 12.028095 | 0.46350 | 131 | 3667 | 3.572402 | 0.8587 | 831 | 3879.000 | 21.423047 | 0.6300 | 1675 | 28 | 1.671642 | 0.3824 | 147 | 8.776119 | 0.8404 | 23 | 1531 | 1.502286 | 0.6736 | 35 | 1531.000 | 2.2860875 | 0.16500 | 12 | 3879 | 0.3093581 | 0.5109 |
And then finally recall for county we need to add state abbreviation:
# Note that county without state returns an error
rank_variables(svi_2010, rank_by = "county", location = "Bucks County")
[1] "Enter state abbreviation in function and re-try"
NULL
# County
svi_2010_county <- rank_variables(svi_2010, rank_by = "county", location = "Bucks County", state_abbr = "PA")
svi_2010_county %>% head() %>% kbl() %>% kable_styling() %>% scroll_box(width = "100%")
GEOID_2010_trt | FIPS_st | FIPS_county | FIPS_tract | state | state_name | county | region_number | region | division_number | division | E_TOTPOP_10 | E_HU_10 | E_HH_10 | E_POV150_10 | ET_POVSTATUS_10 | EP_POV150_10 | EPL_POV150_10 | E_UNEMP_10 | ET_EMPSTATUS_10 | EP_UNEMP_10 | EPL_UNEMP_10 | E_HBURD_OWN_10 | ET_HOUSINGCOST_OWN_10 | EP_HBURD_OWN_10 | EPL_HBURD_OWN_10 | E_HBURD_RENT_10 | ET_HOUSINGCOST_RENT_10 | EP_HBURD_RENT_10 | EPL_HBURD_RENT_10 | E_HBURD_10 | ET_HOUSINGCOST_10 | EP_HBURD_10 | EPL_HBURD_10 | E_NOHSDP_10 | ET_EDSTATUS_10 | EP_NOHSDP_10 | EPL_NOHSDP_10 | E_UNINSUR_12 | ET_INSURSTATUS_12 | EP_UNINSUR_12 | EPL_UNINSUR_12 | E_AGE65_10 | EP_AGE65_10 | EPL_AGE65_10 | E_AGE17_10 | EP_AGE17_10 | EPL_AGE17_10 | E_DISABL_12 | ET_DISABLSTATUS_12 | EP_DISABL_12 | EPL_DISABL_12 | E_SNGPNT_10 | ET_FAMILIES_10 | EP_SNGPNT_10 | EPL_SNGPNT_10 | E_LIMENG_10 | ET_POPAGE5UP_10 | EP_LIMENG_10 | EPL_LIMENG_10 | E_MINRTY_10 | ET_POPETHRACE_10 | EP_MINRTY_10 | EPL_MINRTY_10 | E_STRHU_10 | E_MUNIT_10 | EP_MUNIT_10 | EPL_MUNIT_10 | E_MOBILE_10 | EP_MOBILE_10 | EPL_MOBILE_10 | E_CROWD_10 | ET_OCCUPANTS_10 | EP_CROWD_10 | EPL_CROWD_10 | E_NOVEH_10 | ET_KNOWNVEH_10 | EP_NOVEH_10 | EPL_NOVEH_10 | E_GROUPQ_10 | ET_HHTYPE_10 | EP_GROUPQ_10 | EPL_GROUPQ_10 |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
42017100102 | 42 | 017 | 100102 | PA | Pennsylvania | Bucks County | 1 | Northeast Region | 2 | Middle Atlantic Division | 2520 | 1559 | 1255 | 501 | 2484 | 20.16908 | 0.9437 | 110 | 1281 | 8.587041 | 0.8732 | 179 | 415 | 43.13253 | 0.9366 | 387 | 840 | 46.07143 | 0.4648 | 566 | 1255 | 45.09960 | 0.9014 | 233 | 1952 | 11.936475 | 0.7606 | 209 | 2770 | 7.545126 | 0.6549 | 455 | 18.055556 | 0.8169 | 429 | 17.02381 | 0.08451 | 466 | 2391 | 19.48975 | 0.8873 | 102 | 575 | 17.739130 | 0.8803 | 38 | 2373 | 1.6013485 | 0.6972 | 361 | 2520 | 14.32540 | 0.7606 | 1559 | 366 | 23.476588 | 0.9014 | 25 | 1.603592 | 0.8310 | 29 | 1255 | 2.310757 | 0.9296 | 41 | 1255 | 3.266932 | 0.5986 | 0 | 2520 | 0.0000000 | 0.3275 |
42017100103 | 42 | 017 | 100103 | PA | Pennsylvania | Bucks County | 1 | Northeast Region | 2 | Middle Atlantic Division | 2677 | 1134 | 1009 | 303 | 2136 | 14.18539 | 0.7535 | 64 | 1204 | 5.315615 | 0.4225 | 219 | 570 | 38.42105 | 0.8310 | 172 | 439 | 39.17995 | 0.3521 | 391 | 1009 | 38.75124 | 0.6972 | 202 | 1568 | 12.882653 | 0.7958 | 190 | 2161 | 8.792226 | 0.7535 | 400 | 14.942099 | 0.6549 | 709 | 26.48487 | 0.78870 | 388 | 1880 | 20.63830 | 0.9648 | 52 | 571 | 9.106830 | 0.5070 | 22 | 2545 | 0.8644401 | 0.4648 | 972 | 2677 | 36.30930 | 0.9366 | 1134 | 185 | 16.313933 | 0.8310 | 0 | 0.000000 | 0.3451 | 0 | 1009 | 0.000000 | 0.2535 | 78 | 1009 | 7.730426 | 0.8662 | 541 | 2677 | 20.2091894 | 0.9789 |
42017100104 | 42 | 017 | 100104 | PA | Pennsylvania | Bucks County | 1 | Northeast Region | 2 | Middle Atlantic Division | 4613 | 2052 | 1830 | 1091 | 4613 | 23.65055 | 0.9648 | 158 | 2492 | 6.340289 | 0.5634 | 211 | 611 | 34.53355 | 0.5845 | 672 | 1219 | 55.12715 | 0.7254 | 883 | 1830 | 48.25137 | 0.9577 | 447 | 3271 | 13.665546 | 0.8239 | 469 | 4441 | 10.560685 | 0.8521 | 590 | 12.789941 | 0.4296 | 788 | 17.08216 | 0.09859 | 637 | 3631 | 17.54338 | 0.8028 | 135 | 1175 | 11.489362 | 0.6761 | 365 | 4357 | 8.3773238 | 0.9859 | 1846 | 4613 | 40.01734 | 0.9718 | 2052 | 549 | 26.754386 | 0.9225 | 0 | 0.000000 | 0.3451 | 0 | 1830 | 0.000000 | 0.2535 | 270 | 1830 | 14.754098 | 0.9648 | 0 | 4613 | 0.0000000 | 0.3275 |
42017100105 | 42 | 017 | 100105 | PA | Pennsylvania | Bucks County | 1 | Northeast Region | 2 | Middle Atlantic Division | 3457 | 1324 | 1242 | 444 | 3457 | 12.84351 | 0.7042 | 225 | 1719 | 13.089005 | 0.9859 | 334 | 982 | 34.01222 | 0.5352 | 139 | 260 | 53.46154 | 0.7042 | 473 | 1242 | 38.08374 | 0.6620 | 452 | 2418 | 18.693135 | 0.9507 | 385 | 3593 | 10.715280 | 0.8732 | 528 | 15.273358 | 0.6901 | 752 | 21.75296 | 0.42250 | 490 | 2896 | 16.91989 | 0.7606 | 57 | 886 | 6.433409 | 0.3099 | 150 | 3288 | 4.5620438 | 0.9437 | 458 | 3457 | 13.24848 | 0.7254 | 1324 | 21 | 1.586103 | 0.3873 | 0 | 0.000000 | 0.3451 | 50 | 1242 | 4.025765 | 0.9718 | 61 | 1242 | 4.911433 | 0.7113 | 34 | 3457 | 0.9835117 | 0.7535 |
42017100201 | 42 | 017 | 100201 | PA | Pennsylvania | Bucks County | 1 | Northeast Region | 2 | Middle Atlantic Division | 4127 | 1789 | 1605 | 576 | 4127 | 13.95687 | 0.7394 | 159 | 2197 | 7.237142 | 0.7042 | 521 | 1376 | 37.86337 | 0.8169 | 89 | 229 | 38.86463 | 0.3451 | 610 | 1605 | 38.00623 | 0.6479 | 457 | 2990 | 15.284281 | 0.8944 | 557 | 4264 | 13.062852 | 0.9577 | 601 | 14.562636 | 0.5915 | 839 | 20.32954 | 0.28170 | 429 | 3380 | 12.69231 | 0.6197 | 62 | 1165 | 5.321888 | 0.2183 | 135 | 3825 | 3.5294118 | 0.8803 | 887 | 4127 | 21.49261 | 0.8521 | 1789 | 0 | 0.000000 | 0.1444 | 244 | 13.638904 | 0.9648 | 37 | 1605 | 2.305296 | 0.9225 | 76 | 1605 | 4.735202 | 0.6901 | 0 | 4127 | 0.0000000 | 0.3275 |
42017100206 | 42 | 017 | 100206 | PA | Pennsylvania | Bucks County | 1 | Northeast Region | 2 | Middle Atlantic Division | 4815 | 2086 | 1828 | 860 | 4786 | 17.96908 | 0.8944 | 194 | 2661 | 7.290492 | 0.7254 | 426 | 1103 | 38.62194 | 0.8451 | 370 | 725 | 51.03448 | 0.6338 | 796 | 1828 | 43.54486 | 0.8592 | 237 | 3392 | 6.987028 | 0.5000 | 439 | 4765 | 9.213012 | 0.7887 | 452 | 9.387331 | 0.1620 | 1097 | 22.78297 | 0.50700 | 421 | 3746 | 11.23865 | 0.4507 | 180 | 1392 | 12.931035 | 0.7500 | 50 | 4570 | 1.0940919 | 0.5634 | 1095 | 4815 | 22.74143 | 0.8803 | 2086 | 189 | 9.060403 | 0.7042 | 25 | 1.198466 | 0.7887 | 0 | 1828 | 0.000000 | 0.2535 | 53 | 1828 | 2.899344 | 0.5563 | 34 | 4815 | 0.7061267 | 0.7113 |
# County
svi_2020_county <- rank_variables(svi_2020, rank_by = "county", location = "Bucks County", state = "PA")
svi_2020_county %>% head() %>% kbl() %>% kable_styling() %>% scroll_box(width = "100%")
GEOID_2010_trt | FIPS_st | FIPS_county | FIPS_tract | state | state_name | county | region_number | region | division_number | division | E_TOTPOP_20 | E_HU_20 | E_HH_20 | E_POV150_20 | ET_POVSTATUS_20 | EP_POV150_20 | EPL_POV150_20 | E_UNEMP_20 | ET_EMPSTATUS_20 | EP_UNEMP_20 | EPL_UNEMP_20 | E_HBURD_OWN_20 | ET_HOUSINGCOST_OWN_20 | EP_HBURD_OWN_20 | EPL_HBURD_OWN_20 | E_HBURD_RENT_20 | ET_HOUSINGCOST_RENT_20 | EP_HBURD_RENT_20 | EPL_HBURD_RENT_20 | E_HBURD_20 | ET_HOUSINGCOST_20 | EP_HBURD_20 | EPL_HBURD_20 | E_NOHSDP_20 | ET_EDSTATUS_20 | EP_NOHSDP_20 | EPL_NOHSDP_20 | E_UNINSUR_20 | ET_INSURSTATUS_20 | EP_UNINSUR_20 | EPL_UNINSUR_20 | E_AGE65_20 | EP_AGE65_20 | EPL_AGE65_20 | E_AGE17_20 | EP_AGE17_20 | EPL_AGE17_20 | E_DISABL_20 | ET_DISABLSTATUS_20 | EP_DISABL_20 | EPL_DISABL_20 | E_SNGPNT_20 | ET_FAMILIES_20 | EP_SNGPNT_20 | EPL_SNGPNT_20 | E_LIMENG_20 | ET_POPAGE5UP_20 | EP_LIMENG_20 | EPL_LIMENG_20 | E_MINRTY_20 | ET_POPETHRACE_20 | EP_MINRTY_20 | EPL_MINRTY_20 | E_STRHU_20 | E_MUNIT_20 | EP_MUNIT_20 | EPL_MUNIT_20 | E_MOBILE_20 | EP_MOBILE_20 | EPL_MOBILE_20 | E_CROWD_20 | ET_OCCUPANTS_20 | EP_CROWD_20 | EPL_CROWD_20 | E_NOVEH_20 | ET_KNOWNVEH_20 | EP_NOVEH_20 | EPL_NOVEH_20 | E_GROUPQ_20 | ET_HHTYPE_20 | EP_GROUPQ_20 | EPL_GROUPQ_20 |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
42017100102 | 42 | 017 | 100102 | PA | Pennsylvania | Bucks County | 1 | Northeast Region | 2 | Middle Atlantic Division | 2595 | 1375 | 1223 | 547 | 2595 | 21.078998 | 0.9366 | 162 | 1515 | 10.693069 | 0.9648 | 125 | 348 | 35.91954 | 0.9577 | 337 | 875 | 38.51429 | 0.3873 | 462 | 1223 | 37.77596 | 0.8803 | 179 | 2043 | 8.761625 | 0.8028 | 148 | 2595 | 5.703276 | 0.7465 | 545 | 21.001927 | 0.6690 | 311 | 11.98459 | 0.05634 | 342 | 2284 | 14.973730 | 0.7465 | 104 | 711 | 14.627285 | 0.7254 | 25 | 2493 | 1.002808 | 0.4648 | 480 | 2595 | 18.49711 | 0.6831 | 1375 | 422 | 30.69091 | 0.9366 | 25 | 1.818182 | 0.8451 | 58 | 1223 | 4.742437 | 0.9366 | 86 | 1223 | 7.031889 | 0.7324 | 0 | 2595 | 0.0000000 | 0.2042 |
42017100103 | 42 | 017 | 100103 | PA | Pennsylvania | Bucks County | 1 | Northeast Region | 2 | Middle Atlantic Division | 2375 | 1029 | 952 | 479 | 2375 | 20.168421 | 0.8803 | 50 | 1383 | 3.615329 | 0.4789 | 76 | 449 | 16.92650 | 0.1479 | 143 | 503 | 28.42942 | 0.2183 | 219 | 952 | 23.00420 | 0.2113 | 148 | 1688 | 8.767772 | 0.8099 | 143 | 2375 | 6.021053 | 0.7676 | 221 | 9.305263 | 0.0493 | 561 | 23.62105 | 0.79580 | 490 | 1814 | 27.012128 | 0.9930 | 197 | 612 | 32.189543 | 0.9789 | 71 | 2199 | 3.228740 | 0.8521 | 662 | 2375 | 27.87368 | 0.8592 | 1029 | 225 | 21.86589 | 0.8451 | 0 | 0.000000 | 0.3310 | 67 | 952 | 7.037815 | 0.9718 | 99 | 952 | 10.399160 | 0.8944 | 10 | 2375 | 0.4210526 | 0.6549 |
42017100104 | 42 | 017 | 100104 | PA | Pennsylvania | Bucks County | 1 | Northeast Region | 2 | Middle Atlantic Division | 5242 | 2034 | 1982 | 1733 | 5238 | 33.085147 | 0.9930 | 156 | 2950 | 5.288136 | 0.6972 | 130 | 611 | 21.27660 | 0.3239 | 721 | 1371 | 52.58935 | 0.7183 | 851 | 1982 | 42.93643 | 0.9648 | 610 | 3491 | 17.473503 | 1.0000 | 821 | 5238 | 15.673921 | 1.0000 | 609 | 11.617703 | 0.1479 | 1102 | 21.02251 | 0.60560 | 837 | 4138 | 20.227163 | 0.9296 | 236 | 1373 | 17.188638 | 0.7887 | 745 | 4776 | 15.598828 | 1.0000 | 3082 | 5242 | 58.79435 | 1.0000 | 2034 | 600 | 29.49853 | 0.9225 | 0 | 0.000000 | 0.3310 | 161 | 1982 | 8.123108 | 0.9930 | 444 | 1982 | 22.401615 | 1.0000 | 4 | 5242 | 0.0763068 | 0.4085 |
42017100105 | 42 | 017 | 100105 | PA | Pennsylvania | Bucks County | 1 | Northeast Region | 2 | Middle Atlantic Division | 3022 | 1259 | 1199 | 397 | 2942 | 13.494222 | 0.7746 | 137 | 1985 | 6.901763 | 0.8662 | 312 | 953 | 32.73872 | 0.9225 | 74 | 246 | 30.08130 | 0.2606 | 386 | 1199 | 32.19349 | 0.6972 | 95 | 2276 | 4.173990 | 0.4507 | 167 | 2957 | 5.647616 | 0.7324 | 420 | 13.898081 | 0.2817 | 468 | 15.48643 | 0.18310 | 241 | 2543 | 9.476996 | 0.2958 | 51 | 677 | 7.533235 | 0.4507 | 60 | 2882 | 2.081888 | 0.7465 | 362 | 3022 | 11.97882 | 0.4366 | 1259 | 163 | 12.94678 | 0.7042 | 0 | 0.000000 | 0.3310 | 0 | 1199 | 0.000000 | 0.2254 | 106 | 1199 | 8.840701 | 0.8451 | 176 | 3022 | 5.8239576 | 0.9366 |
42017100201 | 42 | 017 | 100201 | PA | Pennsylvania | Bucks County | 1 | Northeast Region | 2 | Middle Atlantic Division | 5061 | 1903 | 1836 | 444 | 4940 | 8.987854 | 0.5634 | 160 | 2803 | 5.708170 | 0.7676 | 513 | 1683 | 30.48128 | 0.8732 | 75 | 153 | 49.01961 | 0.6408 | 588 | 1836 | 32.02614 | 0.6761 | 440 | 3602 | 12.215436 | 0.9437 | 321 | 5061 | 6.342620 | 0.7958 | 645 | 12.744517 | 0.1901 | 935 | 18.47461 | 0.35920 | 503 | 4126 | 12.190984 | 0.5634 | 171 | 1277 | 13.390760 | 0.6690 | 280 | 4838 | 5.787515 | 0.9366 | 1638 | 5061 | 32.36515 | 0.9085 | 1903 | 0 | 0.00000 | 0.1232 | 211 | 11.087756 | 0.9718 | 29 | 1836 | 1.579521 | 0.7465 | 58 | 1836 | 3.159041 | 0.4507 | 5 | 5061 | 0.0987947 | 0.4296 |
42017100206 | 42 | 017 | 100206 | PA | Pennsylvania | Bucks County | 1 | Northeast Region | 2 | Middle Atlantic Division | 5333 | 2093 | 2011 | 449 | 5323 | 8.435093 | 0.5070 | 239 | 3326 | 7.185809 | 0.8873 | 304 | 1095 | 27.76256 | 0.7042 | 490 | 916 | 53.49345 | 0.7535 | 794 | 2011 | 39.48284 | 0.9085 | 499 | 3895 | 12.811296 | 0.9648 | 452 | 5302 | 8.525085 | 0.8944 | 646 | 12.113257 | 0.1620 | 942 | 17.66360 | 0.28170 | 682 | 4360 | 15.642202 | 0.7817 | 202 | 1549 | 13.040671 | 0.6620 | 276 | 5098 | 5.413888 | 0.9296 | 1970 | 5333 | 36.93981 | 0.9225 | 2093 | 555 | 26.51696 | 0.8873 | 0 | 0.000000 | 0.3310 | 91 | 2011 | 4.525112 | 0.9225 | 138 | 2011 | 6.862258 | 0.7254 | 0 | 5333 | 0.0000000 | 0.2042 |
Now that we have our datasets created with our EPL columns filled, we can filter to look at various tracts of interest to see their demographics. For example if we look at Norfolk Naval Shipyard we can see the uniqueness of the area where almost all of its inhabitants live in group quarters (as would be expected due to the fact that residents of this area live in Military Quarters):
# Norfolk Naval Shipyard example
# https://data.indystar.com/census/total-population/total-population-change/census-tract-9801-portsmouth-city-virginia/140-51740980100/
svi_2020_national %>% filter(GEOID_2010_trt == "51740980100") %>% kbl() %>% kable_styling() %>% scroll_box(width = "100%")
GEOID_2010_trt | FIPS_st | FIPS_county | FIPS_tract | state | state_name | county | region_number | region | division_number | division | E_TOTPOP_20 | E_HU_20 | E_HH_20 | E_POV150_20 | ET_POVSTATUS_20 | EP_POV150_20 | EPL_POV150_20 | E_UNEMP_20 | ET_EMPSTATUS_20 | EP_UNEMP_20 | EPL_UNEMP_20 | E_HBURD_OWN_20 | ET_HOUSINGCOST_OWN_20 | EP_HBURD_OWN_20 | EPL_HBURD_OWN_20 | E_HBURD_RENT_20 | ET_HOUSINGCOST_RENT_20 | EP_HBURD_RENT_20 | EPL_HBURD_RENT_20 | E_HBURD_20 | ET_HOUSINGCOST_20 | EP_HBURD_20 | EPL_HBURD_20 | E_NOHSDP_20 | ET_EDSTATUS_20 | EP_NOHSDP_20 | EPL_NOHSDP_20 | E_UNINSUR_20 | ET_INSURSTATUS_20 | EP_UNINSUR_20 | EPL_UNINSUR_20 | E_AGE65_20 | EP_AGE65_20 | EPL_AGE65_20 | E_AGE17_20 | EP_AGE17_20 | EPL_AGE17_20 | E_DISABL_20 | ET_DISABLSTATUS_20 | EP_DISABL_20 | EPL_DISABL_20 | E_SNGPNT_20 | ET_FAMILIES_20 | EP_SNGPNT_20 | EPL_SNGPNT_20 | E_LIMENG_20 | ET_POPAGE5UP_20 | EP_LIMENG_20 | EPL_LIMENG_20 | E_MINRTY_20 | ET_POPETHRACE_20 | EP_MINRTY_20 | EPL_MINRTY_20 | E_STRHU_20 | E_MUNIT_20 | EP_MUNIT_20 | EPL_MUNIT_20 | E_MOBILE_20 | EP_MOBILE_20 | EPL_MOBILE_20 | E_CROWD_20 | ET_OCCUPANTS_20 | EP_CROWD_20 | EPL_CROWD_20 | E_NOVEH_20 | ET_KNOWNVEH_20 | EP_NOVEH_20 | EPL_NOVEH_20 | E_GROUPQ_20 | ET_HHTYPE_20 | EP_GROUPQ_20 | EPL_GROUPQ_20 |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
51740980100 | 51 | 740 | 980100 | VA | Virginia | Portsmouth city | 3 | South Region | 5 | South Atlantic Division | 661 | 0 | 0 | 0 | 0 | NaN | NA | 0 | 14 | 0 | 0.004873 | 0 | 0 | NaN | NA | 0 | 0 | NaN | NA | 0 | 0 | NaN | NA | 0 | 99 | 0 | 0.003598 | 0 | 0 | NaN | NA | 0 | 0 | 0.001609 | 0 | 0 | 0.001926 | 0 | 0 | NaN | NA | 0 | 0 | NaN | NA | 0 | 661 | 0 | 0.09479 | 403 | 661 | 60.96823 | 0.744 | 0 | 0 | NaN | NA | 0 | NaN | NA | 0 | 0 | NaN | NA | 0 | 0 | NaN | NA | 661 | 661 | 100 | 0.9988 |
We can now take this data a step further and create our actual SVI rankings with a second function called svi_theme_variables()
:
Once again, we will want to employ our grepl/regex functions to find our columns of interest for each category. We can refer back to our CDC Social Vulnerability Index chart at the top of the lab to refresh our memories on which variables belong to each grouping.
We can also note that our only variable needed here is the df:
svi_theme_variables <- function(df) {
# Sum of Theme1: Socioeconomic Status Percentiles
SES_cols <- colnames(df) %>% str_detect("EPL_POV|EPL_UNEMP|EPL_HBURD_[0-9]|EPL_NOHSDP|EPL_UNINSUR")
SES_select <- colnames(df)[SES_cols]
SES <- paste0(SES_select)
df2 <- df %>% select(GEOID_2010_trt, all_of(SES)) %>% mutate(SPL_THEME1 = rowSums(across(where(is.numeric)))) %>% select(GEOID_2010_trt, SPL_THEME1)
df <- left_join(df, df2, join_by("GEOID_2010_trt" == "GEOID_2010_trt"))
# Ranking for Theme1: Socioeconomic Status Percentiles with 4 significant digits
df <- df %>%
mutate(RPL_THEME1 = rank(SPL_THEME1)/length(SPL_THEME1)) %>%
mutate(RPL_THEME1 = signif(RPL_THEME1, 4))
# Sum of Theme2: Household Characteristics
HHchar_cols <- colnames(df) %>% str_detect("EPL_AGE65|EPL_AGE17|EPL_DISABL|EPL_SNGPNT|EPL_LIMENG")
HHchar_select <- colnames(df)[HHchar_cols]
HHchar <- paste0(HHchar_select)
df2 <- df %>% select(GEOID_2010_trt, all_of(HHchar)) %>% mutate(SPL_THEME2 = rowSums(across(where(is.numeric)))) %>% select(GEOID_2010_trt, SPL_THEME2)
df <- left_join(df, df2, join_by("GEOID_2010_trt" == "GEOID_2010_trt"))
# Ranking for Theme2: Household Characteristics
df <- df %>%
mutate(RPL_THEME2 = rank(SPL_THEME2)/length(SPL_THEME2)) %>%
mutate(RPL_THEME2 = signif(RPL_THEME2, 4))
# Sum of Theme3: Racial & Ethnic Minority Status
REM_cols <- colnames(df) %>% str_detect("EPL_MINRTY")
REM_select <- colnames(df)[REM_cols]
REM <- paste0(REM_select)
df2 <- df %>% select(GEOID_2010_trt, all_of(REM)) %>% mutate(SPL_THEME3 = rowSums(across(where(is.numeric)))) %>% select(GEOID_2010_trt, SPL_THEME3)
df <- left_join(df, df2, join_by("GEOID_2010_trt" == "GEOID_2010_trt"))
# Ranking for Theme3: Racial & Ethnic Minority Status
df <- df %>%
mutate(RPL_THEME3 = rank(SPL_THEME3)/length(SPL_THEME3)) %>%
mutate(RPL_THEME3 = signif(RPL_THEME3, 4))
# Sum of Theme4: Housing Type & Transportation
HTT_cols <- colnames(df) %>% str_detect("EPL_MUNIT|EPL_MOBILE|EPL_CROWD|EPL_NOVEH|EPL_GROUPQ")
HTT_select <- colnames(df)[HTT_cols]
HTT <- paste0(HTT_select)
df2 <- df %>% select(GEOID_2010_trt, all_of(HTT)) %>% mutate(SPL_THEME4 = rowSums(across(where(is.numeric)))) %>% select(GEOID_2010_trt, SPL_THEME4)
df <- left_join(df, df2, join_by("GEOID_2010_trt" == "GEOID_2010_trt"))
# Ranking for Theme4: Housing Type & Transportation
df <- df %>%
mutate(RPL_THEME4 = rank(SPL_THEME4)/length(SPL_THEME4)) %>%
mutate(RPL_THEME4 = signif(RPL_THEME4, 4))
# Sum for All Themes
SPL_cols <- colnames(df) %>% str_detect("SPL_THEME")
SPL_select <- colnames(df)[SPL_cols]
SPL <- paste0(SPL_select)
df2 <- df %>% select(GEOID_2010_trt, all_of(SPL)) %>% mutate(SPL_THEMES = rowSums(across(where(is.numeric)))) %>% select(GEOID_2010_trt, SPL_THEMES)
df <- left_join(df, df2, join_by("GEOID_2010_trt" == "GEOID_2010_trt"))
# Ranking for All These
df <- df %>%
mutate(RPL_THEMES = rank(SPL_THEMES)/length(SPL_THEMES)) %>%
mutate(RPL_THEMES = signif(RPL_THEMES, 4))
# Output data
return(df)
}
We can take a peek at the output of this function here:
svi_2020_national <- svi_theme_variables(svi_2020_national)
svi_2020_national %>% head() %>% kbl() %>% kable_styling() %>% scroll_box(width = "100%")
GEOID_2010_trt | FIPS_st | FIPS_county | FIPS_tract | state | state_name | county | region_number | region | division_number | division | E_TOTPOP_20 | E_HU_20 | E_HH_20 | E_POV150_20 | ET_POVSTATUS_20 | EP_POV150_20 | EPL_POV150_20 | E_UNEMP_20 | ET_EMPSTATUS_20 | EP_UNEMP_20 | EPL_UNEMP_20 | E_HBURD_OWN_20 | ET_HOUSINGCOST_OWN_20 | EP_HBURD_OWN_20 | EPL_HBURD_OWN_20 | E_HBURD_RENT_20 | ET_HOUSINGCOST_RENT_20 | EP_HBURD_RENT_20 | EPL_HBURD_RENT_20 | E_HBURD_20 | ET_HOUSINGCOST_20 | EP_HBURD_20 | EPL_HBURD_20 | E_NOHSDP_20 | ET_EDSTATUS_20 | EP_NOHSDP_20 | EPL_NOHSDP_20 | E_UNINSUR_20 | ET_INSURSTATUS_20 | EP_UNINSUR_20 | EPL_UNINSUR_20 | E_AGE65_20 | EP_AGE65_20 | EPL_AGE65_20 | E_AGE17_20 | EP_AGE17_20 | EPL_AGE17_20 | E_DISABL_20 | ET_DISABLSTATUS_20 | EP_DISABL_20 | EPL_DISABL_20 | E_SNGPNT_20 | ET_FAMILIES_20 | EP_SNGPNT_20 | EPL_SNGPNT_20 | E_LIMENG_20 | ET_POPAGE5UP_20 | EP_LIMENG_20 | EPL_LIMENG_20 | E_MINRTY_20 | ET_POPETHRACE_20 | EP_MINRTY_20 | EPL_MINRTY_20 | E_STRHU_20 | E_MUNIT_20 | EP_MUNIT_20 | EPL_MUNIT_20 | E_MOBILE_20 | EP_MOBILE_20 | EPL_MOBILE_20 | E_CROWD_20 | ET_OCCUPANTS_20 | EP_CROWD_20 | EPL_CROWD_20 | E_NOVEH_20 | ET_KNOWNVEH_20 | EP_NOVEH_20 | EPL_NOVEH_20 | E_GROUPQ_20 | ET_HHTYPE_20 | EP_GROUPQ_20 | EPL_GROUPQ_20 | SPL_THEME1 | RPL_THEME1 | SPL_THEME2 | RPL_THEME2 | SPL_THEME3 | RPL_THEME3 | SPL_THEME4 | RPL_THEME4 | SPL_THEMES | RPL_THEMES |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
01001020100 | 01 | 001 | 020100 | AL | Alabama | Autauga County | 3 | South Region | 6 | East South Central Division | 1941 | 710 | 693 | 352 | 1941 | 18.13498 | 0.4630 | 18 | 852 | 2.112676 | 0.15070 | 81 | 507 | 15.976331 | 0.26320 | 63 | 186 | 33.87097 | 0.2913 | 144 | 693 | 20.77922 | 0.2230 | 187 | 1309 | 14.285714 | 0.6928 | 187 | 1941 | 9.634209 | 0.6617 | 295 | 15.19835 | 0.4601 | 415 | 21.38073 | 0.4681 | 391 | 1526 | 25.62254 | 0.9011 | 58 | 555 | 10.45045 | 0.3451 | 0 | 1843 | 0.0000000 | 0.09479 | 437 | 1941 | 22.51417 | 0.3902 | 710 | 0 | 0.0000000 | 0.1079 | 88 | 12.3943662 | 0.8263 | 0 | 693 | 0.0000000 | 0.09796 | 10 | 693 | 1.443001 | 0.1643 | 0 | 1941 | 0.000000 | 0.1831 | 2.19120 | 0.4084 | 2.26919 | 0.3503 | 0.3902 | 0.3869 | 1.37956 | 0.07216 | 6.23015 | 0.2314 |
01001020200 | 01 | 001 | 020200 | AL | Alabama | Autauga County | 3 | South Region | 6 | East South Central Division | 1757 | 720 | 573 | 384 | 1511 | 25.41363 | 0.6427 | 29 | 717 | 4.044630 | 0.41320 | 33 | 392 | 8.418367 | 0.03542 | 116 | 181 | 64.08840 | 0.9086 | 149 | 573 | 26.00349 | 0.4041 | 139 | 1313 | 10.586443 | 0.5601 | 91 | 1533 | 5.936073 | 0.4343 | 284 | 16.16392 | 0.5169 | 325 | 18.49744 | 0.2851 | 164 | 1208 | 13.57616 | 0.4127 | 42 | 359 | 11.69916 | 0.3998 | 0 | 1651 | 0.0000000 | 0.09479 | 1116 | 1757 | 63.51736 | 0.7591 | 720 | 3 | 0.4166667 | 0.2470 | 5 | 0.6944444 | 0.5106 | 9 | 573 | 1.5706806 | 0.46880 | 57 | 573 | 9.947644 | 0.7317 | 212 | 1757 | 12.066022 | 0.9549 | 2.45440 | 0.4888 | 1.70929 | 0.1025 | 0.7591 | 0.7527 | 2.91300 | 0.68620 | 7.83579 | 0.4802 |
01001020300 | 01 | 001 | 020300 | AL | Alabama | Autauga County | 3 | South Region | 6 | East South Central Division | 3694 | 1464 | 1351 | 842 | 3694 | 22.79372 | 0.5833 | 53 | 1994 | 2.657974 | 0.22050 | 117 | 967 | 12.099276 | 0.11370 | 147 | 384 | 38.28125 | 0.3856 | 264 | 1351 | 19.54108 | 0.1827 | 317 | 2477 | 12.797739 | 0.6460 | 127 | 3673 | 3.457664 | 0.2308 | 464 | 12.56091 | 0.3088 | 929 | 25.14889 | 0.7080 | 473 | 2744 | 17.23761 | 0.6211 | 263 | 975 | 26.97436 | 0.8234 | 128 | 3586 | 3.5694367 | 0.70770 | 1331 | 3694 | 36.03140 | 0.5515 | 1464 | 26 | 1.7759563 | 0.3675 | 14 | 0.9562842 | 0.5389 | 35 | 1351 | 2.5906736 | 0.60550 | 42 | 1351 | 3.108808 | 0.3415 | 0 | 3694 | 0.000000 | 0.1831 | 1.86330 | 0.3063 | 3.16900 | 0.8380 | 0.5515 | 0.5468 | 2.03650 | 0.26830 | 7.62030 | 0.4460 |
01001020400 | 01 | 001 | 020400 | AL | Alabama | Autauga County | 3 | South Region | 6 | East South Central Division | 3539 | 1741 | 1636 | 503 | 3539 | 14.21305 | 0.3472 | 39 | 1658 | 2.352232 | 0.17990 | 219 | 1290 | 16.976744 | 0.30880 | 74 | 346 | 21.38728 | 0.1037 | 293 | 1636 | 17.90954 | 0.1333 | 173 | 2775 | 6.234234 | 0.3351 | 169 | 3529 | 4.788892 | 0.3448 | 969 | 27.38062 | 0.9225 | 510 | 14.41085 | 0.1208 | 670 | 3019 | 22.19278 | 0.8194 | 148 | 1137 | 13.01671 | 0.4541 | 89 | 3409 | 2.6107363 | 0.64690 | 454 | 3539 | 12.82848 | 0.2364 | 1741 | 143 | 8.2136703 | 0.6028 | 0 | 0.0000000 | 0.2186 | 10 | 1636 | 0.6112469 | 0.28340 | 72 | 1636 | 4.400978 | 0.4538 | 0 | 3539 | 0.000000 | 0.1831 | 1.34030 | 0.1575 | 2.96370 | 0.7496 | 0.2364 | 0.2344 | 1.74170 | 0.16270 | 6.28210 | 0.2389 |
01001020500 | 01 | 001 | 020500 | AL | Alabama | Autauga County | 3 | South Region | 6 | East South Central Division | 10674 | 4504 | 4424 | 1626 | 10509 | 15.47245 | 0.3851 | 81 | 5048 | 1.604596 | 0.09431 | 321 | 2299 | 13.962592 | 0.17970 | 711 | 2125 | 33.45882 | 0.2836 | 1032 | 4424 | 23.32731 | 0.3109 | 531 | 6816 | 7.790493 | 0.4251 | 301 | 10046 | 2.996217 | 0.1894 | 1613 | 15.11149 | 0.4553 | 2765 | 25.90407 | 0.7494 | 1124 | 7281 | 15.43744 | 0.5253 | 342 | 2912 | 11.74451 | 0.4019 | 52 | 9920 | 0.5241935 | 0.35230 | 2603 | 10674 | 24.38636 | 0.4160 | 4504 | 703 | 15.6083481 | 0.7378 | 29 | 0.6438721 | 0.5037 | 37 | 4424 | 0.8363472 | 0.33420 | 207 | 4424 | 4.679023 | 0.4754 | 176 | 10674 | 1.648866 | 0.7598 | 1.40481 | 0.1743 | 2.48420 | 0.4802 | 0.4160 | 0.4125 | 2.81090 | 0.63730 | 7.11591 | 0.3654 |
01001020600 | 01 | 001 | 020600 | AL | Alabama | Autauga County | 3 | South Region | 6 | East South Central Division | 3536 | 1464 | 1330 | 1279 | 3523 | 36.30429 | 0.8215 | 34 | 1223 | 2.780049 | 0.23780 | 321 | 1111 | 28.892889 | 0.75870 | 67 | 219 | 30.59361 | 0.2305 | 388 | 1330 | 29.17293 | 0.5075 | 306 | 2380 | 12.857143 | 0.6480 | 415 | 3496 | 11.870709 | 0.7535 | 547 | 15.46946 | 0.4760 | 982 | 27.77149 | 0.8327 | 729 | 2514 | 28.99761 | 0.9488 | 95 | 880 | 10.79545 | 0.3601 | 0 | 3394 | 0.0000000 | 0.09479 | 985 | 3536 | 27.85633 | 0.4608 | 1464 | 0 | 0.0000000 | 0.1079 | 364 | 24.8633880 | 0.9300 | 0 | 1330 | 0.0000000 | 0.09796 | 17 | 1330 | 1.278196 | 0.1463 | 0 | 3536 | 0.000000 | 0.1831 | 2.96830 | 0.6434 | 2.71239 | 0.6156 | 0.4608 | 0.4569 | 1.46526 | 0.08976 | 7.60675 | 0.4440 |
Once we finally have our SVI categories created, we can create our SVI flags. We will want to have two input variables for this function: the dataframe and our percentile for interest.
Specifically, we want our function to create a flag for 1 if estimated percentiles (indicated by EPL_ prefix) are greater than a particular threshold of interest (example .90 or .75) and 0 if they are not. We will then create a count of flags by theme and total count of flags across all themes.
To accomplish this we will repeat techniques from our previous functions to employ grepl/regex, for loops, and the bang-bang injection operator:
svi_theme_flags <- function(df, percentile) {
# Search column names for our estimated percentile columns
epl_cols <- colnames(df) %>% str_detect("^EPL_")
# Select these from all column names
epl_cols_names <- colnames(df)[epl_cols]
for (epl in epl_cols_names) {
eflg <- str_replace(epl, "EPL_", "F_")
df <- df %>%
mutate(!!as.name(eflg) := if_else(!!as.name(epl) > percentile, 1, 0)) %>%
relocate(c(!!as.name(eflg)),.after = !!as.name(epl))
}
# Find flags by category, sum
# Sum of Theme1 Flags: Socioeconomic Status
SES_cols <- colnames(df) %>% str_detect("F_POV|F_UNEMP|F_HBURD_[0-9]|F_NOHSDP|F_UNINSUR")
SES_select <- colnames(df)[SES_cols]
SES <- paste0(SES_select)
df2 <- df %>% select(GEOID_2010_trt, all_of(SES)) %>% mutate(F_THEME1 = rowSums(across(where(is.numeric)))) %>% select(GEOID_2010_trt, F_THEME1)
df <- left_join(df, df2, join_by("GEOID_2010_trt" == "GEOID_2010_trt")) %>%
relocate(c(F_THEME1),.after = RPL_THEME1)
# Sum of Theme2 Flags: Household Characteristics
HHchar_cols <- colnames(df) %>% str_detect("F_AGE65|F_AGE17|F_DISABL|F_SNGPNT|F_LIMENG")
HHchar_select <- colnames(df)[HHchar_cols]
HHchar <- paste0(HHchar_select)
df2 <- df %>% select(GEOID_2010_trt, all_of(HHchar)) %>% mutate(F_THEME2 = rowSums(across(where(is.numeric)))) %>% select(GEOID_2010_trt, F_THEME2)
df <- left_join(df, df2, join_by("GEOID_2010_trt" == "GEOID_2010_trt")) %>%
relocate(c(F_THEME2),.after = RPL_THEME2)
# Sum of Theme3 Flags: Household Characteristics
REM_cols <- colnames(df) %>% str_detect("F_MINRTY")
REM_select <- colnames(df)[REM_cols]
REM <- paste0(REM_select)
df2 <- df %>% select(GEOID_2010_trt, all_of(REM)) %>% mutate(F_THEME3 = rowSums(across(where(is.numeric)))) %>% select(GEOID_2010_trt, F_THEME3)
df <- left_join(df, df2, join_by("GEOID_2010_trt" == "GEOID_2010_trt")) %>%
relocate(c(F_THEME3),.after = RPL_THEME3)
# Sum of Theme4 Flags: Housing Type & Transportation
HTT_cols <- colnames(df) %>% str_detect("F_MUNIT|F_MOBILE|F_CROWD|F_NOVEH|F_GROUPQ")
HTT_select <- colnames(df)[HTT_cols]
HTT <- paste0(HTT_select)
df2 <- df %>% select(GEOID_2010_trt, all_of(HTT)) %>% mutate(F_THEME4 = rowSums(across(where(is.numeric)))) %>% select(GEOID_2010_trt, F_THEME4)
df <- left_join(df, df2, join_by("GEOID_2010_trt" == "GEOID_2010_trt")) %>%
relocate(c(F_THEME4),.after = RPL_THEME4)
# Sum of all theme flags
THEME_cols <- colnames(df) %>% str_detect("F_THEME")
THEME_select <- colnames(df)[THEME_cols]
THEME <- paste0(THEME_select)
df2 <- df %>% select(GEOID_2010_trt, all_of(THEME)) %>% mutate(F_TOTAL = rowSums(across(where(is.numeric)))) %>% select(GEOID_2010_trt, F_TOTAL)
df <- left_join(df, df2, join_by("GEOID_2010_trt" == "GEOID_2010_trt"))
# Return data
return(df)
}
GEOID_2010_trt | FIPS_st | FIPS_county | FIPS_tract | state | state_name | county | region_number | region | division_number | division | E_TOTPOP_20 | E_HU_20 | E_HH_20 | E_POV150_20 | ET_POVSTATUS_20 | EP_POV150_20 | EPL_POV150_20 | F_POV150_20 | E_UNEMP_20 | ET_EMPSTATUS_20 | EP_UNEMP_20 | EPL_UNEMP_20 | F_UNEMP_20 | E_HBURD_OWN_20 | ET_HOUSINGCOST_OWN_20 | EP_HBURD_OWN_20 | EPL_HBURD_OWN_20 | F_HBURD_OWN_20 | E_HBURD_RENT_20 | ET_HOUSINGCOST_RENT_20 | EP_HBURD_RENT_20 | EPL_HBURD_RENT_20 | F_HBURD_RENT_20 | E_HBURD_20 | ET_HOUSINGCOST_20 | EP_HBURD_20 | EPL_HBURD_20 | F_HBURD_20 | E_NOHSDP_20 | ET_EDSTATUS_20 | EP_NOHSDP_20 | EPL_NOHSDP_20 | F_NOHSDP_20 | E_UNINSUR_20 | ET_INSURSTATUS_20 | EP_UNINSUR_20 | EPL_UNINSUR_20 | F_UNINSUR_20 | E_AGE65_20 | EP_AGE65_20 | EPL_AGE65_20 | F_AGE65_20 | E_AGE17_20 | EP_AGE17_20 | EPL_AGE17_20 | F_AGE17_20 | E_DISABL_20 | ET_DISABLSTATUS_20 | EP_DISABL_20 | EPL_DISABL_20 | F_DISABL_20 | E_SNGPNT_20 | ET_FAMILIES_20 | EP_SNGPNT_20 | EPL_SNGPNT_20 | F_SNGPNT_20 | E_LIMENG_20 | ET_POPAGE5UP_20 | EP_LIMENG_20 | EPL_LIMENG_20 | F_LIMENG_20 | E_MINRTY_20 | ET_POPETHRACE_20 | EP_MINRTY_20 | EPL_MINRTY_20 | F_MINRTY_20 | E_STRHU_20 | E_MUNIT_20 | EP_MUNIT_20 | EPL_MUNIT_20 | F_MUNIT_20 | E_MOBILE_20 | EP_MOBILE_20 | EPL_MOBILE_20 | F_MOBILE_20 | E_CROWD_20 | ET_OCCUPANTS_20 | EP_CROWD_20 | EPL_CROWD_20 | F_CROWD_20 | E_NOVEH_20 | ET_KNOWNVEH_20 | EP_NOVEH_20 | EPL_NOVEH_20 | F_NOVEH_20 | E_GROUPQ_20 | ET_HHTYPE_20 | EP_GROUPQ_20 | EPL_GROUPQ_20 | F_GROUPQ_20 | SPL_THEME1 | RPL_THEME1 | F_THEME1 | SPL_THEME2 | RPL_THEME2 | F_THEME2 | SPL_THEME3 | RPL_THEME3 | F_THEME3 | SPL_THEME4 | RPL_THEME4 | F_THEME4 | SPL_THEMES | RPL_THEMES | F_TOTAL |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
48141000404 | 48 | 141 | 000404 | TX | Texas | El Paso County | 3 | South Region | 7 | West South Central Division | 3380 | 1648 | 1221 | 2390 | 3380 | 70.71006 | 0.9928 | 1 | 210 | 1268 | 16.56151 | 0.9697 | 1 | 12 | 154 | 7.792208 | 0.02796 | 0 | 705 | 1067 | 66.07310 | 0.9281 | 1 | 717 | 1221 | 58.72236 | 0.9772 | 1 | 745 | 1955 | 38.10742 | 0.9703 | 1 | 1234 | 3370 | 36.61721 | 0.9940 | 1 | 369 | 10.917160 | 0.22390 | 0 | 1070 | 31.65680 | 0.9356 | 1 | 664 | 2300 | 28.86957 | 0.9477 | 1 | 365 | 761 | 47.96321 | 0.9741 | 1 | 649 | 3025 | 21.45455 | 0.9659 | 1 | 3222 | 3380 | 95.32544 | 0.9478 | 1 | 1648 | 701 | 42.53641 | 0.9214 | 1 | 0 | 0 | 0.2186 | 0 | 130 | 1221 | 10.647011 | 0.9224 | 1 | 344 | 1221 | 28.17363 | 0.9344 | 1 | 0 | 3380 | 0.0000000 | 0.1831 | 0 | 4.9040 | 0.9886 | 5 | 4.04720 | 0.9848 | 4 | 0.9478 | 0.9398 | 1 | 3.1799 | 0.8000 | 3 | 13.07890 | 0.9859 | 13 |
06037224420 | 06 | 037 | 224420 | CA | California | Los Angeles County | 4 | West Region | 9 | Pacific Division | 2651 | 943 | 883 | 1562 | 2389 | 65.38301 | 0.9868 | 1 | 232 | 1430 | 16.22378 | 0.9672 | 1 | 13 | 57 | 22.807018 | 0.56500 | 0 | 584 | 826 | 70.70218 | 0.9614 | 1 | 597 | 883 | 67.61042 | 0.9949 | 1 | 894 | 1588 | 56.29723 | 0.9975 | 1 | 605 | 2651 | 22.82158 | 0.9514 | 1 | 243 | 9.166352 | 0.14720 | 0 | 543 | 20.48284 | 0.4073 | 0 | 211 | 1889 | 11.16993 | 0.2666 | 0 | 207 | 571 | 36.25219 | 0.9217 | 1 | 870 | 2539 | 34.26546 | 0.9937 | 1 | 2523 | 2651 | 95.17163 | 0.9465 | 1 | 943 | 540 | 57.26405 | 0.9549 | 1 | 0 | 0 | 0.2186 | 0 | 344 | 883 | 38.958097 | 0.9984 | 1 | 302 | 883 | 34.20159 | 0.9522 | 1 | 253 | 2651 | 9.5435685 | 0.9459 | 1 | 4.8978 | 0.9886 | 5 | 2.73650 | 0.6297 | 2 | 0.9465 | 0.9385 | 1 | 4.0700 | 0.9818 | 4 | 12.65080 | 0.9801 | 12 |
12086001401 | 12 | 086 | 001401 | FL | Florida | Miami-Dade County | 3 | South Region | 5 | South Atlantic Division | 6606 | 2427 | 2203 | 4080 | 6606 | 61.76203 | 0.9802 | 1 | 314 | 2673 | 11.74710 | 0.9138 | 1 | 134 | 300 | 44.666667 | 0.95870 | 1 | 1111 | 1903 | 58.38150 | 0.8314 | 0 | 1245 | 2203 | 56.51384 | 0.9682 | 1 | 1363 | 4012 | 33.97308 | 0.9551 | 1 | 1313 | 6606 | 19.87587 | 0.9252 | 1 | 732 | 11.080836 | 0.23160 | 0 | 1985 | 30.04844 | 0.9023 | 1 | 670 | 4621 | 14.49903 | 0.4697 | 0 | 606 | 1267 | 47.82952 | 0.9736 | 1 | 854 | 5756 | 14.83669 | 0.9273 | 1 | 6592 | 6606 | 99.78807 | 0.9954 | 1 | 2427 | 965 | 39.76102 | 0.9125 | 1 | 0 | 0 | 0.2186 | 0 | 378 | 2203 | 17.158420 | 0.9692 | 1 | 777 | 2203 | 35.27009 | 0.9546 | 1 | 40 | 6606 | 0.6055101 | 0.6241 | 0 | 4.7425 | 0.9867 | 5 | 3.50450 | 0.9317 | 3 | 0.9954 | 0.9870 | 1 | 3.6790 | 0.9403 | 3 | 12.92140 | 0.9845 | 12 |
27053005902 | 27 | 053 | 005902 | MN | Minnesota | Hennepin County | 2 | Midwest Region | 4 | West North Central Division | 3896 | 1173 | 1087 | 2343 | 3739 | 62.66381 | 0.9824 | 1 | 226 | 1842 | 12.26927 | 0.9232 | 1 | 21 | 71 | 29.577465 | 0.77560 | 0 | 521 | 1016 | 51.27953 | 0.6904 | 0 | 542 | 1087 | 49.86201 | 0.9223 | 1 | 719 | 1932 | 37.21532 | 0.9675 | 1 | 608 | 3896 | 15.60575 | 0.8581 | 0 | 87 | 2.233059 | 0.01142 | 0 | 1442 | 37.01232 | 0.9852 | 1 | 640 | 2440 | 26.22951 | 0.9114 | 1 | 274 | 583 | 46.99828 | 0.9714 | 1 | 444 | 3462 | 12.82496 | 0.9096 | 1 | 2911 | 3896 | 74.71766 | 0.8205 | 0 | 1173 | 721 | 61.46633 | 0.9616 | 1 | 0 | 0 | 0.2186 | 0 | 226 | 1087 | 20.791168 | 0.9809 | 1 | 323 | 1087 | 29.71481 | 0.9398 | 1 | 579 | 3896 | 14.8613963 | 0.9619 | 1 | 4.6535 | 0.9834 | 4 | 3.78902 | 0.9713 | 4 | 0.8205 | 0.8136 | 0 | 4.0628 | 0.9815 | 4 | 13.32582 | 0.9873 | 12 |
34001002400 | 34 | 001 | 002400 | NJ | New Jersey | Atlantic County | 1 | Northeast Region | 2 | Middle Atlantic Division | 2614 | 1726 | 1217 | 1579 | 2612 | 60.45176 | 0.9773 | 1 | 290 | 1171 | 24.76516 | 0.9931 | 1 | 69 | 127 | 54.330709 | 0.98500 | 1 | 538 | 1090 | 49.35780 | 0.6469 | 0 | 607 | 1217 | 49.87675 | 0.9224 | 1 | 697 | 1998 | 34.88488 | 0.9590 | 1 | 551 | 2614 | 21.07881 | 0.9374 | 1 | 516 | 19.739862 | 0.70560 | 0 | 503 | 19.24254 | 0.3280 | 0 | 576 | 2111 | 27.28565 | 0.9280 | 1 | 257 | 567 | 45.32628 | 0.9667 | 1 | 556 | 2368 | 23.47973 | 0.9732 | 1 | 2029 | 2614 | 77.62050 | 0.8359 | 0 | 1726 | 1166 | 67.55504 | 0.9693 | 1 | 0 | 0 | 0.2186 | 0 | 115 | 1217 | 9.449466 | 0.9062 | 1 | 673 | 1217 | 55.29992 | 0.9828 | 1 | 223 | 2614 | 8.5309870 | 0.9407 | 1 | 4.7892 | 0.9877 | 5 | 3.90150 | 0.9792 | 3 | 0.8359 | 0.8288 | 0 | 4.0176 | 0.9793 | 4 | 13.54420 | 0.9879 | 12 |
34039039300 | 34 | 039 | 039300 | NJ | New Jersey | Union County | 1 | Northeast Region | 2 | Middle Atlantic Division | 6145 | 1835 | 1727 | 3492 | 6096 | 57.28346 | 0.9684 | 1 | 350 | 3006 | 11.64338 | 0.9114 | 1 | 58 | 140 | 41.428571 | 0.94020 | 1 | 829 | 1587 | 52.23692 | 0.7127 | 0 | 887 | 1727 | 51.36074 | 0.9352 | 1 | 1367 | 3639 | 37.56527 | 0.9686 | 1 | 2771 | 6145 | 45.09357 | 0.9987 | 1 | 400 | 6.509357 | 0.06257 | 0 | 2006 | 32.64443 | 0.9503 | 1 | 443 | 4139 | 10.70307 | 0.2400 | 0 | 476 | 1178 | 40.40747 | 0.9470 | 1 | 1979 | 5714 | 34.63423 | 0.9941 | 1 | 5955 | 6145 | 96.90806 | 0.9624 | 1 | 1835 | 815 | 44.41417 | 0.9271 | 1 | 0 | 0 | 0.2186 | 0 | 391 | 1727 | 22.640417 | 0.9849 | 1 | 748 | 1727 | 43.31210 | 0.9692 | 1 | 114 | 6145 | 1.8551668 | 0.7766 | 0 | 4.7823 | 0.9877 | 5 | 3.19397 | 0.8468 | 3 | 0.9624 | 0.9543 | 1 | 3.8764 | 0.9680 | 3 | 12.81507 | 0.9830 | 12 |
We can now utilize our created functions to analyze our data and determine the most vulnerable areas in our dataset based on the SVI.
Before we begin our analysis, place all of your newly created functions into your project_data_steps.R file. Import them, and run code to answer questions about national data and your division of interest:
import::here( "author",
"census_division",
"fips_region_assignment",
"rank_variables",
"svi_theme_variables",
"svi_theme_flags",
# notice the use of here::here() that points to the .R file
# where all these R objects are created
.from = here::here("analysis/project_data_steps_[your initials].R"),
.character_only = TRUE)
Once you have loaded your data and processed it with your functions, answer the following questions in your RMarkdown file:
Note, remember for SVI: 0 is least vulnerable, 1 is most vulnerable
From a data science project management standpoint, how do you believe that functions are most useful? Can you think of scenarios in your current work or previous data projects where it would have been helpful to implement functions? Can you think of scenarios where functions are not the most useful strategy for processing data?
Describe the CDC SVI index. What is it and how do we intend to use it for our project? (Type your response)
Nationally, what are the most & least vulnerable tracts by THEME1, THEME2, THEME3, THEME4, OVERALL for 2020 and 2010. (Show code/data output to display your findings)
For your division, what are the most & least vulnerable tracts by THEME1, THEME2, THEME3, THEME4, OVERALL. Do they belong to certain divisions/states? (Show code/data output to display your findings)
For the most vulnerable state in your division, what are the most & least vulnerable tracts by THEME1, THEME2, THEME3, THEME4, OVERALL? Do they belong to certain counties? (Show code/data output to display your findings)
OPTIONAL CHALLENGE QUESTION: Do you think it’s possible to create a single function that calls in all of the individual functions we created? If time permits, draft an example function called load_svi_data() and show the inputs/outputs for the function.
Congratulations! You’ve reached the end of the Lab-02 Tutorial!
You are now ready to complete your lab and submit it on Canvas.
The following checklist will ensure that you’re on track: