Optimal allocation of sample sizes by swapping
SwapStrataInd.Rd
This function finds an optimal allocation by swapping one unit at a time between two strata. Beta version: use with caution - needs some extra testing
Arguments
- m
Starting values for sample size in each stratum. This should sum to the desired sample size.
- bhg
A matrix giving the average number of observations in each elementary group in each stratum. See Zhang 2015 for more details.
- totVar
The variance to the index as a function of n (number of observations). See example (?).
- min_n
A minimum sample size in each stratum. This can be a single number used in all strata or a vector of numbers (one for each stratum).
- max_n
A maximum sample size in each stratum. This can be a single number used in all strata or a vector of numbers (one for each stratum).
- iter
Number of unsuccessful iterations for the algorithm to try before stopping. Default is 100.
Examples
{
# call in test dataset
data(priceData)
# Calculate s2 for index
s2 <- CalcIndS2(data = priceData, baseVar = "b1", pVar = "p1", groupVar = "varenr",
type = "carli")$s2
# Calculate bhg matrix
ngh <- table(priceData$nace3, priceData$varenr)
mh <- matrix(rep(table(priceData$nace3), 200), 5, 200)
bhg <- ngh/mh
# Specify variance function for n (number of observations) - unweighted
VarP <- function(n){
return(sum(s2 / n , na.rm = TRUE))
}
# Start values for sample size in each strata with equal numbers (adding to 300)
m <- rep(300/5, 5)
# Run Swap strata
a <- SwapStrataInd(m = m, bhg = bhg, totVar = VarP, iter = 100)
a
}
#> There has been 55 succesful iterations.
#> [1] 59 57 48 91 45