Learn R Programming

fastei (version 0.0.0.12)

get_eim_chile: Extracts voting and demographic data matrices for a given electoral district in Chile.

Description

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,
  use_sex = 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.

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.

use_sex

Logical indicating whether to use the sex from the voters instead of the age ranges. Defaults to FALSE.

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.

See Also

chile_election_2021

Examples

Run this code
# 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.05,
    allow_mismatch = TRUE,
    seed = 123
)

agg_result$group_agg

Run the code above in your browser using DataLab