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

calculate regressivity stats #3

Open
claireboyd opened this issue Apr 9, 2024 · 0 comments
Open

calculate regressivity stats #3

claireboyd opened this issue Apr 9, 2024 · 0 comments

Comments

@claireboyd
Copy link
Collaborator

calculate PRB, COD, PRD at the county, city level if we are able to run the geospatial join

code snippet

#' #' @param data dataframe of data
#' #' @param assessment_value_col string of assessment_value_col name
#' #' @param sale_price_col string of sale_price_col name
#' #' @return dataframe 
#' gen_iaao_stats <- function(data, assessment_value_col, sale_price_col) { 
#'   df_iaao <- data %>% 
#'     rename_at(vars(c(assessment_value_col, sale_price_col)), function(x) c('assessment_value','sale_price')) %>% 
#'     mutate(av_ratio = assessment_value/sale_price,
#'            log2 = log(2),
#'            count = 1) %>%
#'     mutate(cod = 100 * sum(abs(av_ratio - stats::median(av_ratio)))/(n() * stats::median(av_ratio)),
#'            prd = mean(av_ratio, na.rm = TRUE)/stats::weighted.mean(av_ratio, sale_price, na.rm = TRUE),
#'            prb_value = 0.50 * (assessment_value/median(av_ratio)) + 0.50 * sale_price,
#'            prb_ln_value = log(prb_value)/log(2),
#'            prb_pct_diff = (av_ratio - median(av_ratio))/median(av_ratio)
#'     )
#'   prb_model <- linear_reg() %>% 
#'     fit(prb_pct_diff ~ prb_ln_value,  data = df_iaao) %>%
#'     tidy(., conf.int = TRUE) 
#'   iaao_out <- list('cod' = c(unique(df_iaao$cod)) ,
#'                    'prd' = c(unique(df_iaao$prd)) ,
#'                    'prb' = c(prb_model %>% filter(term == 'prb_ln_value') %>% select(estimate) %>% distinct() %>% pull())) %>%
#'     as.data.frame()
#'   return(iaao_out)
#' }
#' 
#' test <- gen_iaao_stats(data = data_input, assessment_value_col = 'assessed_value', sale_price_col = 'sale_price')
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

1 participant