Home
Aug 03, 2023 R Package Open Source

D'Hondt Election Simulator: A Powerful Tool for Electoral Analysis in R

Introducing a user-friendly R package that allows political scientists and statisticians to simulate elections using the D'Hondt highest averages method.

Today, I'm excited to introduce you to my first R package: the D'Hondt simulator. It is a powerful new tool for political scientists, statisticians, and anyone interested in electoral systems. This user-friendly package allows users to simulate elections using the D'Hondt method, a highest averages method for allocating seats in party-list proportional representation.

View on GitHub

onurgitmez/dhondt

Installation

The dhondt package is available directly from GitHub and can be installed using the devtools package in R:

devtools::install_github("onurgitmez/dhondt")

Usage

Start by loading the package:

library(dhondt)

Simulating an Election

To simulate an election, you need a dataframe (data) that includes the electoral district name (district), the number of seats available in that district (seats), and the number of votes each party received (party1, party2, etc.).

Assuming the dataset is complete, you can simulate an election like this:

election_results <- simulate_election(
    data, 
    "district", 
    "seats", 
    c("party1", "party2"), 
    threshold = 0.1
)

The threshold argument specifies the national threshold required for a party to be eligible for seats. If desired, the resulting dataframe can be assigned to a global environment variable, election_results for convenient access.

Function Details

When you run the simulation using the simulate_election() function, the calculations are performed in the background using the D'Hondt method. The function accepts the following arguments:

Output

The function returns a list with two components:

This output provides both a bird's eye view and a detailed analysis of the election results, offering a comprehensive understanding of the electoral landscape.

For more information and a sample dataset shipped with the package, please visit the GitHub page linked above.