Skip to content
12 changes: 8 additions & 4 deletions provisional-ratio-curves/provisional-ratio-curves.R
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,17 @@ walk(unique(all_ratios$township_name), \(x) {
filter(township_name == x) %>%
select(-township_name) %>%
mutate(
price_decile = ntile(sale_price, 10),
price_decile = ntile(
if_else(sale_excluded %in% TRUE, NA_real_, sale_price),
10
),
model_sale_ratio = model_value / sale_price,
desk_review_sale_ratio = desk_review_value / sale_price
)

# Summarize ratios and price ranges by decile for .xlsx output
output$`Ratio Deciles` <- output$`All Parcels` %>%
filter(!is.na(sale_price)) %>%
filter(!is.na(sale_price), !sale_excluded) %>%
summarize(
model_ratio = median(model_sale_ratio),
model_cod = assessr::cod(model_sale_ratio),
Expand All @@ -114,7 +117,7 @@ walk(unique(all_ratios$township_name), \(x) {

# Calculate vertical equity metrics for .xlsx output
output$`Town-Level Stats` <- output$`All Parcels` %>%
filter(!is.na(sale_price)) %>%
filter(!is.na(sale_price), !sale_excluded) %>%
summarize(
model_ratio = median(model_sale_ratio),
model_cod = assessr::cod(model_sale_ratio),
Expand Down Expand Up @@ -153,7 +156,7 @@ walk(unique(all_ratios$township_name), \(x) {

# Build x-axis labels with abbreviated price ranges per decile
axis_labels <- output$`All Parcels` %>%
filter(!is.na(`Sale Price`)) %>%
filter(!is.na(`Sale Price`), !`Sale Excluded`) %>%
summarize(
min_price = min(`Sale Price`),
max_price = max(`Sale Price`),
Expand Down Expand Up @@ -229,6 +232,7 @@ walk(unique(all_ratios$township_name), \(x) {
select(town_nbhd, geometry)

map_data <- output$`All Parcels` %>%
filter(!isTRUE(`Sale Excluded`)) %>%
select(
`Neighborhood Number`,
`Model Sale Ratio`,
Expand Down