Skip to content

I use an agent-based model to explore the impact of imperfect competence and social influence on majority voting. This repository contains the code for an agent-based model and simulations of majority voting, for producing some figures, and for a statistical analysis.

License

HeinDuijf/MajorityVotingCollectiveAccuracy

Repository files navigation

Majoritarian Accuracy of Majority Voting

DOI

This repository is associated with the paper titled "Is majority voting in the best interest of the majority?" (under review). The paper investigates the majoritarian accuracy of majority voting: which refers to the probability that it succeeds in selecting the alternative that is in the best interest of the majority. I use an agent-based model to explore the impact of imperfect competence and social influence on majority voting. The agents are placed on influence networks that are generated in a natural way, without the assumption that powerful minorities manipulate the network structure. Surprisingly, in these circumstances, there is a considerable risk that majority voting fails to track the majority’s interests. Moreover, my statistical analysis suggests that the competences of the minority and the majority and the proportional influence of the minority are strong predictors, while, surprisingly, the relative size of the minority is not.

This repository contains the code for the agent-based model and simulations, for producing some figures, and for the statistical analysis. To get a feel for the agent-based model, click the picture below:

A picture of an example of an agent-based model

1. Setup

To run the project, you first need to install the required packages

pip install -r requirements.txt

2. Simulation

  1. To get a feel for the agent-based model, you can check out the jupyter notebook, which includes some network visualizations, by either opening the pages or by running
jupyter-notebook NotebookWalkthrough.ipynb

Running the notebook will create several html files in the folder www with visualizations of agent-based models.

  1. To run the simulations and generate the data, run the script
python main.py

which will create a csv file data/clean.csv, a collection of communities in the folder data/communities, and a README file with the parameter settings for the simulation in data/README.csv.

  1. To generate the figures, run the script
python figures.py

which will create a folder new_figures containing all the figures.

  1. To run the statistical analysis, run the script
python statistics.py

which will create several csv files in the folder stats with the results of the statistical analysis.

3. Organization of the project

The agent-based model: community.py

The central class Community is defined in community.py. A Community is an agent-based model consisting of a network of agents, and it can be used to compute the estimated accuracy of a given community. The networks are generated with homophilic and preferential attachment.

Jupyter notebook: NotebookWalkthrough.ipynb

The jupyter notebook walks you through the stages of the agent-based model Community using some network visualizations. To minimize the amount of code in the notebook, some scripts are stored in scripts/notebook.py, which is run in one of the initial notebook cells.

Simulations: simulation.py

The central class Simulation and method Simulation.run() is defined in simulation.py, the method produces the csv file data/clean.csv. The method Simulation.run() runs a simulation consisting of generating number_of_communities communities and estimating the accuracy of each community by running number_of_voting_simulations voting simulations.

Figures: figures.py

The script figures.py creates a folder new_figures containing all the figures. The folder generate_figures contains the scripts that generate figures. Each script in that folder is associated with one of the figures.

Statistical analysis: statistics.py

The script statistics.py runs the statistical analysis that generates several csv files in the folder stats. The folder stats contains scripts that generate the csv files. Each script in that folder is associated with one of the csv files.

4. Runtime limitations

  1. Runtime can be an issue for Simulation.run(). To run the simulation (with parameters number_of_communities = 10 ** 5 and number_of_voting_simulations = 10 ** 5), we used a virtual machine with 16 cores and 64 GB RAM, which took approximately 5 days to finish.

  2. Runtime can also be a minor issue for two scripts in the folder generate_figures, which are also included in the script figures.py. We ran these scripts on a basic laptop (2 cores 8 GB RAM).

    1. The script figure_accuracy_homophily.py) takes approximately 10 minutes (with parameters number_of_communities=200 and number_of_voting_simulations=200).
    2. The script figure_distribution_in_degree.py takes approximately 20 minutes to finish (for 10**5 communities).

5. Licence and citation

This repository accompanies an academic paper (under review). In the meantime, please cite as follows:

Cite the code: DOI

Released under the MIT licence.

About

I use an agent-based model to explore the impact of imperfect competence and social influence on majority voting. This repository contains the code for an agent-based model and simulations of majority voting, for producing some figures, and for a statistical analysis.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published