adibender / coalitions

Coalition probabilities in multi-party democracies
https://adibender.github.io/coalitions/
Other
21 stars 4 forks source link

Adding Sainte-Lagüe formula #142

Closed paugrau closed 9 months ago

paugrau commented 2 years ago

Hello,

I used your package recently to make some simulations of seat distribution in the parliament. Specifically, I needed to use the Sainte-Lagüe formula and slightly modified your dhondt function. I leave it here just in case you think it's useful and add it to the package! :)

Best regards,

Pau Grau

slague <- function (votes, parties, n_seats) { divisor.mat <- sum(votes)/sapply(votes, "/", seq(1, n_seats, 2)) # The only difference from hondt is that 2 here colnames(divisor.mat) <- parties m.mat <- tidyr::gather(as.data.frame(divisor.mat), key = "name", value = "value", everything()) m.mat <- m.mat[rank(m.mat$value, ties.method = "random") <= n_seats, ] rle.seats <- rle(as.character(m.mat$name)) if (sum(rle.seats$length) != n_seats) stop(paste("Number of seats distributed not equal to", n_seats)) if (any(!(parties %in% rle.seats$values))) { missing_parties <- parties[!(parties %in% rle.seats$values)] for (party in missing_parties) { rle.seats$lengths <- c(rle.seats$lengths, 0) rle.seats$values <- c(rle.seats$values, party) } rle.seats$lengths <- rle.seats$lengths[match(parties, rle.seats$values)] rle.seats$values <- rle.seats$values[match(parties, rle.seats$values)] } rle.seats$length }

adibender commented 2 years ago

Hi @paugrau sorry, didn't see this. We have an implementaiton of sainte-lague scheppers here: https://github.com/adibender/coalitions/blob/master/R/saint-lague-scheppers.R Is this missing some functionality you need?

adibender commented 9 months ago

closing due to inactivity