adibender / coalitions

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

Recalculating same input data multiple times - gives different results (depending on what?) #131

Open mbflex opened 4 years ago

mbflex commented 4 years ago

library(coalitions) dHondt(c(360, 280), c("A", "B"), n_seats=15) [1] 9 6 dHondt(c(360, 280), c("A", "B"), n_seats=15) [1] 9 6 dHondt(c(360, 280), c("A", "B"), nseats=15) [1] 8 7_ dHondt(c(360, 280), c("A", "B"), n_seats=15) [1] 9 6 dHondt(c(360, 280), c("A", "B"), n_seats=15) [1] 9 6 dHondt(c(360, 280), c("A", "B"), nseats=15) [1] 8 7_ dHondt(c(360, 280), c("A", "B"), n_seats=15) [1] 9 6 dHondt(c(360, 280), c("A", "B"), n_seats=15) [1] 9 6

(tested with latest version)

mbflex commented 4 years ago

It's the constellation which is described in NÖ Gemeinderatswahlordnung in §53 paragraph 6): Wenn nach dieser Rechnung zwei Parteien oder mehrere Parteien auf das letzte zur Verteilung gelangende Mandat denselben Anspruch haben, so entscheidet zwischen ihnen das Los. (If, according to this calculation, two or more parties have the same claim to the last mandate to be distributed, the decision between them shall be made by lot.) It seems that any result of the dHondt function should be marked as "unique" or "not unique" to make this point even more clear.

mbflex commented 4 years ago

another (real life) example:

dHondt(c(397, 327, 274, 109), c("A","B","C","D"), n_seats=19) [1] 7 6 5 1 dHondt(c(397, 327, 274, 109), c("A","B","C","D"), nseats=19) **[1] 7 5 5 2_ dHondt(c(397, 327, 274, 109), c("A","B","C","D"), n_seats=19) [1] 7 5 5 2** dHondt(c(397, 327, 274, 109), c("A","B","C","D"), n_seats=19) [1] 7 6 5 1 dHondt(c(397, 327, 274, 109), c("A","B","C","D"), n_seats=19)

adibender commented 4 years ago

probably a result of

m.mat     <- m.mat[rank(m.mat$value, ties.method = "random") <= n_seats, ] 

ties in the calculation of ranks are split randomly. But you should get same results if you set a seed before the calculation.

mbflex commented 4 years ago

probably a result of

m.mat     <- m.mat[rank(m.mat$value, ties.method = "random") <= n_seats, ] 

ties in the calculation of ranks are split randomly. But you should get same results if you set a seed before the calculation.

This might be the technical explanation. I personally would prefer to know whether a dHondt result is unique or not.

adibender commented 4 years ago

I guess I could store the info as an attribute of the return object, would that help? In the bigger scope, I think it doesn't matter, because for the calculation of the coalition probabilities and other quantities, we usually make the calculation a couple hundred of times.

mbflex commented 4 years ago

The result of the dHondt procedure is sometimes unique, sometimes not. In my opinion any implementation of the procedure should appreciate this feature. E.g. by the function returning a list. If the dHondt-method has a unique result at a given input, then the list should have exactly one element, namely the determined distribution - which itself is a list. If the dHondt procedure leads to n equivalent distributions, then the result list should have n entries - namely all n valid distributions.