# Example 1: Using a simulated instance
simulations <- simulate_election(
num_ballots = 400,
num_candidates = 3,
num_groups = 6,
group_proportions = c(0.4, 0.1, 0.1, 0.1, 0.2, 0.1),
lambda = 0.7,
seed = 42
)
result <- get_agg_proxy(
X = simulations$X,
W = simulations$W,
sd_threshold = 0.015,
seed = 42
)
result$group_agg # c(2 6)
# This means that the resulting group aggregation is conformed by
# two macro-groups: one that has the original groups 1 and 2; and
# a second that has the original groups 3, 4, 5, and 6.
# Example 2: Using the chilean election results
data(chile_election_2021)
niebla_df <- chile_election_2021[chile_election_2021$ELECTORAL.DISTRICT == "NIEBLA", ]
# Create the X matrix with selected columns
X <- as.matrix(niebla_df[, c("C1", "C2", "C3", "C4", "C5", "C6", "C7")])
# Create the W matrix with selected columns
W <- as.matrix(niebla_df[, c(
"X18.19", "X20.29",
"X30.39", "X40.49",
"X50.59", "X60.69",
"X70.79", "X80."
)])
solution <- get_agg_proxy(
X = X, W = W,
allow_mismatch = TRUE, sd_threshold = 0.03,
sd_statistic = "average", seed = 42
)
solution$group_agg # c(3, 4, 5, 6, 8)
# This means that the resulting group aggregation consists of
# five macro-groups: one that includes the original groups 1, 2, and 3;
# three singleton groups (4, 5, and 6); and one macro-group that includes groups 7 and 8.
Run the code above in your browser using DataLab