# Artificial population of 50 568 business establishments and 5 business
# sectors (data from Valliant, R., Dever, J. A., & Kreuter, F. (2013).
# Practical tools for designing and weighting survey samples. Springer.
# https://doi.org/10.1007/978-1-4614-6449-5, Example 5.2 pages 133-9)
# See also https://umd.app.box.com/s/9yvvibu4nz4q6rlw98ac/file/297813512360
# file: Code 5.3 constrOptim.example.R
Nh <- c(6221, 11738, 4333, 22809, 5467) # stratum sizes
H <- length(Nh)
ch <- c(120, 80, 80, 90, 150) # stratum-specific cost of surveying
budget <- 300000
# Examples
#----------------------------------------------------------------------------
# Example 1: Assume we want so specify one overall cost constraint for the
# five strata. The cost of surveying must not exceed 300000 $.
# The input \code{C} and \code{C} to \code{mosalloc} can be specified as
# follows:
C <- matrix(ch, nrow = 1)
c <- as.vector(budget)
# Using \code{constructCrestrSTRS} this can also be done via
list <- list(list(stratum_id = 1:5, c_coef = ch, c_lower = NULL,
c_upper = budget, name = "Overall"))
Cc <- constructCrestrSTRS(H, list)
# Evaluation of the output
Cc$C - C
Cc$c - c
# Example 2: In addition to the overall cost constraint from Example 1,
# we want to specify a minimum sample size for strata 1 to 3.
# The input \code{C} and \code{C} to \code{mosalloc} can be specified as
# follows:
C <- rbind(ch,
ch * c(-1, -1, -1, 0, 0))
c <- c(budget, # Maximum overall survey budget
- 0.5 * budget) # Minimum overall budget for strata 1-3
# Using \code{constructCrestrSTRS} this can also be done via
list <- list(list(stratum_id = 1:5, c_coef = ch, c_lower = NULL,
c_upper = budget, name = "Overall"),
list(stratum_id = 1:3, c_coef = ch[1:3], c_lower = 0.5 * budget,
c_upper = NULL, name = "1to3"))
Cc <- constructCrestrSTRS(H, list)
# Evaluation of the output
Cc$C - C
Cc$c - c
Run the code above in your browser using DataLab