knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "README-" )
The package saipeAPI
provides an R client for Census Bureau's API for Small Area Income and Poverty Estimates (SAIPE). Here is a short introduction for the SAIPE program from Census:
The Small Area Income and Poverty Estimates (SAIPE) program produces single-year estimates of median household income and poverty for states and all counties, as well as population and poverty estimates for school districts. Since SAIPE estimates combine ACS data with administrative and other data, SAIPE estimates generally have lower variance than ACS estimates but are released later because they incorporate ACS data in the models. For counties and school districts, particularly those with populations below 65,000, the SAIPE program provides the most accurate subnational estimates of poverty. For counties, SAIPE generally provides the best single-year estimates of median household income.
# install.packages("remotes") remotes::install_github("jjchern/saipeAPI@v0.0.3")
saipeAPI
have three functions that return SAIPE data at different geographic level:
saipeAPI::saipe_us() saipeAPI::saipe_state() saipeAPI::saipe_county()
Census's SAIPE has four levels of income and poverty estimates: us, state, county, and school district.
library(dplyr, warn.conflicts = FALSE) saipeAPI::saipe_vars %>% select(Name, Label) %>% knitr::kable()
Obtain an API key from the U.S. Census Bureau at http://api.census.gov/data/key_signup.html. After that, set your API key with the function saipeAPI::set_api_key()
, and then start calling the data retrieval functions.
You can also save your API key in the .Renviron
file for future usage. First, open the .Renviron
file by
# install.packages("usethis") usethis::edit_r_environ()
Save your key in the file in the format of
saipe_key='<Your API Key Here>'
Reload the .Renviron
file and check if the key can be assessed:
readRenviron("~/.Renviron") Sys.getenv("saipe_key")
# saipe::set_api_key("<Your API Key Here>") saipeAPI::saipe_us(year = 2010:2017, var = c("NAME", "SAEMHI_PT", "SAEPOVRTALL_PT"))
# saipe::set_api_key("<Your API Key Here>") saipeAPI::saipe_state(year = 2010:2017, var = c("NAME", "SAEMHI_PT", "SAEPOVRTALL_PT"))
# saipe::set_api_key("<Your API Key Here>") saipeAPI::saipe_county(year = 2017, var = c("NAME", "SAEMHI_PT", "SAEPOVRTALL_PT"))
# The pacakge contains a data frame that shows possible variables and variable labels saipeAPI::saipe_vars # To get a vector of all possible variables saipeAPI::saipe_vars$Name # To get a vector of all possible years saipeAPI::saipe_years # Use the above two vectors to download all the US-level data saipeAPI::saipe_us(year = saipeAPI::saipe_years, var = saipeAPI::saipe_vars$Name)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.