Learn R Programming

⚠️There's a newer version (3.0.3) of this package.Take me there.

wru: Who Are You? Bayesian Prediction of Racial Category Using Surname and Geolocation

The R package implements the methods proposed in Imai, Kosuke and Kabir Khanna. (2016). ``Improving Ecological Inference by Predicting Individual Ethnicity from Voter Registration Record.'' Political Analysis, Vol. 24, No. 2 (Spring), pp. 263-272. doi: 10.1093/pan/mpw001

Using wru

To start using the package, get Census Data API Key from http://api.census.gov/data/key_signup.html

Once you have the key, you can dive right in. The package downloads relevant data on demand.

For instance, to get the race of someone with name last name Smith, write in where `---' should be replaced with the Census Data API Key you obtained:

race.pred(voters = data.frame(surname="Smith"), races = c("white", "black", "latino"), census = "tract", 
          census.key = "---", demo = TRUE, surname.only=TRUE)

which returns the predicted probabilities for each racial category:

# surname pred.whi pred.bla pred.his
# 1   Smith   0.7335   0.2222   0.0156

It is also possible to pre-download and save the census data for the intended states. For example, suppose the voters data involves people in DE, FL, NJ:

censusObj <- getCensusData("...", state = c("FL", "NJ", "DE"), demo = TRUE)         
## where ... is the census key to access the census website
race.pred(voters = data.frame(surname="Smith"), races = c("white", "black", "latino"), census = "tract", demo = TRUE, surname.only=TRUE, census.data = censusObj)

This is useful for the following reasons: (1) the machine runs race.pred may not have internet access. (2) No redundent download of the census data for each state. (3) Timely snapshots of the census data that match the voter data.

Copy Link

Version

Install

install.packages('wru')

Monthly Downloads

449

Version

0.1-1

License

GPL (>= 3)

Issues

Pull Requests

Stars

Forks

Maintainer

Kabir Khanna

Last Published

December 13th, 2016

Functions in wru (0.1-1)

getCensusData

Title return Multilevel Census Data download function.
pid

Dataset containing distribution of party registration by race.
names.all

Dataset containing Census Surname List and Spanish Surname Lists.
censusData

Census Data download function.
census.helper.api.online

Census helper function.
name.clean

Name cleaning and matching function.
census.helper.api

Census helper function.
census.helper.api.local

Census helper function.
race.pred

Race prediction function.
State.FIPS

Dataset containing FIPS codes for each state.
vecToChunk

Variable vector into chunks.
getCensusApi

Census API function.
getCensusApi2

Census API URL assembler.
voters

Dataset containing example voter file.