# 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
# 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: Assume we want to minimize the variation of estimates for
# revenue.
#
# The input \code{D} and \code{d} to \code{mosalloc()} can be calculated as
# follows:
D <- matrix(Sh.rev**2 * Nh**2, nrow = 1) # objective variance components
d <- sum(Sh.rev**2 * Nh) # finite population correction
# Using \code{constructDobjPrecisionSTRS()} this can also be done via
list <- list(list(stratum_id = 1:5, variate = "rev", measure = "VAR",
name = "pop"))
Dc <- constructDobjPrecisionSTRS(X_var, X_tot, Nh, list, fpc = TRUE)
# or equivalently by
list <- list(list(stratum_id = 1:5, variate = 1, measure = "VAR",
name = "pop"))
Dc <- constructDobjPrecisionSTRS(X_var, X_tot, Nh, list, fpc = TRUE)
# Evaluate output
Dc$D - D
Dc$d - d
# Example 2: Minimization of the maximum coefficient of 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
# The input \code{D} and \code{d} to \code{mosalloc()} can be calculated as
# follows:
D <- rbind(Sh.rev**2 * Nh**2 / sum(Nh * mh.rev)**2,
Sh.emp**2 * Nh**2 / sum(Nh * mh.emp)**2,
ph.rsch * (1 - ph.rsch) * Nh**3/(Nh - 1)/sum(Nh * ph.rsch)**2,
ph.offsh * (1 - ph.offsh) * Nh**3/(Nh - 1)/sum(Nh * ph.offsh)**2)
d <- as.vector(D %*% (1 / Nh)) # finite population correction
# Using \code{constructDobjPrecisionSTRS()} this can also be done via
list <- 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"))
Dc <- constructDobjPrecisionSTRS(X_var, X_tot, Nh, list, fpc = TRUE)
# Evaluation of the output
Dc$D - D
Dc$d - d
Run the code above in your browser using DataLab