class: center middle main-title section-title-1 # Evaluating your propensity score model .class-info[ **Session 14** .light[STA 379/679: Causal Inference <br> Lucy D'Agostino McGowan ] ] --- class: title title-1 # Checking balance .box-1.medium[Love Plots] -- .box-1.medium[eCDF plots] --- class: title title-1 # Standardized Mean Difference (SMD) `$$\LARGE d = \frac{\bar{z}_{exposed}-\bar{z}_{unexposed}}{\sqrt{\frac{s^2_{exposed}+s^2_{unexposed}}{2}}}$$` -- <br> .box-1[Rule of thumb: SMD < 0.1] --- class: title title-1 # Customer satisfaction data .small[ ```r library(tidyverse) library(broom) glm(satisfied_customer_service ~ income + married + n_kids + has_pets + age + education + gender + former_customer_service + previous_spend, family = binomial(), data = customer_satisfaction) %>% augment(data = customer_satisfaction, type.predict = "response") %>% mutate(atm_wts = pmin(.fitted, 1 - .fitted) / (satisfied_customer_service * .fitted + (1 - satisfied_customer_service) * (1 - .fitted)) ) -> customer_satisfaction ``` ] --- class: title title-1 # Customer satisfaction data .small[ ```r library(tidyverse) library(broom) glm(satisfied_customer_service ~ income + married + n_kids + has_pets + age + education + gender + former_customer_service + previous_spend, family = binomial(), data = customer_satisfaction) %>% augment(data = customer_satisfaction, type.predict = "response") %>% mutate(atm_wts = pmin(.fitted, 1 - .fitted) / (satisfied_customer_service * .fitted + (1 - satisfied_customer_service) * (1 - .fitted)) ) -> customer_satisfaction ``` ] .box-1[Which confounders did I identify?] --- class: title title-1 # Customer satisfaction data .small[ ```r library(tidyverse) library(broom) *glm(satisfied_customer_service ~ income + married + n_kids + has_pets + age + * education + gender + former_customer_service + previous_spend, family = binomial(), data = customer_satisfaction) %>% augment(data = customer_satisfaction, type.predict = "response") %>% mutate(atm_wts = pmin(.fitted, 1 - .fitted) / (satisfied_customer_service * .fitted + (1 - satisfied_customer_service) * (1 - .fitted)) ) -> customer_satisfaction ``` ] --- class: title title-1 # Customer satisfaction data .small[ ```r library(tidyverse) library(broom) glm(satisfied_customer_service ~ income + married + n_kids + has_pets + age + education + gender + former_customer_service + previous_spend, family = binomial(), data = customer_satisfaction) %>% augment(data = customer_satisfaction, type.predict = "response") %>% mutate(atm_wts = pmin(.fitted, 1 - .fitted) / (satisfied_customer_service * .fitted + (1 - satisfied_customer_service) * (1 - .fitted)) ) -> customer_satisfaction ``` ] .box-1[What estimand am I interested in?] --- class: title title-1 # Customer satisfaction data .small[ ```r library(tidyverse) library(broom) glm(satisfied_customer_service ~ income + married + n_kids + has_pets + age + education + gender + former_customer_service + previous_spend, family = binomial(), data = customer_satisfaction) %>% augment(data = customer_satisfaction, type.predict = "response") %>% * mutate(atm_wts = pmin(.fitted, 1 - .fitted) / * (satisfied_customer_service * .fitted + * (1 - satisfied_customer_service) * (1 - .fitted)) ) -> customer_satisfaction ``` ] .box-1[What estimand am I interested in?] --- class: title title-1 # SMD in R ```r library(smd) library(tidyverse) df %>% # w is optional summarise(smd = smd(confounder_1, exposure, w = wts)$estimate) ``` --- class: title title-1 # SMD in R .small[ ```r library(smd) library(tidyverse) customer_satisfaction %>% # w is optional summarize(smd = smd(income, satisfied_customer_service, w = atm_wts)$estimate) ``` ``` ## # A tibble: 1 × 1 ## smd ## <dbl> ## 1 0.0297 ``` ] --- class: title title-1 # SMD in R ```r smds <- df %>% summarise( across( c(confounder_1, confounder_2, ...), list( unweighted = ~smd(.x, exposure)$estimate, weighted = ~smd(.x, exposure, wts)$estimate ) ) ) ``` --- class: title title-1 # SMD in R ```r smds <- df %>% summarise( across( * c(confounder_1, confounder_2, ...), list( unweighted = ~smd(.x, exposure)$estimate, weighted = ~smd(.x, exposure, wts)$estimate ) ) ) ``` --- class: title title-1 # SMD in R ```r smds <- df %>% summarise( across( c(confounder_1, confounder_2, ...), list( * unweighted = ~smd(.x, exposure)$estimate, * weighted = ~smd(.x, exposure, wts)$estimate ) ) ) ``` --- class: title title-1 # SMD in R .small[ ```r smds <- customer_satisfaction %>% summarise( across( c(income, married, n_kids, has_pets, age, education, gender, former_customer_service, previous_spend), list( unweighted = ~smd(.x, satisfied_customer_service)$estimate, weighted = ~smd(.x, satisfied_customer_service, atm_wts)$estimate ) ) ) ``` ] --- class: title title-1 #
Application Exercise .box-1[Go to our Github organization and open `appex-10`] .box-1[Fit a propensity score model for `satisfied_customer_service` (you can use the one you chose for Lab 2)] .box-1[Calculate the `ate` and `ato` weights] .box-1[Calculate the standardized mean differences (unweighted, `ate` weighted and `ato` weighted) for all of the variables (excluding the outcome, `next_spend`)] .box-1[Knit, commit, push to GitHub]
10
:
00
--- class: title title-1 # SMD in R .small[ ```r smds ``` ``` ## # A tibble: 1 × 18 ## income_unweighted income_weighted married_unweighted married_weighted ## <dbl> <dbl> <dbl> <dbl> ## 1 0.0168 0.0297 0.0357 0.0350 ## # … with 14 more variables: n_kids_unweighted <dbl>, n_kids_weighted <dbl>, ## # has_pets_unweighted <dbl>, has_pets_weighted <dbl>, age_unweighted <dbl>, ## # age_weighted <dbl>, education_unweighted <dbl>, education_weighted <dbl>, ## # gender_unweighted <dbl>, gender_weighted <dbl>, ## # former_customer_service_unweighted <dbl>, ## # former_customer_service_weighted <dbl>, previous_spend_unweighted <dbl>, ## # previous_spend_weighted <dbl> ``` ] --- class: title title-1 # SMD in R ```r plot_df <- smds %>% pivot_longer( everything(), values_to = "SMD", names_to = c("variable", "Method"), names_pattern = "(.*)_(.*)" ) ``` --- class: title title-1 # SMD in R ```r plot_df <- smds %>% * pivot_longer( everything(), values_to = "SMD", names_to = c("variable", "Method"), names_pattern = "(.*)_(.*)" ) ``` --- class: title title-1 # SMD in R ```r plot_df <- smds %>% pivot_longer( * everything(), values_to = "SMD", names_to = c("variable", "Method"), names_pattern = "(.*)_(.*)" ) ``` --- class: title title-1 # SMD in R ```r plot_df <- smds %>% pivot_longer( everything(), * values_to = "SMD", names_to = c("variable", "Method"), names_pattern = "(.*)_(.*)" ) ``` --- class: title title-1 # SMD in R ```r plot_df <- smds %>% pivot_longer( everything(), values_to = "SMD", * names_to = c("variable", "Method"), * names_pattern = "(.*)_(.*)" ) ``` --- class: title title-1 # SMD in R ```r plot_df <- smds %>% pivot_longer( everything(), values_to = "SMD", names_to = c("variable", "Method"), names_pattern = "(.*)_(.*)" ) %>% arrange(Method, abs(SMD)) %>% mutate(variable = fct_inorder(variable)) ``` --- class: title title-1 # SMD in R .small[ ```r plot_df ``` ``` ## # A tibble: 18 × 3 ## variable Method SMD ## <fct> <chr> <dbl> ## 1 gender unweighted 0.0161 ## 2 income unweighted 0.0168 ## 3 has_pets unweighted -0.0285 ## 4 married unweighted 0.0357 ## 5 former_customer_service unweighted 0.0616 ## 6 n_kids unweighted -0.203 ## 7 age unweighted 0.340 ## 8 education unweighted -0.664 ## 9 previous_spend unweighted -1.02 ## 10 education weighted 0.00000476 ## 11 former_customer_service weighted 0.00869 ## 12 previous_spend weighted 0.0138 ## 13 gender weighted 0.0148 ## 14 age weighted 0.0194 ## 15 has_pets weighted 0.0221 ## 16 n_kids weighted 0.0226 ## 17 income weighted 0.0297 ## 18 married weighted 0.0350 ``` ] --- class: title title-1 # Love Plot .left-code[ ```r ggplot( data = plot_df, aes(x = abs(SMD), y = variable, group = Method, color = Method) ) + geom_line(orientation = "y") + geom_point() + geom_vline(xintercept = 0.1, color = "black", size = 0.1) ``` ] --- class: title title-1 # Love Plot .left-code[ ```r ggplot( data = plot_df, * aes(x = abs(SMD), y = variable, * group = Method, color = Method) ) + geom_line(orientation = "y") + geom_point() + geom_vline(xintercept = 0.1, color = "black", size = 0.1) ``` ] --- class: title title-1 # Love Plot .left-code[ ```r ggplot( data = plot_df, aes(x = abs(SMD), y = variable, group = Method, color = Method) ) + * geom_line(orientation = "y") + geom_point() + geom_vline(xintercept = 0.1, color = "black", size = 0.1) ``` ] --- class: title title-1 # Love Plot .left-code[ ```r ggplot( data = plot_df, aes(x = abs(SMD), y = variable, group = Method, color = Method) ) + geom_line(orientation = "y") + * geom_point() + geom_vline(xintercept = 0.1, color = "black", size = 0.1) ``` ] --- class: title title-1 # Love Plot .left-code[ ```r ggplot( data = plot_df, aes(x = abs(SMD), y = variable, group = Method, color = Method) ) + geom_line(orientation = "y") + geom_point() + * geom_vline(xintercept = 0.1, * color = "black", size = 0.1) ``` ] --- class: title title-1 # Love Plot .left-code[ ```r ggplot( data = plot_df, aes(x = abs(SMD), y = variable, group = Method, color = Method) ) + geom_line(orientation = "y") + geom_point() + geom_vline(xintercept = 0.1, color = "black", size = 0.1) ``` ] .right-plot[ <img src="14-evaluating-propensity-score_files/figure-html/unnamed-chunk-27-1.png" width="504" style="display: block; margin: auto;" /> ] --- class: title title-1 #
Application Exercise .box-1[Pivot your standardized mean difference output to make it plot-able] .box-1[Arrange your data frame by method and (absolute) standardized mean difference] .box-1[Create a Love Plot of your standardized mean differences] .box-1[Knit, commit, push to GitHub]
10
:
00
--- class: title title-1 # Compare Matching .small[ ```r library(MatchIt) matched_smds <- matchit(satisfied_customer_service ~ income + married + n_kids + has_pets + age + education + gender + former_customer_service + previous_spend, data = customer_satisfaction, caliper = 0.5) %>% get_matches() %>% summarise( across( c(income, married, n_kids, has_pets, age, education, gender, former_customer_service, previous_spend), list( matched = ~smd(.x, satisfied_customer_service)$estimate ) ) ) ``` ] --- class: title title-1 # Compare Matching .small[ ```r *library(MatchIt) matched_smds <- matchit(satisfied_customer_service ~ income + married + n_kids + has_pets + age + education + gender + former_customer_service + previous_spend, data = customer_satisfaction, caliper = 0.5) %>% get_matches() %>% summarise( across( c(income, married, n_kids, has_pets, age, education, gender, former_customer_service, previous_spend), list( matched = ~smd(.x, satisfied_customer_service)$estimate ) ) ) ``` ] --- class: title title-1 # Compare Matching .small[ ```r library(MatchIt) *matched_smds <- matchit(satisfied_customer_service ~ income + married + * n_kids + has_pets + age + education + gender + * former_customer_service + previous_spend, data = customer_satisfaction, caliper = 0.5) %>% get_matches() %>% summarise( across( c(income, married, n_kids, has_pets, age, education, gender, former_customer_service, previous_spend), list( matched = ~smd(.x, satisfied_customer_service)$estimate ) ) ) ``` ] --- class: title title-1 # Compare Matching .small[ ```r library(MatchIt) matched_smds <- matchit(satisfied_customer_service ~ income + married + n_kids + has_pets + age + education + gender + former_customer_service + previous_spend, * data = customer_satisfaction, caliper = 0.5) %>% get_matches() %>% summarise( across( c(income, married, n_kids, has_pets, age, education, gender, former_customer_service, previous_spend), list( matched = ~smd(.x, satisfied_customer_service)$estimate ) ) ) ``` ] --- class: title title-1 # Compare Matching .small[ ```r library(MatchIt) matched_smds <- matchit(satisfied_customer_service ~ income + married + n_kids + has_pets + age + education + gender + former_customer_service + previous_spend, data = customer_satisfaction, caliper = 0.5) %>% * get_matches() %>% summarise( across( c(income, married, n_kids, has_pets, age, education, gender, former_customer_service, previous_spend), list( matched = ~smd(.x, satisfied_customer_service)$estimate ) ) ) ``` ] --- class: title title-1 # Compare Matching .small[ ```r library(MatchIt) matched_smds <- matchit(satisfied_customer_service ~ income + married + n_kids + has_pets + age + education + gender + former_customer_service + previous_spend, data = customer_satisfaction, caliper = 0.5) %>% get_matches() %>% * summarise( * across( * c(income, married, n_kids, has_pets, age, * education, gender, former_customer_service, previous_spend), * list( * matched = ~smd(.x, satisfied_customer_service)$estimate * ) * ) * ) ``` ] --- class: title title-1 # Compare Matching .small[ ```r matched_smds ``` ``` ## income_matched married_matched n_kids_matched has_pets_matched age_matched ## 1 0.03624997 0.006514001 -0.1074924 0.04472136 0.1654134 ## education_matched gender_matched former_customer_service_matched ## 1 -0.2177035 0.0959927 0.02060323 ## previous_spend_matched ## 1 -0.4016459 ``` ] --- class: title title-1 # Compare Matching ```r plot_df_all <- matched_smds %>% pivot_longer( everything(), values_to = "SMD", names_to = c("variable", "Method"), names_pattern = "(.*)_(.*)" ) %>% bind_rows(plot_df) ``` --- class: title title-1 # Compare Matching ```r *plot_df_all <- matched_smds %>% pivot_longer( everything(), values_to = "SMD", names_to = c("variable", "Method"), names_pattern = "(.*)_(.*)" ) %>% bind_rows(plot_df) ``` --- class: title title-1 # Compare Matching ```r plot_df_all <- matched_smds %>% * pivot_longer( * everything(), * values_to = "SMD", * names_to = c("variable", "Method"), * names_pattern = "(.*)_(.*)" ) %>% bind_rows(plot_df) ``` --- class: title title-1 # Compare Matching ```r plot_df_all <- matched_smds %>% pivot_longer( everything(), values_to = "SMD", names_to = c("variable", "Method"), names_pattern = "(.*)_(.*)" ) %>% * bind_rows(plot_df) ``` --- class: title title-1 # Compare Matching ```r plot_df_all <- matched_smds %>% pivot_longer( everything(), values_to = "SMD", names_to = c("variable", "Method"), names_pattern = "(.*)_(.*)" ) %>% bind_rows(plot_df) %>% arrange(Method, abs(SMD)) %>% mutate(variable = fct_inorder(variable)) ``` --- class: title title-1 # Love Plot .left-code[ ```r ggplot( data = plot_df_all, aes(x = abs(SMD), y = variable, group = Method, color = Method) ) + geom_line(orientation = "y") + geom_point() + geom_vline(xintercept = 0.1, color = "black", size = 0.1) ``` ] .right-plot[ <img src="14-evaluating-propensity-score_files/figure-html/unnamed-chunk-41-1.png" width="504" style="display: block; margin: auto;" /> ] --- class: title title-1 # What if we changed the caliper? .small[ ```r matched_smds <- matchit(satisfied_customer_service ~ income + married + n_kids + has_pets + age + education + gender + former_customer_service + previous_spend, data = customer_satisfaction, caliper = 0.01) %>% get_matches() %>% summarise( across( c(income, married, n_kids, has_pets, age, education, gender, former_customer_service, previous_spend), list( matched.calp.01 = ~smd(.x, satisfied_customer_service)$estimate ) ) ) ``` ] --- class: title title-1 # Love Plot .left-code[ ```r ggplot( data = plot_df_all, aes(x = abs(SMD), y = variable, group = Method, color = Method) ) + geom_line(orientation = "y") + geom_point() + geom_vline(xintercept = 0.1, color = "black", size = 0.1) ``` ] .right-plot[ <img src="14-evaluating-propensity-score_files/figure-html/unnamed-chunk-45-1.png" width="504" style="display: block; margin: auto;" /> ] --- class: title title-1 # ECDF For continuous variables, it can be helpful to look at the _whole_ distribution pre and post-weighting rather than a single summary measure <img src="14-evaluating-propensity-score_files/figure-html/unnamed-chunk-46-1.png" width="504" style="display: block; margin: auto;" /> --- class: title title-1 # Unweighted ECDF .small[ ```r ggplot(customer_satisfaction, aes(x = previous_spend, group = satisfied_customer_service, color = factor(satisfied_customer_service))) + stat_ecdf() + scale_color_manual("Satisfied with Customer Service", values = c("#5154B8", "#5DB854"), labels = c("No", "Yes")) + scale_x_continuous("Previous spending", label = scales::dollar) + ylab("Proportion <= x") ``` ] --- class: title title-1 # Unweighted ECDF .small[ ```r *ggplot(customer_satisfaction, * aes(x = previous_spend, group = satisfied_customer_service, * color = factor(satisfied_customer_service))) + stat_ecdf() + scale_color_manual("Satisfied with Customer Service", values = c("#5154B8", "#5DB854"), labels = c("No", "Yes")) + scale_x_continuous("Previous spending", label = scales::dollar) + ylab("Proportion <= x") ``` ] --- class: title title-1 # Unweighted ECDF .small[ ```r ggplot(customer_satisfaction, aes(x = previous_spend, group = satisfied_customer_service, color = factor(satisfied_customer_service))) + * stat_ecdf() + scale_color_manual("Satisfied with Customer Service", values = c("#5154B8", "#5DB854"), labels = c("No", "Yes")) + scale_x_continuous("Previous spending", label = scales::dollar) + ylab("Proportion <= x") ``` ] --- class: title title-1 # Unweighted ECDF .small[ ```r ggplot(customer_satisfaction, aes(x = previous_spend, group = satisfied_customer_service, color = factor(satisfied_customer_service))) + stat_ecdf() + * scale_color_manual("Satisfied with Customer Service", * values = c("#5154B8", "#5DB854"), * labels = c("No", "Yes")) + scale_x_continuous("Previous spending", label = scales::dollar) + ylab("Proportion <= x") ``` ] --- class: title title-1 # Unweighted ECDF .small[ ```r ggplot(customer_satisfaction, aes(x = previous_spend, group = satisfied_customer_service, color = factor(satisfied_customer_service))) + stat_ecdf() + scale_color_manual("Satisfied with Customer Service", values = c("#5154B8", "#5DB854"), labels = c("No", "Yes")) + * scale_x_continuous("Previous spending", label = scales::dollar) + ylab("Proportion <= x") ``` ] --- class: title title-1 # Unweighted ECDF .small[ ```r ggplot(customer_satisfaction, aes(x = previous_spend, group = satisfied_customer_service, color = factor(satisfied_customer_service))) + stat_ecdf() + scale_color_manual("Satisfied with Customer Service", values = c("#5154B8", "#5DB854"), labels = c("No", "Yes")) + scale_x_continuous("Previous spending", label = scales::dollar) + * ylab("Proportion <= x") ``` ] --- class: title title-1 #
Application Exercise .box-1[Create an unweighted eCDF looking at `age`] .box-1[Knit, commit, push to GitHub]
06
:
00
--- class: title title-1 # Weighted ECDF .small[ <img src="14-evaluating-propensity-score_files/figure-html/unnamed-chunk-53-1.png" width="504" style="display: block; margin: auto;" /> ] --- class: title title-1 # Weighted ECDF .small[ ```r ecdf_1 <- customer_satisfaction %>% filter(satisfied_customer_service == 1) %>% arrange(previous_spend) %>% mutate(cum_pct = cumsum(atm_wts) / sum(atm_wts)) ecdf_0 <- customer_satisfaction %>% filter(satisfied_customer_service == 0) %>% arrange(previous_spend) %>% mutate(cum_pct = cumsum(atm_wts) / sum(atm_wts)) ggplot(ecdf_1, aes(x = previous_spend, y = cum_pct)) + geom_line(color = "#5DB854") + geom_line(data = ecdf_0, aes(x = previous_spend, y = cum_pct), color = "#5154B8") + xlab("Previous spending") + ylab("Proportion <= x") ``` ] --- class: title title-1 # Weighted ECDF .small[ ```r ecdf_1 <- customer_satisfaction %>% * filter(satisfied_customer_service == 1) %>% arrange(previous_spend) %>% mutate(cum_pct = cumsum(atm_wts) / sum(atm_wts)) ecdf_0 <- customer_satisfaction %>% filter(satisfied_customer_service == 0) %>% arrange(previous_spend) %>% mutate(cum_pct = cumsum(atm_wts) / sum(atm_wts)) ggplot(ecdf_1, aes(x = previous_spend, y = cum_pct)) + geom_line(color = "#5DB854") + geom_line(data = ecdf_0, aes(x = previous_spend, y = cum_pct), color = "#5154B8") + xlab("Previous spending") + ylab("Proportion <= x") ``` ] --- class: title title-1 # Weighted ECDF .small[ ```r ecdf_1 <- customer_satisfaction %>% filter(satisfied_customer_service == 1) %>% * arrange(previous_spend) %>% mutate(cum_pct = cumsum(atm_wts) / sum(atm_wts)) ecdf_0 <- customer_satisfaction %>% filter(satisfied_customer_service == 0) %>% arrange(previous_spend) %>% mutate(cum_pct = cumsum(atm_wts) / sum(atm_wts)) ggplot(ecdf_1, aes(x = previous_spend, y = cum_pct)) + geom_line(color = "#5DB854") + geom_line(data = ecdf_0, aes(x = previous_spend, y = cum_pct), color = "#5154B8") + xlab("Previous spending") + ylab("Proportion <= x") ``` ] --- class: title title-1 # Weighted ECDF .small[ ```r ecdf_1 <- customer_satisfaction %>% filter(satisfied_customer_service == 1) %>% arrange(previous_spend) %>% * mutate(cum_pct = cumsum(atm_wts) / sum(atm_wts)) ecdf_0 <- customer_satisfaction %>% filter(satisfied_customer_service == 0) %>% arrange(previous_spend) %>% mutate(cum_pct = cumsum(atm_wts) / sum(atm_wts)) ggplot(ecdf_1, aes(x = previous_spend, y = cum_pct)) + geom_line(color = "#5DB854") + geom_line(data = ecdf_0, aes(x = previous_spend, y = cum_pct), color = "#5154B8") + xlab("Previous spending") + ylab("Proportion <= x") ``` ] --- class: title title-1 # Weighted ECDF .small[ ```r ecdf_1 <- customer_satisfaction %>% filter(satisfied_customer_service == 1) %>% arrange(previous_spend) %>% mutate(cum_pct = cumsum(atm_wts) / sum(atm_wts)) *ecdf_0 <- customer_satisfaction %>% * filter(satisfied_customer_service == 0) %>% * arrange(previous_spend) %>% * mutate(cum_pct = cumsum(atm_wts) / sum(atm_wts)) ggplot(ecdf_1, aes(x = previous_spend, y = cum_pct)) + geom_line(color = "#5DB854") + geom_line(data = ecdf_0, aes(x = previous_spend, y = cum_pct), color = "#5154B8") + xlab("Previous spending") + ylab("Proportion <= x") ``` ] --- class: title title-1 # Weighted ECDF .small[ ```r ecdf_1 <- customer_satisfaction %>% filter(satisfied_customer_service == 1) %>% arrange(previous_spend) %>% mutate(cum_pct = cumsum(atm_wts) / sum(atm_wts)) ecdf_0 <- customer_satisfaction %>% filter(satisfied_customer_service == 0) %>% arrange(previous_spend) %>% mutate(cum_pct = cumsum(atm_wts) / sum(atm_wts)) *ggplot(ecdf_1, aes(x = previous_spend, y = cum_pct)) + geom_line(color = "#5DB854") + geom_line(data = ecdf_0, aes(x = previous_spend, y = cum_pct), color = "#5154B8") + xlab("Previous spending") + ylab("Proportion <= x") ``` ] --- class: title title-1 # Weighted ECDF .small[ ```r ecdf_1 <- customer_satisfaction %>% filter(satisfied_customer_service == 1) %>% arrange(previous_spend) %>% mutate(cum_pct = cumsum(atm_wts) / sum(atm_wts)) ecdf_0 <- customer_satisfaction %>% filter(satisfied_customer_service == 0) %>% arrange(previous_spend) %>% mutate(cum_pct = cumsum(atm_wts) / sum(atm_wts)) ggplot(ecdf_1, aes(x = previous_spend, y = cum_pct)) + * geom_line(color = "#5DB854") + geom_line(data = ecdf_0, aes(x = previous_spend, y = cum_pct), color = "#5154B8") + xlab("Previous spending") + ylab("Proportion <= x") ``` ] --- class: title title-1 # Weighted ECDF .small[ ```r ecdf_1 <- customer_satisfaction %>% filter(satisfied_customer_service == 1) %>% arrange(previous_spend) %>% mutate(cum_pct = cumsum(atm_wts) / sum(atm_wts)) ecdf_0 <- customer_satisfaction %>% filter(satisfied_customer_service == 0) %>% arrange(previous_spend) %>% mutate(cum_pct = cumsum(atm_wts) / sum(atm_wts)) ggplot(ecdf_1, aes(x = previous_spend, y = cum_pct)) + geom_line(color = "#5DB854") + * geom_line(data = ecdf_0, * aes(x = previous_spend, y = cum_pct), * color = "#5154B8") + xlab("Previous spending") + ylab("Proportion <= x") ``` ] --- class: title title-1 #
Application Exercise .box-1[Create an weighted eCDF looking at `age` with the `ate` weights] .box-1[Create an weighted eCDF looking at `age` with the `ato` weights] .box-1[Knit, commit, push to GitHub]
06
:
00
--- class: title title-1 # Iterate on your propensity score model! .box-1.medium[Decrease your caliper if doing matching] -- .box-1.medium[Allow for more degrees of freedom for variables that look imbalanced] -- .box-inv-1.medium[Polynomial terms // splines] --- class: title title-1 # Iterate on your propensity score model .box-1[`previous_spend` modeled as a 3rd degree polynomial] .small[ ```r glm(satisfied_customer_service ~ income + married + n_kids + has_pets + age + education + gender + former_customer_service + poly(previous_spend, 3), family = binomial(), data = customer_satisfaction) %>% augment(data = customer_satisfaction, type.predict = "response") %>% mutate(atm_wts = pmin(.fitted, 1 - .fitted) / (satisfied_customer_service * .fitted + (1 - satisfied_customer_service) * (1 - .fitted)) ) -> customer_satisfaction ``` ] --- class: title title-1 # Iterate on your propensity score model .box-1[`previous_spend` modeled as a 3rd degree polynomial] .small[ ```r glm(satisfied_customer_service ~ income + married + n_kids + has_pets + age + education + gender + former_customer_service + * poly(previous_spend, 3), family = binomial(), data = customer_satisfaction) %>% augment(data = customer_satisfaction, type.predict = "response") %>% mutate(atm_wts = pmin(.fitted, 1 - .fitted) / (satisfied_customer_service * .fitted + (1 - satisfied_customer_service) * (1 - .fitted)) ) -> customer_satisfaction ``` ] --- class: title title-1 # Iterate on your propensity score model .box-1.small[`previous_spend` modeled as a 3rd degree polynomial] <img src="14-evaluating-propensity-score_files/figure-html/unnamed-chunk-64-1.png" width="504" style="display: block; margin: auto;" /> --- class: title title-1 # Iterate on your propensity score model .box-1.small[`previous_spend` modeled as a 3rd degree polynomial] <img src="14-evaluating-propensity-score_files/figure-html/unnamed-chunk-65-1.png" width="504" style="display: block; margin: auto;" /> --- class: title title-1 # Iterate on your propensity score model .box-1[`previous_spend` modeled as a natural spline with 3 degrees of freedom] .small[ ```r glm(satisfied_customer_service ~ income + married + n_kids + has_pets + age + education + gender + former_customer_service + splines::ns(previous_spend, 3), family = binomial(), data = customer_satisfaction) %>% augment(data = customer_satisfaction, type.predict = "response") %>% mutate(atm_wts = pmin(.fitted, 1 - .fitted) / (satisfied_customer_service * .fitted + (1 - satisfied_customer_service) * (1 - .fitted)) ) -> customer_satisfaction ``` ] --- class: title title-1 # Iterate on your propensity score model .box-1.small[`previous_spend` modeled as a natural spline with 3 degrees of freedom] .small[ ```r glm(satisfied_customer_service ~ income + married + n_kids + has_pets + age + education + gender + former_customer_service + * splines::ns(previous_spend, 3), family = binomial(), data = customer_satisfaction) %>% augment(data = customer_satisfaction, type.predict = "response") %>% mutate(atm_wts = pmin(.fitted, 1 - .fitted) / (satisfied_customer_service * .fitted + (1 - satisfied_customer_service) * (1 - .fitted)) ) -> customer_satisfaction ``` ] --- class: title title-1 # Iterate on your propensity score model .box-1.small[`previous_spend` modeled as a natural spline with 3 degrees of freedom] <img src="14-evaluating-propensity-score_files/figure-html/unnamed-chunk-68-1.png" width="504" style="display: block; margin: auto;" /> --- class: title title-1 # Iterate on your propensity score model .box-1[`previous_spend` modeled as a natural spline with 3 degrees of freedom] <img src="14-evaluating-propensity-score_files/figure-html/unnamed-chunk-69-1.png" width="504" style="display: block; margin: auto;" /> --- class: title title-1 # Iterate on your propensity score model .box-1.small[`previous_spend` modeled as a natural spline with 8 degrees of freedom] .small[ ```r glm(satisfied_customer_service ~ income + married + n_kids + has_pets + age + education + gender + former_customer_service + * splines::ns(previous_spend, 8), family = binomial(), data = customer_satisfaction) %>% augment(data = customer_satisfaction, type.predict = "response") %>% mutate(atm_wts = pmin(.fitted, 1 - .fitted) / (satisfied_customer_service * .fitted + (1 - satisfied_customer_service) * (1 - .fitted)) ) -> customer_satisfaction ``` ] --- class: title title-1 # Iterate on your propensity score model .box-1.small[`previous_spend` modeled as a natural spline with 8 degrees of freedom] <img src="14-evaluating-propensity-score_files/figure-html/unnamed-chunk-71-1.png" width="504" style="display: block; margin: auto;" /> --- class: title title-1 # Iterate on your propensity score model .box-1[`previous_spend` modeled as a natural spline with 8 degrees of freedom] <img src="14-evaluating-propensity-score_files/figure-html/unnamed-chunk-72-1.png" width="504" style="display: block; margin: auto;" /> --- class: title title-1 #
Application Exercise .box-1[Update your propensity score model to include at least one natural spline] .box-1[Recreate your Love Plot and eCDF plots to examine how (whether) this impacts your results] .box-1[Knit, commit, push to GitHub]
10
:
00