# Create synthetic voter file with typical BISG output
voter_file <- data.frame(
precinct = c(1, 1, 2, 2),
pred.whi = c(0.10, 0.20, 0.30, 0.40),
pred.bla = c(0.40, 0.30, 0.20, 0.10),
pred.his = c(0.10, 0.20, 0.30, 0.40),
pred.asi = c(0.30, 0.20, 0.10, 0.00),
pred.oth = c(0.10, 0.10, 0.10, 0.10)
)
# Function uses these column names by default
agg <- precinct_agg_combine(
voter_file = voter_file,
group_col = "precinct",
include_total = FALSE
)
# Running aggregation with a ground truth race column
voter_file <- data.frame(
precinct = c(1, 1, 1, 1, 2, 2, 2, 2),
race = c("BL", "WH", "NA", "MR", "BL", "WH", "BL", "BL")
)
# Need to specify race keys for true race column
agg <- precinct_agg_combine(
voter_file = voter_file,
group_col = "precinct",
true_race_col = "race",
true_race_keys = list("whi" = "WH", "bla" = "BL", "oth" = c("NA", "MR")),
include_total = TRUE
)
# Running aggregation for both predicted and true race columns. Note the
# change in column names, which means we need to specify column names.
voter_file <- data.frame(
precinct = c(1, 1, 2, 2),
p.whi = c(0.10, 0.20, 0.30, 0.40),
p.bla = c(0.40, 0.30, 0.20, 0.10),
p.his = c(0.10, 0.20, 0.30, 0.40),
p.asi = c(0.30, 0.20, 0.10, 0.00),
p.oth = c(0.10, 0.10, 0.10, 0.10),
race = c("BL", "WH", "BL", "WH")
)
agg <- precinct_agg_combine(
voter_file = voter_file,
group_col = "precinct",
race_cols = c("p.whi", "p.bla", "p.his", "p.asi", "p.oth"),
true_race_col = "race",
true_race_keys = list("whi" = "WH", "bla" = "BL"),
include_total = FALSE
)
Run the code above in your browser using DataLab