Predict the race and gender of a name"

knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
library(predictrace)

Overview

The goal of predictrace is to predict the race of a surname or first name and the gender of a first name. This package uses U.S. Census data which says how many people of each race has a certain surname. For first name data, this package uses data from Tzioumis (2018). From this we can predict which race is mostly likely to have that surname or first name. The possible races are American Indian, Asian, Black, Hispanic, White, or two or more races. For the gender of first names, this package uses data from the United States Social Security Administration (SSA) that tells how many people of a given name are female and how many are male (no other genders are included). I use this to determine the proportion of each gender a name is, and use the gender with the higher proportion as the most likely gender for that name. Please note that the Census data on the race of first names is far smaller than the SSA data on the gender of first names, so you will match far fewer first names to race than to gender.

Full citation for the Tzioumis data: Tzioumis, Konstantinos (2018) Demographic aspects of first names, Scientific Data, 5:180025 [dx.doi.org/10.1038/sdata.2018.25].

Installation

To install this package, use the code
install.packages("predictrace")


# The development version is available on Github.
# install.packages("devtools")
devtools::install_github("jacobkap/predictrace")

Usage

library(predictrace)

Race of a surname

To get the race of a surname, the only required parameter in predict_race() is name which is the surname you want to find the race of. Please note that this parameter only accepts surnames, including both first and last name will result in not finding a match in the Census data. This function returns the name you input, the named matched through Census data, and likely race of that name, and the probability that the name is of each race.

predict_race("Washington")

This function accepts a single string or a vector of strings.

predict_race(c("Washington", "Franklin", "Lincoln"))

If you only want the most likely race and not the individual probabilities of each race, set the parameter probability to FALSE.

predict_race("Washington", probability = FALSE)

Race of a first name

To get the race of a first name, you again use predict_race() but now set the parameter surname to FALSE. This returns the exact same results as above, but now only works for first names (you may still get a match of a name if you don't set the parameter to FALSE but that is simply because some first names are also last names. The race results will likely be incorrect.).

predict_race("sarah", surname = FALSE)

This function accepts a single string or a vector of strings.

predict_race(c("sarah", "jaime", "jon", "bao"), surname = FALSE)

If you only want the most likely race and not the individual probabilities of each race, set the parameter probability to FALSE.

predict_race("sarah", probability = FALSE, surname = FALSE)

Gender of a first name

To get the gender of a first name you use the predict_gender() function and the only required parameter in predict_gender() is name which is the first name you want to find the gender of. This function returns the name you input, the named matched through SSA data, and likely gender of that name, and the probability that the name is female or male.

predict_gender("tyrion")
predict_gender(c("tyrion", "jaime", "jon", "sansa", "arya", "cersei"))

If you only want the most likely gender and not the individual probabilities of each gender, set the parameter probability to FALSE.

predict_gender(c("tyrion", "jaime", "jon", "sansa", "arya", "cersei"), probability = FALSE)

In cases where there is no match in the data, it will return NA.

predict_gender("zzztyrion")


Try the predictrace package in your browser

Any scripts or data that you put into this service are public.

predictrace documentation built on July 9, 2023, 5:48 p.m.