# Example 1: Create an eim object from a JSON file
if (FALSE) {
model1 <- eim(json_path = "path/to/file.json")
}
# Example 2: Use simulate_election with optional parameters, then create an eim object
# from matrices
# Simulate data for 500 ballot boxes, 4 candidates and 5 groups
sim_result <- simulate_election(
num_ballots = 500,
num_candidates = 3,
num_groups = 5,
group_proportions = c(0.2, 0.2, 0.4, 0.1, 0.1)
)
model2 <- eim(X = sim_result$X, W = sim_result$W)
# Example 3: Create an object from a user defined matrix with 8 ballot boxes,
# 2 candidates and 7 groups.
x_mat <- matrix(c(
57, 90,
60, 84,
43, 102,
72, 71,
63, 94,
52, 80,
60, 72,
54, 77
), nrow = 8, ncol = 2, byrow = TRUE)
w_mat <- matrix(c(
10, 15, 25, 21, 10, 40, 26,
11, 21, 37, 32, 8, 23, 12,
17, 12, 43, 27, 12, 19, 15,
20, 18, 25, 15, 22, 17, 26,
21, 19, 27, 16, 23, 22, 29,
18, 16, 20, 14, 19, 22, 23,
10, 15, 21, 18, 20, 16, 32,
12, 17, 19, 22, 15, 18, 28
), nrow = 8, ncol = 7, byrow = TRUE)
model3 <- eim(X = x_mat, W = w_mat)
Run the code above in your browser using DataLab