Skip to content

Commit

Permalink
Merge pull request #8 from cmf-uchicago/master
Browse files Browse the repository at this point in the history
close #6
  • Loading branch information
erhla authored Jul 16, 2024
2 parents dd315d2 + beb63b1 commit 7c88232
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 14 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: cmfproperty
Type: Package
Title: Property Tax Analysis
Version: 1.0.0
Version: 1.0.1
Authors@R: person("Eric", "Langowski", email = "erhlango@gmail.com",
role = c("aut", "cre"))
Description: Analyzes property assessment data through a variety of tests.
Expand Down
30 changes: 17 additions & 13 deletions R/iaao_stats.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,22 @@ cod_func <- function(df, ratio_col, bootstrap_iters) {
s <- dplyr::sample_n(data.frame(df[[ratio_col]]), n, replace = T)
generated_cods[i] <- 100 * sum(abs(s[, 1] - stats::median(s[, 1])))/(n * stats::median(s[, 1]))
}
cod_output <- c(round(mean(generated_cods, na.rm = TRUE), 4), round(stats::sd(generated_cods, na.rm = TRUE), 4))
f <- data.frame(df[[ratio_col]])
det_cod <- 100 * sum(abs(f[, 1] - stats::median(f[, 1])))/(n * stats::median(f[, 1]))
cod_output <- c(round(det_cod, 4), round(stats::sd(generated_cods, na.rm = TRUE), 4))
return(cod_output)
}

prd_func <- function(df, ratio_col, sale_price_col, bootstrap_iters) {
generated_prds <- NULL
for (i in 1:bootstrap_iters) {
df <- dplyr::sample_n(data.frame(df), nrow(df), replace = TRUE)
generated_prds[i] <- mean(df[[ratio_col]], na.rm = TRUE)/stats::weighted.mean(df[[ratio_col]], df[[sale_price_col]],
df2 <- dplyr::sample_n(data.frame(df), nrow(df), replace = TRUE)
generated_prds[i] <- mean(df2[[ratio_col]], na.rm = TRUE)/stats::weighted.mean(df2[[ratio_col]], df[[sale_price_col]],
na.rm = TRUE)
}
prd_output <- c(round(mean(generated_prds, na.rm = TRUE), 4), round(stats::sd(generated_prds, na.rm = TRUE), 4))
det_prd <- mean(df[[ratio_col]], na.rm = TRUE)/stats::weighted.mean(df[[ratio_col]], df[[sale_price_col]],
na.rm = TRUE)
prd_output <- c(round(det_prd, 4), round(stats::sd(generated_prds, na.rm = TRUE), 4))
return(prd_output)
}

Expand All @@ -33,16 +37,16 @@ prb_func <- function(df, ratio_col, assessed_value_col, sale_price_col, bootstra
}

get_stats <- function(df, bootstrap_iters) {
cod_calcs <- cod_func(df, "RATIO", bootstrap_iters)
prd_calcs <- prd_func(df, "RATIO", "SALE_PRICE", bootstrap_iters)
prb_calcs <- prb_func(df, "RATIO", "ASSESSED_VALUE", "SALE_PRICE", bootstrap_iters)
cod_calcs <- cod_func(df, "RATIO", bootstrap_iters)
prd_calcs <- prd_func(df, "RATIO", "SALE_PRICE", bootstrap_iters)
prb_calcs <- prb_func(df, "RATIO", "ASSESSED_VALUE", "SALE_PRICE", bootstrap_iters)

stats <- data.frame(N = nrow(df), COD = cod_calcs[1], COD_SE = cod_calcs[2], PRD = prd_calcs[1], PRD_SE = prd_calcs[2],
PRB = prb_calcs[1], PRB_SE = prb_calcs[2], q1_ratio = stats::quantile(df$RATIO)[[2]], median_ratio = stats::median(df$RATIO),
q3_ratio = stats::quantile(df$RATIO)[[4]], q1_sale = stats::quantile(df$SALE_PRICE)[[2]], median_sale = stats::median(df$SALE_PRICE),
q3_sale = stats::quantile(df$SALE_PRICE)[[4]], q1_assessed_value = stats::quantile(df$ASSESSED_VALUE)[[2]], median_assessed_value = stats::quantile(df$ASSESSED_VALUE)[[3]],
q3_assessed_value = stats::quantile(df$ASSESSED_VALUE)[[4]])
return(stats)
stats <- data.frame(N = nrow(df), COD = cod_calcs[1], COD_SE = cod_calcs[2], PRD = prd_calcs[1], PRD_SE = prd_calcs[2],
PRB = prb_calcs[1], PRB_SE = prb_calcs[2], q1_ratio = stats::quantile(df$RATIO)[[2]], median_ratio = stats::median(df$RATIO),
q3_ratio = stats::quantile(df$RATIO)[[4]], q1_sale = stats::quantile(df$SALE_PRICE)[[2]], median_sale = stats::median(df$SALE_PRICE),
q3_sale = stats::quantile(df$SALE_PRICE)[[4]], q1_assessed_value = stats::quantile(df$ASSESSED_VALUE)[[2]], median_assessed_value = stats::quantile(df$ASSESSED_VALUE)[[3]],
q3_assessed_value = stats::quantile(df$ASSESSED_VALUE)[[4]])
return(stats)
}


Expand Down
Binary file modified R/sysdata.rda
Binary file not shown.

0 comments on commit 7c88232

Please sign in to comment.