Title: | Optimum Sample Allocation in Stratified Sampling |
---|---|
Description: | Functions in this package provide solution to classical problem in survey methodology - an optimum sample allocation in stratified sampling. In this context, the optimum allocation is in the classical Tschuprow-Neyman's sense and it satisfies additional lower or upper bounds restrictions imposed on sample sizes in strata. There are few different algorithms available to use, and one them is based on popular sample allocation method that applies Neyman allocation to recursively reduced set of strata. This package also provides the function that computes a solution to the minimum cost allocation problem, which is a minor modification of the classical optimum sample allocation. This problem lies in the determination of a vector of strata sample sizes that minimizes total cost of the survey, under assumed fixed level of the stratified estimator's variance. As in the case of the classical optimum allocation, the problem of minimum cost allocation can be complemented by imposing upper-bounds constraints on sample sizes in strata. |
Authors: | Wojciech Wójciak [aut, cre], Jacek Wesołowski [sad], Robert Wieczorkowski [ctb] |
Maintainer: | Wojciech Wójciak <[email protected]> |
License: | GPL-2 |
Version: | 2.2.1 |
Built: | 2024-11-01 11:16:03 UTC |
Source: | https://github.com/wwojciech/stratallo |
Optimum Sample Allocation in Stratified Sampling
Wojciech Wójciak [email protected]
Stenger, H., Gabler, S. (2005).
Combining random sampling and census strategies -
Justification of inclusion probabilities equal to 1.
Metrika, 61(2), pp. 137–156.
doi:10.1007/s001840400328
Särndal, C.-E., Swensson, B. and Wretman, J. (1992).
Model Assisted Survey Sampling, Springer, New York.
Wesołowski, J., Wieczorkowski, R., Wójciak, W. (2021).
Optimality of the Recursive Neyman Allocation.
Journal of Survey Statistics and Methodology, 10(5), pp. 1263–1275.
doi:10.1093/jssam/smab018,
doi:10.48550/arXiv.2105.14486
Wesołowski, J., Wieczorkowski, R., Wójciak, W. (2023).
R Package stratallo - source code (Version 2.2.0).
https://github.com/wwojciech/stratallo
Wesołowski, J., Wieczorkowski, R., Wójciak, W. (2023).
Numerical Performance of the RNABOX Algorithm (Version 1.0.1).
https://github.com/rwieczor/recursive_Neyman_rnabox
Wójciak, W. (2023).
Another Solution of Some Optimum Allocation Problem.
Statistics in Transition new series, 24(5) (in press).
https://arxiv.org/abs/2204.04035
Wójciak, W. (2019). Optimal Allocation in Stratified Sampling Schemes. MSc Thesis, Warsaw University of Technology, Warsaw, Poland. http://home.elka.pw.edu.pl/~wwojciak/msc_optimal_allocation.pdf
A helper function that returns a simple data.frame
with summary of the
allocation as returned by the opt()
or optcost()
. See the illustrate
example below.
asummary(x, A, m = NULL, M = NULL)
asummary(x, A, m = NULL, M = NULL)
x |
( |
A |
( |
m |
( |
M |
( |
A data.frame
with as many rows as number of strata + 1,
and up to 7 variables. A single row corresponds to a given stratum
, whilst the last row contains sums of all of the
numerical values from the above rows (wherever feasible).
Summary table has the following columns (* indicates that the column may
not be present):
population constant
lower bound imposed on sample size in stratum
upper bound imposed on sample size in stratum
sample size for a given stratum
indication whether the allocation is of take-min
type,
i.e.
indication whether the allocation is of take-max
type,
i.e.
indication whether the allocation is of take-Neyman
type, i.e.
A <- c(3000, 4000, 5000, 2000) m <- c(100, 90, 70, 80) M <- c(200, 150, 300, 210) xopt_1 <- opt(n = 400, A, m) asummary(xopt_1, A, m) xopt_2 <- opt(n = 540, A, m, M) asummary(xopt_2, A, m, M)
A <- c(3000, 4000, 5000, 2000) m <- c(100, 90, 70, 80) M <- c(200, 150, 300, 210) xopt_1 <- opt(n = 400, A, m) asummary(xopt_1, A, m) xopt_2 <- opt(n = 540, A, m, M) asummary(xopt_2, A, m, M)
Better algorithm from paper Friedrich et al. (2015) for integer-valued optimal allocation in stratified sampling.
CapacityScaling(n, Ah, mh = rep(1, length(Ah)), Mh = rep(Inf, length(Ah))) CapacityScaling2( v0, Nh, Sh, mh = rep(1, length(Nh)), Mh = rep(Inf, length(Nh)) )
CapacityScaling(n, Ah, mh = rep(1, length(Ah)), Mh = rep(Inf, length(Ah))) CapacityScaling2( v0, Nh, Sh, mh = rep(1, length(Nh)), Mh = rep(Inf, length(Nh)) )
n |
|
Ah |
|
mh |
|
Mh |
|
v0 |
|
Nh |
|
Sh |
|
A vector of optimal allocation sizes.
CapacityScaling2()
:
Friedrich, U., Münnich, R., de Vries, S. and Wagner, M. (2015) Fast integer-valued algorithms for optimal allocations under constraints in stratified sampling, Computational Statistics and Data Analysis, 92, pp. 1–12. https://www.sciencedirect.com/science/article/pii/S0167947315001413
Algorithm for optimal allocation in stratified sampling with lower and upper constraints based on fixed point iteration.
fpia( n, Ah, mh = NULL, Mh = NULL, lambda0 = NULL, maxiter = 100, tol = .Machine$double.eps * 1000 ) fpia2(v0, Nh, Sh, mh = NULL, Mh = NULL, lambda0 = NULL, maxiter = 100)
fpia( n, Ah, mh = NULL, Mh = NULL, lambda0 = NULL, maxiter = 100, tol = .Machine$double.eps * 1000 ) fpia2(v0, Nh, Sh, mh = NULL, Mh = NULL, lambda0 = NULL, maxiter = 100)
n |
|
Ah |
|
mh |
|
Mh |
|
lambda0 |
|
maxiter |
|
tol |
|
v0 |
|
Nh |
|
Sh |
|
A vector of optimal allocation sizes, and number of iterations.
fpia2()
:
Münnich, R. T., Sachs, E.W. and Wagner, M. (2012) Numerical solution of optimal allocation problems in stratified sampling under box constraints, AStA Advances in Statistical Analysis, 96(3), pp. 435-450. doi:10.1007/s10182-011-0176-z
A classical problem in survey methodology in stratified sampling is optimum
sample allocation. This problem is formulated as determination of strata
sample sizes that minimize the variance of the
stratified estimator of the population total (or mean) of a
given study variable, under certain constraints on sample sizes in strata.
The opt()
user function solves the following optimum sample allocation
problem, formulated below in the language of mathematical optimization.
Minimize
subject to
where , such that
, and
, are given numbers.
The minimization is on
.
The inequality constraints are optional and user can choose whether and how
they are to be added to the optimization problem. This is achieved by the
proper use of m
and M
arguments of this function, according to the
following rules:
no inequality constraints imposed: both m
and M
must be both set to
NULL
(default).
one-sided lower bounds , imposed:
lower bounds are specified with
m
, while M
is set to NULL
.
one-sided upper bounds , imposed:
upper bounds are specified with
M
, while m
is set to NULL
.
box-constraints imposed: lower and upper bounds must be specified with m
and M
, respectively.
opt(n, A, m = NULL, M = NULL, M_algorithm = "rna")
opt(n, A, m = NULL, M = NULL, M_algorithm = "rna")
n |
( |
A |
( |
m |
( |
M |
( |
M_algorithm |
( |
The opt()
function makes use of several allocation algorithms, depending
on which of the inequality constraints should be taken into account in the
optimization problem. Each algorithm is implemented in a separate R
function that in general should not be used directly by the end user.
The following is the list with the algorithms that are used along with the
name of the function that implements a given algorithm. See the description
of a specific function to find out more about the corresponding algorithm.
Numeric vector with optimal sample allocations in strata.
If no inequality constraints are added, the allocation is given by the Neyman allocation as:
For stratified estimator of the population total with
stratified simple random sampling without replacement design in use,
the parameters of the objective function
are:
where is the size of stratum
and
denotes
standard deviation of a given study variable in stratum
.
Särndal, C.-E., Swensson, B. and Wretman, J. (1992). Model Assisted Survey Sampling, Springer, New York.
optcost()
, rna()
, sga()
, sgaplus()
, coma()
, rnabox()
.
A <- c(3000, 4000, 5000, 2000) m <- c(100, 90, 70, 50) M <- c(300, 400, 200, 90) # One-sided lower bounds. opt(n = 340, A = A, m = m) opt(n = 400, A = A, m = m) opt(n = 700, A = A, m = m) # One-sided upper bounds. opt(n = 190, A = A, M = M) opt(n = 700, A = A, M = M) # Box-constraints. opt(n = 340, A = A, m = m, M = M) opt(n = 500, A = A, m = m, M = M) xopt <- opt(n = 800, A = A, m = m, M = M) xopt var_st(x = xopt, A = A, A0 = 45000) # Value of the variance for allocation xopt. # Execution-time comparisons of different algorithms with microbenchmark R package. ## Not run: N <- pop969[, "N"] S <- pop969[, "S"] A <- N * S nfrac <- c(0.005, seq(0.05, 0.95, 0.05)) n <- setNames(as.integer(nfrac * sum(N)), nfrac) lapply( n, function(ni) { microbenchmark::microbenchmark( RNA = opt(ni, A, M = N, M_algorithm = "rna"), SGA = opt(ni, A, M = N, M_algorithm = "sga"), SGAPLUS = opt(ni, A, M = N, M_algorithm = "sgaplus"), COMA = opt(ni, A, M = N, M_algorithm = "coma"), times = 200, unit = "us" ) } ) ## End(Not run)
A <- c(3000, 4000, 5000, 2000) m <- c(100, 90, 70, 50) M <- c(300, 400, 200, 90) # One-sided lower bounds. opt(n = 340, A = A, m = m) opt(n = 400, A = A, m = m) opt(n = 700, A = A, m = m) # One-sided upper bounds. opt(n = 190, A = A, M = M) opt(n = 700, A = A, M = M) # Box-constraints. opt(n = 340, A = A, m = m, M = M) opt(n = 500, A = A, m = m, M = M) xopt <- opt(n = 800, A = A, m = m, M = M) xopt var_st(x = xopt, A = A, A0 = 45000) # Value of the variance for allocation xopt. # Execution-time comparisons of different algorithms with microbenchmark R package. ## Not run: N <- pop969[, "N"] S <- pop969[, "S"] A <- N * S nfrac <- c(0.005, seq(0.05, 0.95, 0.05)) n <- setNames(as.integer(nfrac * sum(N)), nfrac) lapply( n, function(ni) { microbenchmark::microbenchmark( RNA = opt(ni, A, M = N, M_algorithm = "rna"), SGA = opt(ni, A, M = N, M_algorithm = "sga"), SGAPLUS = opt(ni, A, M = N, M_algorithm = "sgaplus"), COMA = opt(ni, A, M = N, M_algorithm = "coma"), times = 200, unit = "us" ) } ) ## End(Not run)
Functions that implement selected optimal allocation algorithms that compute a solution to the optimal allocation problem defined in the language of mathematical optimization as follows.
Minimize
subject to
and either
or
where
,
are given numbers. The minimization is on
.
The inequality constraints are optional and user can choose whether and how
they are to be added to the optimization problem.
If one-sided lower bounds , must be imposed, it
is then required that
.
If one-sided upper bounds
, must be imposed, it
is then required that
.
Lower bounds can be specified instead of the upper bounds only in case of the
LRNA algorithm. All other algorithms allow only for specification of
the upper bounds. For the sake of clarity, we emphasize that in the
optimization problem consider here, the lower and upper bounds cannot be
imposed jointly.
Costs , of surveying one element in stratum, can
be specified by the user only in case of the RNA and LRNA
algorithms. For remaining algorithms, these costs are fixed at 1, i.e.
.
The following is the list of all the algorithms available to use along with the name of the function that implements a given algorithm. See the description of a specific function to find out more about the corresponding algorithm.
RNA - rna()
LRNA- rna()
SGA- sga()
SGAPLUS - sgaplus()
COMA - coma()
Functions in this family should not be called directly by the user. Use
opt()
or optcost()
instead.
rna( total_cost, A, bounds = NULL, unit_costs = 1, check_violations = .Primitive(">="), details = FALSE ) sga(total_cost, A, M) sgaplus(total_cost, A, M) coma(total_cost, A, M)
rna( total_cost, A, bounds = NULL, unit_costs = 1, check_violations = .Primitive(">="), details = FALSE ) sga(total_cost, A, M) sgaplus(total_cost, A, M) coma(total_cost, A, M)
total_cost |
( |
A |
( |
bounds |
(
|
unit_costs |
( |
check_violations |
( |
details |
( |
M |
( |
Numeric vector with optimal sample allocations in strata. In case
of the rna()
only, it can also be a list
with optimal sample
allocations and strata assignments (either to take-Neyman or take-bound).
rna()
: Recursive Neyman Algorithm (RNA) and its
twin version, Lower Recursive Neyman Algorithm (LRNA)
dedicated to the allocation problem with one-sided lower-bounds constraints.
The RNA is described in Wesołowski et al. (2021), while LRNA is
introduced in Wójciak (2023).
sga()
: Stenger-Gabler type algorithm SGA, described in
Wesołowski et al. (2021) and in Stenger and Gabler (2005).
This algorithm solves the problem with one-sided upper-bounds constraints.
It also assumes unit costs are constant and equal to 1, i.e.
.
sgaplus()
: modified Stenger-Gabler type algorithm, described in
Wójciak (2019) as Sequential Allocation (version 1) algorithm.
This algorithm solves the problem with one-sided upper-bounds constraints.
It also assumes unit costs are constant and equal to 1, i.e.
.
coma()
: Change of Monotonicity Algorithm (COMA),
described in Wesołowski et al. (2021).
This algorithm solves the problem with one-sided upper-bounds constraints.
It also assumes unit costs are constant and equal to 1, i.e.
.
If no inequality constraints are added, the allocation is given by the Neyman allocation as:
For stratified estimator of the population total with
stratified simple random sampling without replacement design in use,
the parameters of the objective function
are:
where is the size of stratum
and
denotes
standard deviation of a given study variable in stratum
.
Wójciak, W. (2023).
Another Solution of Some Optimum Allocation Problem.
Statistics in Transition new series, 24(5) (in press).
https://arxiv.org/abs/2204.04035
Wesołowski, J., Wieczorkowski, R., Wójciak, W. (2021).
Optimality of the Recursive Neyman Allocation.
Journal of Survey Statistics and Methodology, 10(5), pp. 1263–1275.
doi:10.1093/jssam/smab018,
doi:10.48550/arXiv.2105.14486
Wójciak, W. (2019). Optimal Allocation in Stratified Sampling Schemes.
MSc Thesis, Warsaw University of Technology, Warsaw, Poland.
http://home.elka.pw.edu.pl/~wwojciak/msc_optimal_allocation.pdf
Stenger, H., Gabler, S. (2005).
Combining random sampling and census strategies -
Justification of inclusion probabilities equal to 1.
Metrika, 61(2), pp. 137–156.
doi:10.1007/s001840400328
Särndal, C.-E., Swensson, B. and Wretman, J. (1992). Model Assisted Survey Sampling, Springer, New York.
A <- c(3000, 4000, 5000, 2000) m <- c(50, 40, 10, 30) # lower bounds M <- c(100, 90, 70, 80) # upper bounds rna(total_cost = 190, A = A, bounds = M) rna(total_cost = 190, A = A, bounds = m, check_violations = .Primitive("<=")) sga(total_cost = 190, A = A, M = M) sgaplus(total_cost = 190, A = A, M = M) coma(total_cost = 190, A = A, M = M)
A <- c(3000, 4000, 5000, 2000) m <- c(50, 40, 10, 30) # lower bounds M <- c(100, 90, 70, 80) # upper bounds rna(total_cost = 190, A = A, bounds = M) rna(total_cost = 190, A = A, bounds = m, check_violations = .Primitive("<=")) sga(total_cost = 190, A = A, M = M) sgaplus(total_cost = 190, A = A, M = M) coma(total_cost = 190, A = A, M = M)
Function that determines fixed strata sample sizes that minimize total cost
of the survey, under assumed level of the variance of the stratified
estimator and under optional one-sided upper bounds imposed on strata sample
sizes. Namely, the following optimization problem, formulated below in the
language of mathematical optimization, is solved by optcost()
function.
Minimize
subject to
where ,
and
are given numbers. The
minimization is on
.
The upper-bounds constraints
, are
optional and can be skipped. In such a case, it is only required that
.
optcost(V, A, A0, M = NULL, unit_costs = 1)
optcost(V, A, A0, M = NULL, unit_costs = 1)
V |
( |
A |
( |
A0 |
( |
M |
( |
unit_costs |
( |
The algorithm that is used by optcost()
is the LRNA
and it is
described in Wójciak (2023). The allocation computed is valid for all
stratified sampling schemes for which the variance of the stratified
estimator is of the form:
where denotes total number of strata,
are
strata sample sizes and
, do not
depend on
.
Numeric vector with optimal sample allocations in strata.
For stratified estimator of the population total and
for stratified simple random sampling without replacement design,
the population parameters are as follows:
where is the size of stratum
and
denotes
standard deviation of a given study variable in stratum
.
Wójciak, W. (2023). Another Solution of Some Optimum Allocation Problem. Statistics in Transition new series, 24(5) (in press). https://arxiv.org/abs/2204.04035
A <- c(3000, 4000, 5000, 2000) M <- c(100, 90, 70, 80) xopt <- optcost(1017579, A = A, A0 = 579, M = M) xopt
A <- c(3000, 4000, 5000, 2000) M <- c(100, 90, 70, 80) xopt <- optcost(1017579, A = A, A0 = 579, M = M) xopt
A dataset containing the artificial population with 10 strata. Additionally, the lower and upper bounds for samples in strata are specified.
pop10_mM
pop10_mM
A matrix with 10 rows and 5 variables:
stratum size
standard deviation of study variable in stratum
lower bound for sample size in stratum
upper bound for sample size in stratum
cost of surveying one element in stratum
A dataset containing the artificial population with 507 strata.
pop507
pop507
A matrix with 507 rows and 3 variables:
stratum size
standard deviation of study variable in stratum
cost of surveying one element in stratum
A dataset containing the artificial population with 969 strata.
pop969
pop969
A matrix with 969 rows and 3 variables:
stratum size
standard deviation of study variable in stratum
cost of surveying one element in stratum
A number is rounded to integer
according to the following
rule:
where function , is defined as:
and is number that is generated from
Uniform(0, 1)
distribution.
ran_round(x)
ran_round(x)
x |
( |
An integer vector.
x <- c(4.5, 4.1, 4.9) set.seed(5) ran_round(x) # 5 4 4 set.seed(6) ran_round(x) # 4 4 5
x <- c(4.5, 4.1, 4.9) set.seed(5) ran_round(x) # 5 4 4 set.seed(6) ran_round(x) # 4 4 5
This is the version of the RNA that makes use of additional information about strata for which the allocation can possibly be violated. For all other strata allocation will not be violated.
rna_prior( total_cost, A, bounds = NULL, check = NULL, check_violations = .Primitive(">="), details = FALSE )
rna_prior( total_cost, A, bounds = NULL, check = NULL, check_violations = .Primitive(">="), details = FALSE )
total_cost |
( |
A |
( |
bounds |
(
|
check |
( |
check_violations |
( |
details |
( |
this coded was not extensively tested.
rna_rec( total_cost, A, bounds = NULL, unit_costs = rep(1, length(A)), check_violations = .Primitive(">=") )
rna_rec( total_cost, A, bounds = NULL, unit_costs = rep(1, length(A)), check_violations = .Primitive(">=") )
total_cost |
( |
A |
( |
bounds |
(
|
unit_costs |
( |
check_violations |
( |
this coded was not extensively tested.
A <- c(3000, 4000, 5000, 2000) M <- c(100, 90, 70, 80) # upper bounds. rna_rec(total_cost = 190, A = A, bounds = M) rna_rec(total_cost = 312, A = A, bounds = M) rna_rec(total_cost = 339, A = A, bounds = M) rna_rec(total_cost = 340, A = A, bounds = M)
A <- c(3000, 4000, 5000, 2000) M <- c(100, 90, 70, 80) # upper bounds. rna_rec(total_cost = 190, A = A, bounds = M) rna_rec(total_cost = 312, A = A, bounds = M) rna_rec(total_cost = 339, A = A, bounds = M) rna_rec(total_cost = 340, A = A, bounds = M)
An internal function that implements the RNABOX
algorithm that solves the
following optimal allocation problem, formulated below in the language of
mathematical optimization.
Minimize
subject to
where , such that
, and
, are given numbers.
The minimization is on
.
Inequality constraints are optional and can be skipped.
rnabox()
function should not be called directly by the user. Use opt()
instead.
rnabox( n, A, bounds1 = NULL, bounds2 = NULL, check_violations1 = .Primitive(">="), check_violations2 = .Primitive("<=") )
rnabox( n, A, bounds1 = NULL, bounds2 = NULL, check_violations1 = .Primitive(">="), check_violations2 = .Primitive("<=") )
n |
( |
A |
( |
bounds1 |
( |
bounds2 |
( |
check_violations1 |
( |
check_violations2 |
( |
Numeric vector with optimal sample allocations in strata.
To be added soon.
opt()
, optcost()
, sga()
, sgaplus()
, coma()
.
N <- c(454, 10, 116, 2500, 2240, 260, 39, 3000, 2500, 400) S <- c(0.9, 5000, 32, 0.1, 3, 5, 300, 13, 20, 7) A <- N * S m <- c(322, 3, 57, 207, 715, 121, 9, 1246, 1095, 294) # lower bounds M <- N # upper bounds # Regular allocation. n <- 6000 opt_regular <- rnabox(n, A, M, m) # Vertex allocation. n <- 4076 opt_vertex <- rnabox(n, A, M, m)
N <- c(454, 10, 116, 2500, 2240, 260, 39, 3000, 2500, 400) S <- c(0.9, 5000, 32, 0.1, 3, 5, 300, 13, 20, 7) A <- N * S m <- c(322, 3, 57, 207, 715, 121, 9, 1246, 1095, 294) # lower bounds M <- N # upper bounds # Regular allocation. n <- 6000 opt_regular <- rnabox(n, A, M, m) # Vertex allocation. n <- 4076 opt_vertex <- rnabox(n, A, M, m)
round_oric(x)
round_oric(x)
x |
( |
An integer vector.
Cont, R., Heidari, M. (2014). Optimal rounding under integer constraints. doi:10.48550/arXiv.1501.00014
x <- c(4.5, 4.1, 4.9) round_oric(x) # 4 4 5
x <- c(4.5, 4.1, 4.9) round_oric(x) # 4 4 5
Simple algorithm from paper Friedrich et al. (2015) for integer-valued optimal allocation in stratified sampling.
SimpleGreedy( n, Ah, mh = rep(1, length(Ah)), Mh = rep(Inf, length(Ah)), nh = mh ) SimpleGreedy2(v0, Nh, Sh, mh = rep(1, length(Nh)), Mh = Nh, nh = mh)
SimpleGreedy( n, Ah, mh = rep(1, length(Ah)), Mh = rep(Inf, length(Ah)), nh = mh ) SimpleGreedy2(v0, Nh, Sh, mh = rep(1, length(Nh)), Mh = Nh, nh = mh)
n |
|
Ah |
|
mh |
|
Mh |
|
nh |
|
v0 |
|
Nh |
|
Sh |
|
A vector of optimal allocation sizes.
SimpleGreedy2()
:
Friedrich, U., Münnich, R., de Vries, S. and Wagner, M. (2015) Fast integer-valued algorithms for optimal allocations under constraints in stratified sampling, Computational Statistics and Data Analysis, 92, pp. 1–12. https://www.sciencedirect.com/science/article/pii/S0167947315001413
Compute the value of the variance function of the stratified
estimator, which is of the following generic form:
where denotes total number of strata,
are strata
sample sizes and
, are population
constants.
var_st(x, A, A0) var_st_tsi(x, N, S)
var_st(x, A, A0) var_st_tsi(x, N, S)
x |
( |
A |
( |
A0 |
( |
N |
( |
S |
( |
Value of the variance for a given allocation vector
.
var_st_tsi()
: computes value of variance for the case of
stratified
estimator of the population total and
stratified simple random sampling without replacement design. This
particular case yields:
where is the size of stratum
, and
is stratum
standard deviation of a study variable,
.
Särndal, C.-E., Swensson, B. and Wretman, J. (1992). Model Assisted Survey Sampling, Chapter 3.7 Stratified Sampling, Springer, New York.
N <- c(3000, 4000, 5000, 2000) S <- rep(1, 4) M <- c(100, 90, 70, 80) xopt <- opt(n = 190, A = N * S, M = M) var_st_tsi(x = xopt, N, S) # 1017579
N <- c(3000, 4000, 5000, 2000) S <- rep(1, 4) M <- c(100, 90, 70, 80) xopt <- opt(n = 190, A = N * S, M = M) var_st_tsi(x = xopt, N, S) # 1017579