This repository provides Julia code to replicate the preference polarization analysis from the PrefPol project. The entry point for reproducing the figures and tables of the paper is running/running.jl, which orchestrates the entire data pipeline and visualization workflow.
- Julia 1.10.10 – download from julialang.org.
- R 4.3.3 – download from CRAN.
- Required R packages:
PerMallows,haven, andMICE.install.packages(c("PerMallows", "haven", "MICE"))
Each election year is configured by a TOML file. Within each TOML file the data_file field points to the raw dataset on disk. Obtain the datasets from:
- 2006: https://www.cesop.unicamp.br/por/banco_de_dados/v/1583
- 2018: https://www.cesop.unicamp.br/por/banco_de_dados/v/4538
- 2022: https://www.cesop.unicamp.br/por/banco_de_dados/v/4680
Copy the downloaded files to a convenient location and update the data_file path in the corresponding TOML configuration.
Note: The example configuration sets the number of pseudo‑profiles to 3 for quick runs. The paper uses 1000 pseudo‑profiles.
Any extra dataset must add a preprocessing_specific function to the preprocessing_specific.jl file and a TOML configuration file at config.
-
Activate and instantiate the project
-
Execute the main script running/running.jl
I run it interactively in a text editor (emacs, vscode).
The script performs the full replication workflow:
- Resampling –
PrefPol.save_all_bootstrapsgenerates and stores pseudoprofiles (resamples) of each year. - Imputation –
PrefPol.impute_from_f3fills missing rankings using multiple imputation. - Profile generation –
PrefPol.generate_profiles_for_year_streamed_from_indexcreates preference profiles for every year/scenario combination. - Global measures –
PrefPol.save_or_load_measures_for_yearcomputes global polarization metrics for each election year (Ψ, RHHI) - Group metrics –
PrefPol.save_or_load_group_metrics_for_yearcalculates group metrics (C,D,G) - Plots –
PrefPol.plot_scenario_yearandPrefPol.plot_group_demographics_linesproduce scenario‑specific and group figures which are saved viaPrefPol.save_plot.
Certain preprocessing steps rely on R. Ensure R can find the required packages and that R is available on your system PATH before running the Julia script.
Run the unit tests with ] test in the repl.
The tests exercise the preprocessing and polarization measures modules.