census_helper {wru} | R Documentation |
Census helper function.
Description
census_helper
links user-input dataset with Census geographic data.
Usage
census_helper(
key,
voter.file,
states = "all",
geo = "tract",
age = FALSE,
sex = FALSE,
census.data = NA,
retry = 0
)
Arguments
key |
A required character object. Must contain user's Census API
key, which can be requested here.
|
voter.file |
An object of class data.frame . Must contain field(s) named
county , tract , block , and/or place
specifying geolocation. These should be character variables that match up with
U.S. Census categories. County should be three characters (e.g., "031" not "31"),
tract should be six characters, and block should be four characters.
Place should be five characters if it is included.
|
states |
A character vector specifying which states to extract
Census data for, e.g. c("NJ", "NY") . Default is "all" , which extracts
Census data for all states contained in user-input data.
|
geo |
A character object specifying what aggregation level to use.
Use "county" , "tract" , or "block" . Default is "tract" .
Warning: extracting block-level data takes very long.
|
age |
A TRUE /FALSE object indicating whether to condition on
age or not. If FALSE (default), function will return Pr(Geolocation | Race).
If TRUE , function will return Pr(Geolocation, Age | Race).
If sex is also TRUE , function will return Pr(Geolocation, Age, Sex | Race).
|
sex |
A TRUE /FALSE object indicating whether to condition on
sex or not. If FALSE (default), function will return Pr(Geolocation | Race).
If TRUE , function will return Pr(Geolocation, Sex | Race).
If age is also TRUE , function will return Pr(Geolocation, Age, Sex | Race).
|
census.data |
A optional census object of class list containing
pre-saved Census geographic data. Can be created using get_census_data function.
If census.data is provided, the age element must have the same value
as the age option specified in this function (i.e., TRUE in both or
FALSE in both). Similarly, the sex element in the object provided in
census.data must have the same value as the sex option here.
If census.data is missing, Census geographic data will be obtained via Census API.
|
retry |
The number of retries at the census website if network interruption occurs.
|
Details
This function allows users to link their geocoded dataset (e.g., voter file)
with U.S. Census 2010 data. The function extracts Census Summary File data
at the county, tract, or block level using the 'UScensus2010' package. Census data
calculated are Pr(Geolocation | Race) where geolocation is county, tract, or block.
Value
Output will be an object of class data.frame
. It will
consist of the original user-input data with additional columns of
Census data.
Examples
## Not run: census_helper(key = "...", voter.file = voters, states = "nj", geo = "block")
## Not run: census_helper(key = "...", voter.file = voters, states = "all", geo = "tract",
age = TRUE, sex = TRUE)
## End(Not run)
[Package
wru version 0.1-12
Index]