Skip to content

Commit

Permalink
Merge pull request #152 from kosukeimai/bugfix
Browse files Browse the repository at this point in the history
Fix issue #151
  • Loading branch information
1beb authored May 24, 2024
2 parents a53fce3 + 87bdc47 commit 7a938b8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
6 changes: 3 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Package: wru
Title: Who are You? Bayesian Prediction of Racial Category Using Surname,
First Name, Middle Name, and Geolocation
Version: 3.0.2
Date: 2024-04-04
Version: 3.0.3
Date: 2024-05-24
Authors@R: c(
person("Kabir", "Khanna", , "[email protected]", role = "aut"),
person("Brandon", "Bertelsen", , "[email protected]", role = c("aut", "cre")),
Expand Down Expand Up @@ -55,4 +55,4 @@ LazyData: yes
LazyDataCompression: xz
LazyLoad: yes
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.2.3
RoxygenNote: 7.3.1
14 changes: 6 additions & 8 deletions R/race_prediction_funs.R
Original file line number Diff line number Diff line change
Expand Up @@ -415,16 +415,14 @@ predict_race_new <- function(
}
}

## Normalize (recycle marginal)
preds <- preds/rowSums(preds)
## Revert to Pr(Race|Surname) for missing predictions
if(impute.missing){
miss_ind <- !is.finite(preds$c_whi_last)
if(any(miss_ind)){
preds[miss_ind,] <- voter.file[miss_ind, grep("_last$", names(voter.file))] *
matrix(race.margin, nrow=nrow(voter.file[miss_ind,]), ncol=length(race.margin), byrow = TRUE)
}
for(i in ncol(preds)){
preds[, i] <- dplyr::coalesce(preds[, i], race.margin[i])
}
}
## Normalize (recycle marginal)
preds <- preds/rowSums(preds)
## Revert to national Pr(Race) for missing predictions
colnames(preds) <- paste("pred", eth, sep = ".")

return(data.frame(cbind(voter.file[c(vars.orig)], preds)))
Expand Down

0 comments on commit 7a938b8

Please sign in to comment.