Skip to contents

This function finds an optimal allocation by filling up or down one (or several) units at a time in a stratum(a).

Usage

FillStrataInd(
  totm,
  bhg,
  totVar,
  min_n,
  max_n,
  steps = 1,
  rand,
  direction = "up"
)

Arguments

totm

The total desired sample size as the number of units to select (NOT the number of desired observations).

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).

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).

steps

The number of strata to fill up at each iteration. Default is set to 1.

rand

specify the number of strata to consider for random selection fill up. For example rand = 10 will randomly select 1 (or the number specified in steps) strata to fill up based on the top 10 using probabilities proportional to the difference between the variances. If missing, the algorithm will chose the top strata. Currently not programmed for direction = 'down'

direction

Specify the direction the algorithm should work: "up" to fill up from 0 or a minimum value or "down" to remove one unit at a time from a maximum starting point.

Value

alloc

A vector with the new sample sizes in each strata.

totvar

Total variance

Examples

{
 
# call in test dataset
data(priceData)

# Calculate index for consumer groups
CalcInd(data = priceData, baseVar = "b1", pVar = "p1", groupVar = "varenr", wVar = "weight", 
        consumVar = "coicop", type = "dutot")

# Calculate s2 for index
s2 <- CalcIndS2(data = priceData, baseVar = "b1", pVar = "p1", groupVar = "varenr", 
                type = "carli")$s2

# Calculate bhg matrix
ngh <- as.matrix(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)) }

# Run algorithm filling up one at a time for sample size of 300
a <- FillStrataInd(totm = 300, bhg, totVar = VarP, min_n = 1, steps = 1, 
 direction = "up")
a

# Run algorithm filling down one at a time
max_n <- table(priceData$nace3)
a <- FillStrataInd(totm = 300, bhg = bhg, totVar = VarP, min_n = 1, max_n = max_n, 
 steps = 1, direction = "down")
a
}
#> Warning: Elementary group weights did not add to one and have been scaled.
#> $alloc
#> 863 864 873 875 882 
#>  59  57  48  91  45 
#> 
#> $totvar
#> [1] 0.294182
#>