rstan code for fitting the models from Valence in a statistical mechanics of voting.
To setup the code, first install rstan
install.packages("rstan", repos = "https://cloud.r-project.org/", dependencies = TRUE)
Then import the necessary functions
library(rstan)
source("fitting_fns.r")
To reproduce model fits from the paper, run in bash
Rscript run_all_fits.r
or from within the R-terminal
source('run_all_fits.r')
For any specific data set, one can run
S = read.csv('myData.csv', header=FALSE)
fit_all_models(S, "myData")
where myData.csv
is a csv of +/-1's and each row corresponds to a different case and
"myData" is the name of the models. The model parameters are saved into CSV files into the
out
directory.
The data synthetic.csv
is generated from the model without interactions, and so the
model evidence (correctly) picks model 1. We also provide the voting data for the
Second Rehnquist Court and the Roberts Court as rehnquist1607.csv
and
roberts1709.csv
for reproduction. The corresponding justice initials are in
rehnquist1607_initials.txt
and roberts1709_initials.txt
. These have been taken from the
SCDB Version 01 from 2022 and the four digit suffix is the
natural court identifier.
Individual fields from model 3 are in the CSV file analysis/h_i.csv
. This can be
read in R using
df_read <- read.csv("analysis/h_i.csv", row.names = 1)
and in Python using pandas
df = pd.read_csv('analysis/h_i.csv', index_col=0)
The column named H
is the unanimity field.
Note that there is ambiguity with respect to the sign of the individual field, so we have oriented unanimity field H to be positive.
Models are defined as below.