I've got a problem of allocation of individuals by zones. To simplify this, let's say we have 5 sets, each one with a given (and decreasing) population.
S1=1000
S2=100
S3=50
S4=25
S5=5
I'd like to allocate these populations to zones (say, 10 zones Z1-Z10). Each zone has a given probability of hosting the individuals from the sets.
In a matrix form:
N<-matrix(prob,nrow=5,ncol=10)
N probabilities per set being something like:
0.15 0.05 0.1 0.05 0.05 0.2 0.01 0.09 0.15 0.15
...........
0.15 0.05 0.1 0.05 0.05 0.2 0.01 0.09 0.15 0.15
I'd like to know the resulting population, for each set, for each zone. In the first row there's no problem, because the population is high. Just multiplying 1000 by the probabilities:
S1 allocation is OK:
150 50 100 50 50 200 10 90 150 150 (individuals)
but, when you get to set S3, popul. 50, rounding is not easy as some zones would get less than 1 individual:
S3 allocation:
7.5 2.5 5 2.5 2.5 10 0.5 4.5 7.5 7.5 (individuals)
You may even get to potential sets with only 1 individual to be allocated to one of 10 zones.
How can I use the sample function in R (sample(data,size,prob)), or a similar one, to produce the allocation matrix that calculates an integer number of individuals per zone?
NB: obviously in the real problem the no. of zones is much higher, and probabilities vary for each zone.
Thanks in advance, dev