Skip to content

Commit

Permalink
Add multi-card analysis for challenge groups
Browse files Browse the repository at this point in the history
  • Loading branch information
wagnerlmichael committed Jan 17, 2025
1 parent cce9520 commit 5de1919
Showing 1 changed file with 89 additions and 2 deletions.
91 changes: 89 additions & 2 deletions reports/challenge_groups/challenge_groups.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ knitr:
out.width: "100%"
editor: source
params:
run_id: "2024-03-17-stupefied-maya"
year: "2024"
run_id: "2025-01-10-serene-boni"
year: "2025"
---

{{< include ../_setup.qmd >}}
Expand Down Expand Up @@ -303,3 +303,90 @@ iwalk(plots, ~ {
```

:::

## Assessed values for multi-card properties

The sales data we use to measure accuracy is the most recent sale per multi-card
pin if there was one after 2020.

```{r _}
# Grab multi-card indicator
assessment_pin <- assessment_pin %>%
left_join(
assessment_data %>%
select(meta_pin, ind_pin_is_multicard), by = "meta_pin"
)
df_filtered <- assessment_pin %>%
filter(ind_pin_is_multicard) %>%
mutate(
ratio = pred_pin_final_fmv / sale_recent_1_price
) %>%
filter(sale_recent_1_date >= as.Date("2020-01-01"))
df_filtered <- df_filtered %>%
mutate(decile = ntile(pred_pin_final_fmv, 10))
df_deciles <- df_filtered %>%
group_by(decile) %>%
summarise(median_ratio = median(ratio, na.rm = TRUE))
p_deciles <- ggplot(df_deciles, aes(x = decile, y = median_ratio)) +
geom_line() +
geom_point() +
geom_hline(yintercept = 1, color = "black", linetype = "dashed") +
scale_x_continuous(breaks = 1:10) +
labs(
title = "Median Ratio by Decile (Sales After 2020)",
x = "Decile",
y = "Median Ratio"
) +
theme_minimal()
p_deciles
```

```{r _scatterplot_pred_vs_sale}
max_val <- max(
c(df_filtered$sale_recent_1_price, df_filtered$pred_pin_final_fmv),
na.rm = TRUE
)
p_scatter_base <- plot_ly(
data = df_filtered,
x = ~sale_recent_1_price,
y = ~pred_pin_final_fmv,
type = "scatter",
mode = "markers",
hoverinfo = "text",
text = ~paste(
"<b>PIN:</b>", meta_pin,
"<br><b>Sale Price:</b>", sale_recent_1_price,
"<br><b>Predicted (Base):</b>", round(pred_pin_final_fmv, 2),
"<br><b>Sale Date:</b>", sale_recent_1_date,
"<br><b>Ratio:</b>", round(ratio, 3)
)
) %>%
plotly::layout(
title = "FMV vs sale price",
shapes = list(
list(
type = "line",
x0 = 0,
y0 = 0,
x1 = max_val,
y1 = max_val,
xref = "x",
yref = "y",
line = list(color = "red", dash = "dash")
)
),
xaxis = list(title = "Sale Price"),
yaxis = list(title = "Predicted FMV (Base)")
)
p_scatter_base
```

0 comments on commit 5de1919

Please sign in to comment.