sim |>group_by(confounder, exposure) |>summarise(avg_y =mean(outcome)) |>pivot_wider(names_from = exposure,values_from = avg_y, names_prefix ="x_" ) |>summarise(estimate = x_1 - x_0) |># note: we would need to weight this # if the confounder groups were not equal sizedsummarise(estimate =mean(estimate))sim |>group_by(confounder, exposure) |>summarise(avg_y =mean(outcome)) |>pivot_wider(names_from = exposure,values_from = avg_y, names_prefix ="x_" ) |>summarise(estimate = x_1 - x_0) |># note: we would need to weight this # if the confounder groups were not equal sizedsummarise(estimate =mean(estimate))