Description Usage Arguments Value Examples
If the user passes IV-like moments to the function, then the
function constructs the components of the LP problem. If no IV-like
moments are passed, then the function constructs the linear
constraints of the QCQP problem. Note that the LP/QCQP model will
be saved inside an environment variable, which is to be passed
through the argument env. This is done for efficient use of
memory. The environment env is supposed to already contain a
list under the entry $mbobj containing the matrices defining
the shape constraints. This list of shape constraints $mbobj
should contain three entries corresponding to a system of linear
equations of the form Ax <=> b: mbA, the matrix
defining the constraints, A; mbs, a vector indicating
whether a row in mbA is an equality or inequality constraint
(for Gurobi and MOSEK, use '<=', '>=', '='; for CPLEX,
use 'L', 'G', and 'E'); mbrhs, a vector of the right hand
side values defining the constraint of the form i.e. the vector
b. Depending on the linear programming solver used, this
function will return different output specific to the solver.
1 2 3 4 5 6 7 8 9 10 11 |
env |
environment containing the matrices defining the LP/QCQP problem. |
sset |
List of IV-like estimates and the corresponding gamma terms. |
orig.sset |
list, only used for bootstraps. The list contains the gamma moments for each element in the S-set, as well as the IV-like coefficients. |
equal.coef0 |
character, name of terms in |
equal.coef1 |
character, name of terms in |
shape |
boolean, default set to TRUE. Switch to determine whether or not to include shape restrictions in the LP/QCQP problem. |
direct |
boolean, set to |
rescale |
boolean, set to |
solver |
string, name of the package used to solve the LP/QCQP problem. |
A list of matrices and vectors necessary to define an LP/QCQP problem.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 | dtm <- ivmte:::gendistMosquito()
## Declare empty list to be updated (in the event multiple IV like
## specifications are provided
sSet <- list()
## Declare MTR formulas
formula0 = ~ 1 + u
formula1 = ~ 1 + u
## Construct object that separates out non-spline components of MTR
## formulas from the spline components. The MTR functions are
## obtained from this object by the function 'genSSet'.
splinesList = list(removeSplines(formula0), removeSplines(formula1))
## Construct MTR polynomials
polynomials0 <- polyparse(formula = formula0,
data = dtm,
uname = u,
as.function = FALSE)
polynomials1 <- polyparse(formula = formula1,
data = dtm,
uname = u,
as.function = FALSE)
## Generate propensity score model
propensityObj <- propensity(formula = d ~ z,
data = dtm,
link = "linear")
## Generate IV estimates
ivEstimates <- ivEstimate(formula = ey ~ d | z,
data = dtm,
components = l(intercept, d),
treat = d,
list = FALSE)
## Generate target gamma moments
targetGamma <- genTarget(treat = "d",
m0 = ~ 1 + u,
m1 = ~ 1 + u,
target = "atu",
data = dtm,
splinesobj = splinesList,
pmodobj = propensityObj,
pm0 = polynomials0,
pm1 = polynomials1)
## Construct S-set. which contains the coefficients and weights
## corresponding to various IV-like estimands
sSet <- genSSet(data = dtm,
sset = sSet,
sest = ivEstimates,
splinesobj = splinesList,
pmodobj = propensityObj$phat,
pm0 = polynomials0,
pm1 = polynomials1,
ncomponents = 2,
scount = 1,
yvar = "ey",
dvar = "d",
means = TRUE)
## Only the entry $sset is required
sSet <- sSet$sset
## Define additional upper- and lower-bound constraints for the LP
## problem. The code below imposes a lower bound of 0.2 and upper
## bound of 0.8 on the MTRs.
A <- matrix(0, nrow = 22, ncol = 4)
A <- cbind(A, rbind(cbind(1, seq(0, 1, 0.1)),
matrix(0, nrow = 11, ncol = 2)))
A <- cbind(A, rbind(matrix(0, nrow = 11, ncol = 2),
cbind(1, seq(0, 1, 0.1))))
sense <- c(rep(">", 11), rep("<", 11))
rhs <- c(rep(0.2, 11), rep(0.8, 11))
## Construct LP object to be interpreted and solved by
## lpSolveAPI. Note that an environment has to be created for the LP
## object. The matrices defining the shape restrictions must be stored
## as a list under the entry \code{$mbobj} in the environment.
modelEnv <- new.env()
modelEnv$mbobj <- list(mbA = A,
mbs = sense,
mbrhs = rhs)
## Convert the matrices defining the shape constraints into a format
## that is suitable for the LP solver.
lpSetup(env = modelEnv,
sset = sSet,
solver = "lpsolveapi")
## Setup LP model so that it is solving for the bounds.
lpSetupBound(env = modelEnv,
g0 = targetGamma$gstar0,
g1 = targetGamma$gstar1,
sset = sSet,
criterion.tol = 0,
criterion.min = 0,
solver = "lpsolveapi")
## Declare any LP solver options as a list.
lpOptions <- optionsLpSolveAPI(list(epslevel = "tight"))
## Obtain the bounds.
bounds <- bound(env = modelEnv,
sset = sSet,
solver = "lpsolveapi",
solver.options = lpOptions)
cat("The bounds are [", bounds$min, ",", bounds$max, "].\n")
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.