Rector elections in Warsaw School of Economics are organized in eleven constituencies representing different communities of our school. Each constituency is represented by different number of electors. I have written a simple R code calculating relative power of electors representing those constituencies. To reduce the volume of calculations I have joined some constituencies (6 and 7, 8 and 9, 10 and 11).
Here is the code performing the Shapley-Shubik Power Index calculations:
library(gregmisc)
# number of electors in each constituency
const <- c(30, 22, 27, 27, 41, 2 + 11, 38 + 5, 1 + 9)
perms <- permutations(8, 8)
outcome <- apply(perms, 1, function(x) {
x[sum(cumsum(const[x]) < 107) + 1] })
sspi <- prop.table(table(outcome))
names(sspi) <- c("C_1","C_2", "C_3", "C_4", "C_5",
"C_67", "C_89", "C_1011")
plot(sspi / (const / sum(const)),
xlab="constituency", ylab="power index / votes")
The plot generated by the code shows relative power of constituency to number of its votes. Here it goes:
Interestingly relative power index of almost all constituencies is balanced. However, power index of constituency #2 is very low in comparison to the fraction of electors it possesses.
I did the same without combining constituencies, and the result are pretty much the same - #2 seems to be really under-represented.
ReplyDeleteOn the other hand the student constituency seems to have really high relative power.
HI there: Two questions: 1) do the permutations need to match the number of constituencies in the variable constit? 2) Is the number 107 the number required to win the election?
ReplyDeleteThe answer is yes to both questions
ReplyDeleteHi, I am just coming back to this. Thanks for your response. How would you rewrite this code (e.g. the Shapley-Shubik code so that it is all in one function? I'm new to writing R functions
ReplyDeleteHere is a basic tutorial how to write functions in R: https://swcarpentry.github.io/r-novice-inflammation/02-func-R/
ReplyDelete