Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
mbflex opened this issue Nov 11, 2020 · 6 comments

Comments

@mbflex
Copy link

mbflex commented Nov 11, 2020

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"), n_seats=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"), n_seats=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
Copy link
Author

mbflex commented Nov 11, 2020

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
Copy link
Author

mbflex commented Nov 12, 2020

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"), n_seats=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
Copy link
Owner

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
Copy link
Author

mbflex commented Nov 14, 2020

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
Copy link
Owner

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
Copy link
Author

mbflex commented Nov 17, 2020

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants