From 60b35cc7555256e1105a03becdefbdb64b7432b7 Mon Sep 17 00:00:00 2001 From: Hunter Mills Date: Wed, 30 Apr 2025 12:29:38 -0700 Subject: [PATCH 1/2] Change population weighted quantile method --- R/powell_wiley.R | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/R/powell_wiley.R b/R/powell_wiley.R index d6b6da6..8dde152 100644 --- a/R/powell_wiley.R +++ b/R/powell_wiley.R @@ -49,10 +49,11 @@ #' @import dplyr #' @importFrom MASS ginv #' @importFrom psych alpha principal -#' @importFrom stats complete.cases cor cov2cor loadings median promax quantile sd +#' @importFrom stats complete.cases cor cov2cor loadings median promax sd #' @importFrom stringr str_trim #' @importFrom tidycensus get_acs #' @importFrom tidyr pivot_longer separate +#' @importFrom wtd quantile #' @export #' #' @seealso \code{\link[tidycensus]{get_acs}} for additional arguments for geographic referent selection (i.e., \code{state} and \code{county}). @@ -346,9 +347,10 @@ powell_wiley <- function(geo = 'tract', NDIQuint <- ndi_data_NDI %>% dplyr::mutate( NDIQuint = cut( - NDI * log(TotalPop), - breaks = stats::quantile( - NDI * log(TotalPop), + NDI, + breaks = wtd::quantile( + NDI, + weights = TotalPop, probs = c(0, 0.2, 0.4, 0.6, 0.8, 1), na.rm = TRUE ), From 20db652f10399b4bb8be1036b658cb43efdc6e43 Mon Sep 17 00:00:00 2001 From: Hunter Mills Date: Wed, 30 Apr 2025 12:52:20 -0700 Subject: [PATCH 2/2] fixed import statement --- R/powell_wiley.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/R/powell_wiley.R b/R/powell_wiley.R index 8dde152..8c8ad06 100644 --- a/R/powell_wiley.R +++ b/R/powell_wiley.R @@ -53,7 +53,7 @@ #' @importFrom stringr str_trim #' @importFrom tidycensus get_acs #' @importFrom tidyr pivot_longer separate -#' @importFrom wtd quantile +#' @importFrom Hmisc wtd.quantile #' @export #' #' @seealso \code{\link[tidycensus]{get_acs}} for additional arguments for geographic referent selection (i.e., \code{state} and \code{county}). @@ -348,7 +348,7 @@ powell_wiley <- function(geo = 'tract', dplyr::mutate( NDIQuint = cut( NDI, - breaks = wtd::quantile( + breaks = Hmisc::wtd.quantile( NDI, weights = TotalPop, probs = c(0, 0.2, 0.4, 0.6, 0.8, 1),