Skip to contents

This function retrieves the voting results and demographic covariates for a given electoral district from the 2021 Chilean election dataset included in this package. The function returns an eim object that can be directly used in run_em or other estimation functions.

Usage

get_eim_chile(
  elect_district = NULL,
  region = NULL,
  merge_blank_null = TRUE,
  remove_mismatch = FALSE
)

Arguments

elect_district

A string indicating the name of the electoral district to extract (e.g., "NIEBLA"). See Note.

region

A string indicating the name of the region to extract (e.g, "DE TARAPACA"). See Note.

merge_blank_null

Logical indicating whether blank and null votes should be merged into a single column. Defaults to TRUE.

remove_mismatch

Logical indicating whether to remove ballot boxes with mismatched vote totals (where MISMATCH == TRUE). Defaults to FALSE.

Value

An eim object with the following attributes:

  • X: A matrix (b x c) with the number of votes per candidate (including a column for blank + null votes if merge_blank_null = TRUE).

  • W: A matrix (b x g) with the number of voters per group (e.g., age ranges) for each ballot box.

This object can be passed to functions like run_em or get_agg_proxy for estimation and group aggregation. See Example.

Details

The function builds the X matrix using the number of votes per candidate, and the W matrix using the number of voters in each demographic group (e.g., age ranges). Optionally, blank and null votes can be merged into a single additional column (considered as another candidate).

Additionally, ballot boxes where the number of votes does not match the number of registered voters (i.e., those where MISMATCH == TRUE) can be excluded from the dataset by setting remove_mismatch = TRUE.

Note

Only one parameter is accepted among elect_district and region. If either both parameters are given, it will return an error. If neither of these two inputs is supplied, it will return an eim object with an aggregation corresponding to the whole dataset. To see all electoral districts and regions names, see the function chile_election_2021.

Examples

# Load data and create an eim object for the electoral district of "NIEBLA"
eim_obj <- get_eim_chile(elect_district = "NIEBLA", remove_mismatch = FALSE)

# Use it to run the EM algorithm
result <- run_em(eim_obj, allow_mismatch = TRUE)

# Use it with group aggregation
agg_result <- get_agg_proxy(
    object = eim_obj,
    sd_threshold = 0.03,
    allow_mismatch = TRUE,
    seed = 123
)

agg_result$group_agg
#> [1] 8