prop_allocation

prop_allocation(
    x,
    n,
    *,
    initial={},
    available={},
    divisor=divisor_method("Jefferson/D'Hondt"),
    ties='largest',
)

Proportional to size allocation for stratified sampling.

Parameters

x : dict

The size of each stratum.

n : int

Sample size.

initial : dict = {}

Initial allocation for strata in ‘x’.

available : dict = {}

Number of available units for each strata in x.

divisor : Callable[[int], float] = divisor_method("Jefferson/D'Hondt")

A function for the divisor (highest-averages) apportionment method. The default uses the Jefferson/D’Hondt method.

ties : (largest, first) = 'largest'

Either ‘largest’ to break ties in favor of the stratum with the largest size (the default), or ‘first’ to break ties in favor of the ordering of ‘x’.

Returns

: dict

Allocation for each stratum in ‘x’.

References

Balinksi, M. L. and Young, H. P. (1982). Fair Representation: Meeting the Ideal of One Man, One Vote. Yale University Press.

Examples

import pysps

pysps.prop_allocation({"a": 1, "b": 2, "c": 3}, 5)
{'a': 0, 'b': 2, 'c': 3}
pysps.prop_allocation(
    {"a": 1, "b": 2, "c": 3},
    5,
    divisor=pysps.divisor_method("Danish")
)
{'a': 1, 'b': 2, 'c': 2}