Skip to content

Commit

Permalink
Fix missing geography_id value for triads (#299)
Browse files Browse the repository at this point in the history
* Fix missing geography_id value for triads

* Fix styler issue
  • Loading branch information
dfsnow authored Dec 20, 2024
1 parent 0ac3b70 commit 8050822
Showing 1 changed file with 21 additions and 11 deletions.
32 changes: 21 additions & 11 deletions pipeline/03-evaluate.R
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,23 @@ assessment_data_pin <- read_parquet(paths$output$assessment_pin$local) %>%
pred_pin_final_fmv_round, sale_ratio_study_price
)

# Helper function to return NA when sale sample size is too small
gte_n <- \(n_sales, min_n, fn, na_type) {
if (sum(!is.na(n_sales)) >= min_n) {
return(fn)
} else {
return(na_type)
}
}

# Helper function to add triad code as geography ID if it's not already present
add_triad_code <- \(data) {
if (!"geography_id" %in% colnames(data)) {
data$geography_id <- data$triad_code
}
return(data)
}




Expand All @@ -73,15 +90,6 @@ assessment_data_pin <- read_parquet(paths$output$assessment_pin$local) %>%
gen_agg_stats <- function(data, truth, estimate, bldg_sqft,
rsn_col, rsf_col, triad, geography,
class, col_dict, min_n) {
# Helper function to return NA when sale sample size is too small
gte_n <- \(n_sales, min_n, fn, na_type) {
if (sum(!is.na(n_sales)) >= min_n) {
return(fn)
} else {
return(na_type)
}
}

# List of summary stat/performance functions applied within summarize() below
# Each function is listed on the right while the name of the function is on
# the left
Expand Down Expand Up @@ -239,7 +247,8 @@ gen_agg_stats <- function(data, truth, estimate, bldg_sqft,
mutate(across(
-(contains("_max") & contains("yoy")) & where(is.numeric),
~ replace(.x, !is.finite(.x), NA)
))
)) %>%
add_triad_code()
}


Expand Down Expand Up @@ -299,7 +308,8 @@ gen_agg_stats_quantile <- function(data, truth, estimate,
mutate(across(
-(contains("_max") & contains("yoy")) & where(is.numeric),
~ replace(.x, !is.finite(.x), NA)
))
)) %>%
add_triad_code()
}


Expand Down

0 comments on commit 8050822

Please sign in to comment.