Retrieve census data and calculate SVI for one or multiple year(s)/state(s)
Source:R/find_svi.R
find_svi.Rd
find_svi()
is like a wrapper for get_census_data()
and
get_svi()
that retrieves census data and produces SVI for one or
multiple years(s) and state(s). For multiple year-state entries, SVI is
obtained from percentile rankings for each entry and summarised into one
table. Note that a Census API key is required for this function to work,
which can be obtained at https://api.census.gov/data/key_signup.html and
set up using tidycensus::census_api_key()
.
Arguments
- year
A vector containing years of interest (available 2012-2022). Length >=1. Acting as pairs with
state
,year
should be of the same length asstate
. The exception is when it's a single year entry (length 1), other than providing one state of interest, supplystate = NULL
as default orstate = 'US'
retrieves and processes nation level data to obtain SVI.- state
A vector containing states of interest. Length >=0. Length 0 (
state = NULL
), orstate = 'US'
must be used with single year argument, when SVI is calculated from nation-level census data. In other cases,state
must have the same elements asyear
(same length).- geography
One geography level of interest for all year-state combination (e.g."county", "zcta", "tract").
- key
Your Census API key. Obtain one at https://api.census.gov/data/key_signup.html. To set up, use
tidycensus::census_api_key("YOUR KEY GOES HERE")
, or include it as an argument.- full.table
Default as
FALSE
, returning SVI table with only "GEOID", and SVI for each theme and all themes. If set asTRUE
, a full SVI table with individual SVI variables and intermediate ranking calculations are also included in addition to the theme-related SVIs (similar style to tables from CDC/ATSDR database).
Value
A tibble of summarised SVI for one or multiple year-state combination(s)
of interest. Rows represent the geographic units, and columns represent its
SVI for each theme and all themes. Additional two columns at the end
indicate the corresponding state and year information. For full.table = TRUE
, estimated count and percentage values for individual SVI variables
are also included. For description of variable names (column names), please
refer to CDC/ATSDR documentation.
Examples
if (FALSE) { # Sys.getenv("CENSUS_API_KEY") != ""
# Census API key required
# For one year-state entry
find_svi(
year = 2019,
state = "AZ",
geography = "county"
)
# For multiple year-state pairs
## All ZCTAs for 2017-AZ; 2017-DE; and 2018-DC
year <- c(2017, 2017, 2018)
state <- c("AZ", "DE", "DC")
info <- data.frame(year, state)
find_svi(
year = info$year,
state = info$state,
geography = "zcta"
)
}