diff --git a/DESCRIPTION b/DESCRIPTION index bcadc74..42a23bb 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -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", , "kabirkhanna@gmail.com", role = "aut"), person("Brandon", "Bertelsen", , "brandon@bertelsen.ca", role = c("aut", "cre")), @@ -55,4 +55,4 @@ LazyData: yes LazyDataCompression: xz LazyLoad: yes Roxygen: list(markdown = TRUE) -RoxygenNote: 7.2.3 +RoxygenNote: 7.3.1 diff --git a/R/race_prediction_funs.R b/R/race_prediction_funs.R index f883336..77ff933 100644 --- a/R/race_prediction_funs.R +++ b/R/race_prediction_funs.R @@ -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)))