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:
To run the project, you first need to install the required packages
pip install -r requirements.txt
- 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.
- 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
.
- To generate the figures, run the script
python figures.py
which will create a folder new_figures
containing all the figures.
- 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.
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.
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.
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.
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.
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.
-
Runtime can be an issue for
Simulation.run()
. To run the simulation (with parametersnumber_of_communities = 10 ** 5
andnumber_of_voting_simulations = 10 ** 5
), we used a virtual machine with 16 cores and 64 GB RAM, which took approximately 5 days to finish. -
Runtime can also be a minor issue for two scripts in the folder
generate_figures
, which are also included in the scriptfigures.py
. We ran these scripts on a basic laptop (2 cores 8 GB RAM).- The script
figure_accuracy_homophily.py
) takes approximately 10 minutes (with parametersnumber_of_communities=200
andnumber_of_voting_simulations=200
). - The script
figure_distribution_in_degree.py
takes approximately 20 minutes to finish (for 10**5 communities).
- The script
This repository accompanies an academic paper (under review). In the meantime, please cite as follows:
Released under the MIT licence.