Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle NAs in randomNames()'s gender argument #56

Closed
msenn opened this issue Aug 22, 2018 · 3 comments
Closed

Handle NAs in randomNames()'s gender argument #56

msenn opened this issue Aug 22, 2018 · 3 comments

Comments

@msenn
Copy link

msenn commented Aug 22, 2018

When calling randomNames(gender = g) on a gender vector that contains NAs, the generated names do no longer represent gender correctly:

# Define gender vector
> (g <- rep(0:1, each = 3))
[1] 0 0 0 1 1 1

# Gender is correctly represented
> randomNames::randomNames(gender = g, which.names = "first")
[1] "Samuel"   "Carlos"   "Theodore" "Emlynn"   "Briana"   "Deborah" 

# Include NA in gender vector
> g[3] <- NA
> randomNames::randomNames(gender = g, which.names = "first")
[1] "Maleeha" "Sean"    "Sad"     "Sang"    "Labeeba" "Carter" 

# First gender is 0 (male)
> g[1]
[1] 0

# "Maleeha" is not among any mal first names list
> fn_male <- grep("^first.*g0$", names(randomNames::randomNamesData))
> sapply(fn_male, function(i)  "Maleeha" %in% names(randomNames::randomNamesData[[
+     names(randomNames::randomNamesData)[i]
+     ]])
+ )
[1] FALSE FALSE FALSE FALSE FALSE FALSE
@dbetebenner
Copy link
Member

Thanks for seeing that. I've fixed that up. Let me know if there's anything else. Version 1.3-0.0 is the new version. Available on GitHub now and will post to CRAN shortly and hopefully available there in a day or two.

@msenn
Copy link
Author

msenn commented Aug 30, 2018

Thanks, Damian, for looking into this. As far as I can tell, the non-NA genders are now populated correctly.

May I ask what behavior you've chosen for the cases where gender is NA? I can think of multiple options that seem sensible:

  • Return NA in the name vector
  • Random draw a name from the names tables (without considering gender)
  • Random draw a gender from the non-missing elements of the gender vector

Possibly, the information on the chosen behavior could be included in the documentation of the function.

@dbetebenner
Copy link
Member

Good idea (to include in documentation).

Current it just randomly samples a gender/ethnicity and replaces the NA with that. https://github.com/CenterForAssessment/randomNames/blob/master/R/randomNames.R#L61-L62

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants