Skip to contents

Function to compute the allocated seats according to the chosen method for a given electoral districts.

Usage

seat_allocation(
  candidacies,
  ballots,
  blank_ballots,
  n_seats,
  method = "hondt",
  threshold = 0.03,
  short_version = TRUE
)

Arguments

candidacies

A vector containing one of the following variable: unique codes or abbreviations of the candidacies that participated in the election.

ballots

A vector containing the absolute number of ballots (integer positive values) received by each candidacies

blank_ballots

A numerical value indicating the number of blank ballots (integer positive values).

n_seats

An integer positive value indicating the number of seats that are going to distributed for a given electoral district.

method

A string vector providing the methods of apportionment to be used. The allowed values are the following: "D'Hondt" (or "Hondt" or "hondt"), "Hamilton" (or "hamilton" or "Vinton" or "vinton"), "Webster" (or "webster" or "Sainte-Lague" or "sainte-lague"), "Hill" (or "hill" or "Huntington-Hill" or "huntington-hill"), "Dean" (or "dean") or "Adams" (or "adams") or "Hagenbach-Bischoff" (or "hagenbach") (or "bischoff") or "First Past the Post" (or "first") (or "fptp"). Defaults to "Hondt".

threshold

A numerical value (between 0 and 1) indicating the minimal percentage of ballots needed to obtain representation for a given electoral district. Defaults to 0.03.

short_version

Flag to indicate whether it should be returned a short version of the data (just key variables) or not. Defaults to TRUE.

Value

A tibble with rows corresponding to each party including the following variables:

candidacies

abbrev or id of the candidacies

seats

number of seats

method

method to allocate seats

ballots

absolute number of ballots, just in long format

porc_ballots

percentage of ballots respect to party ballots (including blank ballots), just in long format

quotient_x

intermediate quotients of the allocation process

Details

The purpose of this function is to calculate the allocation of seats for a given electoral district (and given a particular election) for a set of apportionment methods.

Author

David Pereiro-Pol, Irene Bosque-Gala and Javier Alvarez-Liebana.

Examples


## Correct examples

# Seats distribution with Hill method for given vectors of
# candidacies and ballots without the remainder quotients
candidacies <- c("PP", "PSOE", "PODEMOS", "VOX")
ballots <- c(200, 350, 100, 200)
seats <- seat_allocation(method = "hill", candidacies = candidacies,
                        ballots = ballots, blank_ballots = 50,
                        n_seats = 15, threshold = 0.03)

# Same results in a long version (providing quotients)
seats <- seat_allocation(method = "hill", candidacies = candidacies,
                        ballots = ballots, blank_ballots = 50,
                        n_seats = 15, threshold = 0.03, short_version = FALSE)

# Adams with threshold 0.05
seats <- seat_allocation(method = "adams",candidacies, ballots,
                        blank_ballots = 50, n_seats = 5, threshold = 0.05)

# A very high threshold that only one party meets in Dean method
seats <- seat_allocation(method = "dean",candidacies, ballots,
                        blank_ballots = 50, n_seats = 5, threshold = 0.3)

if (FALSE) { # \dontrun{

# ----
# Incorrect examples
# ----

# Different length of candidacies and ballots

candidacies <- c("PP", "PSOE", "PODEMOS", "VOX")
ballots <- c(200, 350, 100)

seats <- seat_allocation(method = "hill", candidacies = candidacies,
ballots = ballots, blank_ballots = 50, threshold = 0.03)

 # Ballots with missing values
candidacies <- c("PP", "PSOE", "PODEMOS")
ballots <- c(200, 350, NA)
seats <- seat_allocation(method = "hagenbach", candidacies = candidacies,
ballots = ballots, blank_ballots = 50)

# Ballots with char values
candidacies <- c("PP", "PSOE", "PODEMOS")
ballots <- c("200", "350", "100")
seats <- seat_allocation(method = "hamilton", candidacies = candidacies,
ballots = ballots, blank_ballots = 50)

# Threshold should be a numerical value between 0 and 1
candidacies <- c("PP", "PSOE", "PODEMOS")
ballots <- c(200, 350, 100)
seats <- seat_allocation(method = "webster", candidacies = candidacies,
ballots = ballots, blank_ballots = 50, threshold = 3)

} # }