# 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
ch <- c(120, 80, 80, 90, 150) # stratum-specific cost of surveying
# Revenues
mh.rev <- c(85, 11, 23, 17, 126) # mean revenue
Sh.rev <- c(170.0, 8.8, 23.0, 25.5, 315.0) # standard deviation revenue
# Employees
mh.emp <- c(511, 21, 70, 32, 157) # mean number of employees
Sh.emp <- c(255.50, 5.25, 35.00, 32.00, 471.00) # std. dev. employees
# Proportion of estabs claiming research credit
ph.rsch <- c(0.8, 0.2, 0.5, 0.3, 0.9)
# Proportion of estabs with offshore affiliates
ph.offsh <- c(0.06, 0.03, 0.03, 0.21, 0.77)
budget <- 300000 # overall available budget
n.min <- 100 # minimum stratum-specific sample size
# Matrix containing stratum-specific variance components
X_var <- cbind(Sh.rev**2,
Sh.emp**2,
ph.rsch * (1 - ph.rsch) * Nh/(Nh - 1),
ph.offsh * (1 - ph.offsh) * Nh/(Nh - 1))
colnames(X_var) <- c("rev", "emp", "rsch", "offsh")
# Matrix containing stratum-specific totals
X_tot <- cbind(mh.rev, mh.emp, ph.rsch, ph.offsh) * Nh
colnames(X_tot) <- c("rev", "emp", "rsch", "offsh")
# Examples
#----------------------------------------------------------------------------
# Example 1: Univariate minimization of the variation of estimates for
# revenue subject to cost restrictions and precision restrictions to the
# relative standard error of estimates for the proportion of businesses with
# offshore affiliates. Additionally, there is one overall cost constraint and
# at least half of the provided budget must be spend to strata 1 to 3.
# Specify objectives via listD
listD <- list(list(stratum_id = 1:5, variate = "rev", measure = "relVAR",
name = "pop"))
# Specify precision constraints via listA
listA <- list(list(stratum_id = 1:5, variate = "offsh", measure = "RSE",
bound = 0.05, name = "pop"))
# Specify cost constraints via listC
listC <- 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"))
# Specify stratum-specific box constraints
l <- rep(n.min, 5) # minimum sample size per stratum
u <- Nh # maximum sample size per stratum
# Specify parameter for mosalloc (method = "WSS")
opts <- list(sense = "max_precision",
f = NULL, df = NULL, Hf = NULL,
method = "WSS", init_w = 1,
mc_cores = 1L, pm_tol = 1e-05,
max_iters = 100L, print_pm = FALSE)
# Run mosallocSTRS with weighted sum scalarization (WSS)
resWSS <- mosallocSTRS(X_var, X_tot, Nh, listD, listA, listC,
fpc = TRUE, l, u, opts)
summary(resWSS)
# Specify parameter for mosalloc (method = "WCM")
opts = list(sense = "max_precision",
f = NULL, df = NULL, Hf = NULL,
method = "WCM", init_w = 1,
mc_cores = 1L, pm_tol = 1e-05,
max_iters = 100L, print_pm = FALSE)
# Run mosallocSTRS with weighted Chebyshec minimization (WCM)
resWCM <- mosallocSTRS(X_var, X_tot, Nh, listD, listA, listC,
fpc = TRUE, l, u, opts)
summary(resWCM)
# The optimal sample sizes vector can also be obtained by
summary(resWCM)$n_opt
# Hint: For univariate allocation problems 'WSS' and 'WCM' are equivalent!
#----------------------------------------------------------------------------
# Example 2: Minimization of the maximum relative variation of estimates for
# the total revenue, the number of employee, the number of businesses claimed
# research credit and the number of businesses with offshore affiliates
# subject to one overall cost constraint and at least half of the provided
# budget must be spend to strata 1 to 3.
# Specify objectives via listD
listD <- list(list(stratum_id = 1:5, variate = "rev", measure = "relVAR",
name = "pop"),
list(stratum_id = 1:5, variate = "emp", measure = "relVAR",
name = "pop"),
list(stratum_id = 1:5, variate = "rsch", measure = "relVAR",
name = "pop"),
list(stratum_id = 1:5, variate = "offsh", measure = "relVAR",
name = "pop"))
# Specify cost constraints via listC
listC <- 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"))
# Specify stratum-specific box constraints
l <- rep(n.min, 5) # minimum sample size per stratum
u <- Nh # maximum sample size per stratum
# Specify parameter for mosalloc (method = "WSS")
opts = list(sense = "max_precision",
f = NULL, df = NULL, Hf = NULL,
method = "WSS", init_w = 1,
mc_cores = 1L, pm_tol = 1e-05,
max_iters = 100L, print_pm = FALSE)
# Run mosallocSTRS with weighted sum scalarization (WSS)
resWSS <- mosallocSTRS(X_var, X_tot, Nh, listD, NULL, listC,
fpc = TRUE, l, u, opts)
summary(resWSS)
# Specify parameter for mosalloc (method = "WCM")
opts = list(sense = "max_precision",
f = NULL, df = NULL, Hf = NULL,
method = "WCM", init_w = 1,
mc_cores = 1L, pm_tol = 1e-05,
max_iters = 100L, print_pm = FALSE)
# Run mosallocSTRS with weighted Chebyshec minimization (WCM)
resWCM <- mosallocSTRS(X_var, X_tot, Nh, listD, NULL, listC,
fpc = TRUE, l, u, opts)
summary(resWCM)
# Since the WCM does not necessarily lead to Pareto optimal allocations,
# we might force this via a internal stepwise procedure by setting
# ForceOptimality = TRUE.
resWCM_FO <- mosallocSTRS(X_var, X_tot, Nh, listD, NULL, listC,
fpc = TRUE, l, u, opts, ForceOptimality = TRUE)
summary(resWCM_FO)
#----------------------------------------------------------------------------
# Example 3: Example 2 with multiple sets of preference weightings.
# Define a set of preference weightings, e.g.
w_1 <- c(1, 1, 1, 1)
w_2 <- c(1, 2, 2, 1)
w_3 <- c(1, 5, 5, 1)
# Combine the weightings to a matrix stacked rowwise
w <- rbind(w_1, w_2, w_3)
# Specify parameter for mosalloc() (method = "WCM"; not yet possible with WSS)
opts = list(sense = "max_precision",
f = NULL, df = NULL, Hf = NULL,
method = "WCM", init_w = w,
mc_cores = 1L, pm_tol = 1e-05,
max_iters = 100L, print_pm = FALSE)
# Run mosallocSTRS with weighted Chebyshec minimization (WCM)
res <- mosallocSTRS(X_var, X_tot, Nh, listD, NULL, listC, fpc = TRUE,
l, u, opts)
summary(res)
#----------------------------------------------------------------------------
# Example 4: Minimization of survey cost subject to quality restrictions on
# subpopulation level.
X_cost <- matrix(ch, 5, 1, dimnames = list(1:5,"cost"))
# Specify cost objectives via listD
listD <- list(list(stratum_id = 1:5, c_type = "cost", name = "pop"))
# Specify quailty restrictions via listD. Here: 5 % relative standard error
listA <- list(list(stratum_id = 1:2, variate = "rev", measure = "RSE",
bound = 0.05, name = "S1-2"),
list(stratum_id = 3:5, variate = "rev", measure = "RSE",
bound = 0.05, name = "S3-5"),
list(stratum_id = 1:2, variate = "emp", measure = "RSE",
bound = 0.05, name = "S1-2"),
list(stratum_id = 3:5, variate = "emp", measure = "RSE",
bound = 0.05, name = "S3-5"),
list(stratum_id = 1:2, variate = "rsch", measure = "RSE",
bound = 0.05, name = "S1-2"),
list(stratum_id = 3:5, variate = "rsch", measure = "RSE",
bound = 0.05, name = "S3-5"),
list(stratum_id = 1:2, variate = "offsh", measure = "RSE",
bound = 0.05, name = "S1-2"),
list(stratum_id = 3:5, variate = "offsh", measure = "RSE",
bound = 0.05, name = "S3-5"))
# Specify cost constraints
listC <- NULL
# Specify stratum-specific box constraints
l <- rep(n.min, 5) # minimum sample size per stratum
u <- Nh # maximum sample size per stratum
# Specify parameters for mosalloc()
opts = list(sense = "min_cost",
f = NULL, df = NULL, Hf = NULL,
method = "WCM", init_w = 1,
mc_cores = 1L, pm_tol = 1e-05,
max_iters = 100L, print_pm = FALSE)
# Run mosallocSTRS()
res <- mosallocSTRS(X_var, X_tot, Nh, listD, listA, NULL, fpc = TRUE,
l, u, opts, X_cost = X_cost)
summary(res)
# Optimal sample sizes
summary(res)$n_opt
Run the code above in your browser using DataLab