Movatterモバイル変換


[0]ホーム

URL:


Title:Instrumental Variables: Extrapolation by Marginal TreatmentEffects
Version:1.4.0
Maintainer:Joshua Shea <jkcshea@uchicago.edu>
Description:The marginal treatment effect was introduced by Heckman and Vytlacil (2005) <doi:10.1111/j.1468-0262.2005.00594.x> to provide a choice-theoretic interpretation to instrumental variables models that maintain the monotonicity condition of Imbens and Angrist (1994) <doi:10.2307/2951620>. This interpretation can be used to extrapolate from the compliers to estimate treatment effects for other subpopulations. This package provides a flexible set of methods for conducting this extrapolation. It allows for parametric or nonparametric sieve estimation, and allows the user to maintain shape restrictions such as monotonicity. The package operates in the general framework developed by Mogstad, Santos and Torgovitsky (2018) <doi:10.3982/ECTA15463>, and accommodates either point identification or partial identification (bounds). In the partially identified case, bounds are computed using either linear programming or quadratically constrained quadratic programming. Support for four solvers is provided. Gurobi and the Gurobi R API can be obtained fromhttp://www.gurobi.com/index. CPLEX can be obtained fromhttps://www.ibm.com/analytics/cplex-optimizer. CPLEX R APIs 'Rcplex' and 'cplexAPI' are available from CRAN. MOSEK and the MOSEK R API can be obtained fromhttps://www.mosek.com/. The lp_solve library is freely available fromhttp://lpsolve.sourceforge.net/5.5/, and is included when installing its API 'lpSolveAPI', which is available from CRAN.
Depends:R (≥ 3.6.0)
Imports:Formula, methods, stats, utils
Suggests:gurobi (≥ 8.1-0), slam (≥ 0.1-42), cplexAPI (≥ 1.3.3),lpSolveAPI (≥ 5.5.2.0-17), Rmosek (≥ 9.2.38), testthat (≥2.0.0), data.table (≥ 1.12.0), splines2 (≥ 0.2.8),future.apply (≥ 1.6.0), future (≥ 1.18.0), Matrix, knitr,rmarkdown, pander, AER, lsei, ggplot2, gridExtra
License:GPL-2 |GPL-3
Encoding:UTF-8
LazyData:true
RoxygenNote:7.1.1
VignetteBuilder:knitr
NeedsCompilation:no
Packaged:2021-09-08 18:57:33 UTC; jkcshea
Author:Alexander Torgovitsky [aut], Joshua Shea [aut, cre]
Repository:CRAN
Date/Publication:2021-09-17 12:20:07 UTC

Angrist Evans Data

Description

Angrist Evans Data

Usage

AE

Format

A data frame with 209,133 rows and 8 columns.

worked

indicator for whether worked in the previous year

hours

weekly hours worked in the previous year

morekids

indicator for having more than two children vs. exactly two children.

samesex

indicator for the first two children having the same sex (male-male or female-female)

yob

the year the woman was born

black

indicator that mother is Black

hisp

indicator that mother is Hispanic

other

indicator that mother is neither Black nor Hispanic

Source

Derived from Angrist and Evans (1998, The American Economic Review).


(Alternative) Defining single splines basis functions, withinteractions

Description

This function returns a numerically integrable functioncorresponding to a single splines basis function. It was notimplemented because it was slower than using the function from thesplines2 package.

Usage

altDefSplinesBasis(splineslist, j, l, v = 1)

Arguments

splineslist

a list of splines commands and names ofvariables that interact with the splines. This is generatedusing the commandremoveSplines.

j

the index for the spline for which to generate the basisfunctions.

l

the index for the basis.

v

a constant that multiplies the spline basis.

Value

a vectorized function corresponding to a single splinesbasis function that can be numerically integrated.


Auxiliary function: extract arguments from function in string form

Description

Auxiliary function to extract arguments from a function that is instring form.

Usage

argstring(string)

Arguments

string

the function in string form.

Value

string of arguments.


Audit procedure

Description

This is the wrapper for running the entire audit procedure. Thisfunction sets up the LP/QCQP problem of minimizing criterion. forthe set of IV-like estimands, while satisfying boundedness andmonotonicity constraints declared by the user. Rather than enforcethat boundedness and monotonicity hold across the entire support ofcovariates and unobservables, this procedure enforces theconditions over a grid of points. This grid corresponds to the setof values the covariates can take, and a set of values of theunobservable term. The size of this grid is specified by the userin the function arguments. The procedure first estimates the boundswhile imposing the shape constraints for an initial subset ofpoints in the grid. The procedure then goes on to check ('audit')whether the constraints are satisfied over the entire grid. Anypoint where either the boundedness or monotonicity constraints areviolated are incorporated into the initial grid, and the process isrepeated until the audit no longer finds any violations, or untilsome maximum number of iterations is reached.

Usage

audit(  data,  uname,  m0,  m1,  pm0,  pm1,  splinesobj,  vars_mtr,  terms_mtr0,  terms_mtr1,  vars_data,  initgrid.nu = 20,  initgrid.nx = 20,  audit.nx = 2500,  audit.nu = 25,  audit.add = 100,  audit.max = 25,  audit.tol,  audit.grid = NULL,  m1.ub,  m0.ub,  m1.lb,  m0.lb,  mte.ub,  mte.lb,  m1.ub.default = FALSE,  m0.ub.default = FALSE,  mte.ub.default = FALSE,  m1.lb.default = FALSE,  m0.lb.default = FALSE,  mte.lb.default = FALSE,  m0.dec = FALSE,  m0.inc = FALSE,  m1.dec = FALSE,  m1.inc = FALSE,  mte.dec = FALSE,  mte.inc = FALSE,  equal.coef0,  equal.coef1,  sset,  gstar0,  gstar1,  orig.sset = NULL,  orig.criterion = NULL,  criterion.tol = 1e-04,  solver,  solver.options,  solver.presolve,  solver.options.criterion,  solver.options.bounds,  rescale = TRUE,  smallreturnlist = FALSE,  noisy = TRUE,  debug = FALSE)

Arguments

data

data.frame ordata.table used to estimatethe treatment effects.

uname

variable name for the unobservable used in declaringthe MTRs. The name can be provided with or without quotationmarks.

m0

one-sided formula for the marginal treatment responsefunction for the control group. Splines may also beincorporated using the expressionuSpline, e.g.uSpline(degree = 2, knots = c(0.4, 0.8), intercept =TRUE). Theintercept argument may be omitted, and isset toTRUE by default.

m1

one-sided formula for the marginal treatment responsefunction for the treated group. Seem0 for details.

pm0

A list of the monomials in the MTR for the controlgroup.

pm1

A list of the monomials in the MTR for the treatedgroup.

splinesobj

list of spline components in the MTRs for treatedand control groups. Spline terms are extracted usingremoveSplines. This object is supposed to be adictionary of splines, containing the original calls of eachspline in the MTRs, their specifications, and the index usedfor naming each basis spline.

vars_mtr

character, vector of variables entering intom0 andm1.

terms_mtr0

character, vector of terms entering intom0.

terms_mtr1

character, vector of terms entering intom1.

vars_data

character, vector of variables that can be foundin the data.

initgrid.nu

integer determining the number of points in theopen interval (0, 1) drawn from a Halton sequence. The endpoints 0 and 1 are additionally included. These points arealways a subset of the points defining the audit grid (seeaudit.nu). These points are used to form the initialconstraint grid for imposing shape restrictions on theucomponents of the MTRs.

initgrid.nx

integer determining the number of points of thecovariates used to form the initial constraint grid forimposing shape restrictions on the MTRs.

audit.nx

integer determining the number of points on thecovariates space to audit in each iteration of the auditprocedure.

audit.nu

integer determining the number of points in theopen interval (0, 1) drawn from a Halton sequence. The endpoints 0 and 1 are additionally included. These points are usedto audit whether the shape restrictions on theucomponents of the MTRs are satisfied. The initial grid used toimpose the shape constraints in the LP/QCQP problem areconstructed from a subset of these points.

audit.add

maximum number of points to add to the initialconstraint grid for imposing each kind of shape constraint. Forexample, if there are 5 different kinds of shape constraints,there can be at mostaudit.add * 5 additional pointsadded to the constraint grid.

audit.max

maximum number of iterations in the auditprocedure.

audit.tol

feasibility tolerance when performing theaudit. By default to set to be 1e-06, which is equal to thedefault feasibility tolerances of Gurobi (solver ="gurobi"), CPLEX (solver = "cplexapi"), and Rmosek(solver = "rmosek"). This parameter should only bechanged if the feasibility tolerance of the solver is changed,or if numerical issues result in discrepancies between thesolver's feasibility check and the audit.

audit.grid

list, contains theA matrix used in theaudit for the original sample, as well as the RHS vector usedin the audit from the original sample.

m1.ub

numeric value for upper bound on MTR for the treatedgroup. By default, this will be set to the largest value of theobserved outcome in the estimation sample.

m0.ub

numeric value for upper bound on MTR for the controlgroup. By default, this will be set to the largest value of theobserved outcome in the estimation sample.

m1.lb

numeric value for lower bound on MTR for the treatedgroup. By default, this will be set to the smallest value ofthe observed outcome in the estimation sample.

m0.lb

numeric value for lower bound on MTR for the controlgroup. By default, this will be set to the smallest value ofthe observed outcome in the estimation sample.

mte.ub

numeric value for upper bound on treatment effectparameter of interest.

mte.lb

numeric value for lower bound on treatment effectparameter of interest.

m1.ub.default

boolean, default set to FALSE. Indicator forwhether the value assigned was by the user, or set by default.

m0.ub.default

boolean, default set to FALSE. Indicator forwhether the value assigned was by the user, or set by default.

mte.ub.default

boolean, default set to FALSE. Indicator forwhether the value assigned was by the user, or set by default.

m1.lb.default

boolean, default set to FALSE. Indicator forwhether the value assigned was by the user, or set by default.

m0.lb.default

boolean, default set to FALSE. Indicator forwhether the value assigned was by the user, or set by default.

mte.lb.default

boolean, default set to FALSE. Indicator forwhether the value assigned was by the user, or set by default.

m0.dec

logical, set toFALSE by default. Set equal toTRUE if the MTR for the control group should be weaklymonotone decreasing.

m0.inc

logical, set toFALSE by default. Set equal toTRUE if the MTR for the control group should be weaklymonotone increasing.

m1.dec

logical, set toFALSE by default. Set equal toTRUE if the MTR for the treated group should be weaklymonotone decreasing.

m1.inc

logical, set toFALSE by default. Set equal toTRUE if the MTR for the treated group should be weaklymonotone increasing.

mte.dec

logical, set toFALSE by default. Set equaltoTRUE if the MTE should be weakly monotone decreasing.

mte.inc

logical, set toFALSE by default. Set equaltoTRUE if the MTE should be weakly monotone increasing.

equal.coef0

character, a vector containing all the terms inm0 that should have the same coefficients inm1. The order of the variables must match those ofequal.coef1, which contains all the corresponding termsinm1. The reason the terms are entered separately form0 andm1 is because the spline terms may benamed differently across treatment and control groups.

equal.coef1

character, a vector containing all the terms inm1 that should have the same coefficients inm0. See the description forequal.coef0 for moredetails.

sset

a list containing the point estimates and gamma momentsfor each IV-like specification.

gstar0

set of expectations for each terms of the MTR for thecontrol group, corresponding to the target parameter.

gstar1

set of expectations for each terms of the MTR for thecontrol group, corresponding to the target parameter.

orig.sset

list, only used for bootstraps. The list containsthe gamma moments for each element in the S-set, as well as theIV-like coefficients.

orig.criterion

numeric, only used for bootstraps. The scalarcorresponds to the minimum observational equivalence criterionfrom the original sample.

criterion.tol

tolerance for the criterion function, and isset to 1e-4 by default. The criterion measures how well theIV-like moments/conditional means are matched using thel1-norm. Statistical noise may prohibit the theoretical LP/QCQPproblem from being feasible. That is, there may not exist a setof MTR coefficients that are able to match all the specifiedmoments. The function thus first estimates the minimumcriterion, which is reported in the output under the name'minimum criterion', with a criterion of 0 meaning that allmoments were able to be matched. The function then relaxes theconstraints by tolerating a criterion up tominimumcriterion * (1 + criterion.tol). Setcriterion.tol to avalue greater than 0 to allow for more conservative bounds.

solver

character, name of the programming package in R usedto obtain the bounds on the treatment effect. The functionsupports'gurobi','cplexapi',rmosek,'lpsolveapi'. The name of the solver should be providedwith quotation marks.

solver.options

list, each item of the list should correspondto an option specific to the solver selected.

solver.presolve

boolean, default set toTRUE. Setthis parameter toFALSE if presolve should be turned offfor the LP/QCQP problems.

solver.options.criterion

list, each item of the list shouldcorrespond to an option specific to the solver selected. Theseoptions are specific for finding the minimum criterion.

solver.options.bounds

list, each item of the list shouldcorrespond to an option specific to the solver selected. Theseoptions are specific for finding the bounds.

rescale

boolean, set toTRUE if the MTR componentsshould be rescaled to improve stability in the LP/QCQPoptimization.

smallreturnlist

boolean, default set toFALSE. Set toTRUE to exclude large intermediary components(i.e. propensity score model, LP/QCQP model, bootstrapiterations) from being included in the return list.

noisy

boolean, default set toTRUE. IfTRUE,then messages are provided throughout the estimationprocedure. Set toFALSE to suppress all messages,e.g. when performing the bootstrap.

debug

boolean, indicates whether or not the function shouldprovide output when obtaining bounds. The option is onlyapplied whensolver = 'gurobi' orsolver ='rmosek'. The output provided is the same as what the GurobiAPI would send to the console.

Value

a list. Included in the list are estimates of the treatmenteffect bounds; the minimum violation of observationalequivalence of the set of IV-like estimands; the list ofmatrices and vectors defining the LP/QCQP problem; the points usedto generate the audit grid, and the points where the shapeconstraints were violated.

Examples

dtm <- ivmte:::gendistMosquito()## Declare empty list to be updated (in the event multiple IV like## specifications are providedsSet <- list()## Declare MTR formulasformula0 = ~ 1 + uformula1 = ~ 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))## If splines are interacted with other variables, the## 'interactSplines' should be used.## splinesList <- interactSplines(splinesobj = splinesList,##                               m0 = formula0,##                               m1 = formula1,##                               data = data,##                               uname = 'u')## Construct MTR polynomialspolynomials0 <- polyparse(formula = formula0,                 data = dtm,                 uname = u,                 as.function = FALSE)polynomials1 <- polyparse(formula = formula1,                 data = dtm,                 uname = u,                 as.function = FALSE)## Generate propensity score modelpropensityObj <- propensity(formula = d ~ z,                            data = dtm,                            link = "linear")## Generate IV estimatesivEstimates <- ivEstimate(formula = ey ~ d | z,                          data = dtm,                          components = l(intercept, d),                          treat = d,                          list = FALSE)## Generate target gamma momentstargetGamma <- 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 estimandssSet <- 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)## Perform audit procedure and return boundsaudit(data = dtm,      uname = u,      m0 = formula0,      m1 = formula1,      pm0 = polynomials0,      pm1 = polynomials1,      splinesobj = splinesList,      vars_data = colnames(dtm),      vars_mtr = "u",      terms_mtr0 = "u",      terms_mtr1 = "u",      sset = sSet$sset,      gstar0 = targetGamma$gstar0,      gstar1 = targetGamma$gstar1,      m0.inc = TRUE,      m1.dec = TRUE,      m0.lb = 0.2,      m1.ub = 0.8,      audit.max = 5,      solver = "lpSolveAPI")

Spline basis function of order 1

Description

This function is the splines basis function of order 1. Thisfunction was coded in accordance to Carl de Boor's set of notes onsplines, "B(asic)-Spline Basics".

Usage

bX(x, knots, i)

Arguments

x

vector, the values at which to evaluate the basisfunction.

knots

vector, the internal knots.

i

integer, the basis component to be evaluated.

Value

scalar.


Obtaining TE bounds

Description

This function estimates the bounds on the target treatmenteffect. The LP model must be passed as an environment variable,under the entry$model. SeelpSetup.

Usage

bound(  env,  sset,  solver,  solver.options,  noisy = FALSE,  smallreturnlist = FALSE,  rescale = FALSE,  debug = FALSE)

Arguments

env

environment containing the matrices defining the LPproblem.

sset

a list containing the point estimates and gammacomponents associated with each element in the S-set. Thisobject is only used to determine the names of terms. If it isno submitted, then no names are provided to the solutionvector.

solver

string, name of the package used to solve the LPproblem.

solver.options

list, each item of the list should correspondto an option specific to the LP solver selected.

noisy

boolean, set toTRUE if optimization resultsshould be displayed.

smallreturnlist

boolean, set toTRUE if the LP modelshould not be returned.

rescale

boolean, set toTRUE if the MTR componentsshould be rescaled to improve stability in the LP/QP/QCPoptimization.

debug

boolean, indicates whether or not the function shouldprovide output when obtaining bounds. The option is onlyapplied whensolver = 'gurobi' orsolver ='rmosek'. The output provided is the same as what the GurobiAPI would send to the console.

Value

a list containing the bounds on the treatment effect; thecoefficients on each term in the MTR associated with the upperand lower bounds, for both counterfactuals; the optimizationstatus to the maximization and minimization problems; the LPproblem that the optimizer solved.

Examples

dtm <- ivmte:::gendistMosquito()## Declare empty list to be updated (in the event multiple IV like## specifications are providedsSet <- list()## Declare MTR formulasformula0 = ~ 1 + uformula1 = ~ 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 polynomialspolynomials0 <- polyparse(formula = formula0,                          data = dtm,                          uname = u,                          as.function = FALSE)polynomials1 <- polyparse(formula = formula1,                          data = dtm,                          uname = u,                           as.function = FALSE)## Generate propensity score modelpropensityObj <- propensity(formula = d ~ z,                            data = dtm,                            link = "linear")## Generate IV estimatesivEstimates <- ivEstimate(formula = ey ~ d | z,                          data = dtm,                          components = l(intercept, d),                          treat = d,                          list = FALSE)## Generate target gamma momentstargetGamma <- 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 estimandssSet <- 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 requiredsSet <- sSet$sset## Define additional upper- and lower-bound constraints for the LP## problemA <- 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")

Construct confidence intervals for treatment effects under partialidentification

Description

This function constructs the forward and backward confidenceintervals for the treatment effect under partial identification.

Usage

boundCI(bounds, bounds.resamples, n, m, levels, type)

Arguments

bounds

vector, bounds of the treatment effects under partialidentification.

bounds.resamples

matrix, stacked bounds of the treatmenteffects under partial identification. Each row corresponds to asubset resampled from the original data set.

n

integer, size of original data set.

m

integer, size of resampled data sets.

levels

vector, real numbers between 0 and 1. Valuescorrespond to the level of the confidence intervals constructedvia bootstrap.

type

character. Set to 'forward' to construct the forwardconfidence interval for the treatment effect bounds. Set to'backward' to construct the backward confidence interval forthe treatment effect bounds. Set to 'both' to construct bothtypes of confidence intervals.

Value

iftype is 'forward' or 'backward', then thecorresponding type of confidence interval for each level isreturned. The output is in the form of a matrix, with each rowcorresponding to a level. Iftype is 'both', then a listis returned. One element of the list is the matrix of backwardconfidence intervals, and the other element of the list is thematrix of forward confidence intervals.


Construct p-values for treatment effects under partialidentification

Description

This function estimates the p-value for the treatment effect underpartial identification. p-values corresponding to forward andbackward confidence intervals can be returned.

Usage

boundPvalue(bounds, bounds.resamples, n, m, type)

Arguments

bounds

vector, bounds of the treatment effects under partialidentification.

bounds.resamples

matrix, stacked bounds of the treatmenteffects under partial identification. Each row corresponds to asubset resampled from the original data set.

n

integer, size of original data set.

m

integer, size of resampled data sets.

type

character. Set to 'forward' to construct the forwardconfidence interval for the treatment effect bounds. Set to'backward' to construct the backward confidence interval forthe treatment effect bounds. Set to 'both' to construct bothtypes of confidence intervals.

Value

Iftype is 'forward' or 'backward', a scalar p-valuecorresponding to the type of confidence interval isreturned. Iftype is 'both', a vector of p-valuescorresponding to the forward and backward confidence intervalsis returned.


Check polynomial form of the u-term

Description

This function ensures that the unobservable term enters into theMTR in the correct manner. That is, it enters as a polynomial.

Usage

checkU(formula, uname)

Arguments

formula

a formula.

uname

name of the unobserved variable.

Value

If the unobservable term is entered correctly into theformula, thenNULL is returned. Otherwise, the vector ofincorrect terms is returned.


Auxiliary function: test if object is a formula

Description

Auxiliary function to test if an object is a formula. Warnings aresuppressed.

Usage

classFormula(obj)

Arguments

obj

the object to be checked.

Value

boolean expression.


Auxiliary function: test if object is a list

Description

Auxiliary function to test if an object is a list. Warnings aresuppressed.

Usage

classList(obj)

Arguments

obj

the object to be checked.

Value

boolean expression.


Combining the boundedness and monotonicity constraint objects

Description

This function simply combines the objects associated with theboundedness constraints and the monotonicity constraints.

Usage

combinemonobound(bdA, monoA)

Arguments

bdA

list containing the constraint matrix, vector ofinequalities, and RHS vector associated with the boundednessconstraints.

monoA

list containing the constraint matrix, vector oninequalities, and RHS vector associated with the monotonicityconstraints.

Value

a list containing a unified constraint matrix, unifiedvector of inequalities, and unified RHS vector for theboundedness and monotonicity constraints of an LP/QCQP problem.


Construct constant function

Description

This function constructs another function that returns aconstant. It is used for constructing weight/knot functions.

Usage

constructConstant(x)

Arguments

x

scalar, the constant the function evaluates to.

Value

a function.


Minimizing violation of observational equivalence

Description

Given a set of IV-like estimates and the set of matrices/vectorsdefining an LP problem, this function minimizes the violation ofobservational equivalence under the L1 norm. The LP model must bepassed as an environment variable, under the entry$model.SeelpSetup.

Usage

criterionMin(env, sset, solver, solver.options, rescale = FALSE, debug = FALSE)

Arguments

env

environment containing the matrices defining the LPproblem.

sset

A list of IV-like estimates and the corresponding gammaterms.

solver

string, name of the package used to solve the LPproblem.

solver.options

list, each item of the list should correspondto an option specific to the LP solver selected.

rescale

boolean, set toTRUE if the MTR componentsshould be rescaled to improve stability in the LP/QP/QCPoptimization.

debug

boolean, indicates whether or not the function shouldprovide output when obtaining bounds. The option is onlyapplied whensolver = 'gurobi' orsolver ='rmosek'. The output provided is the same as what the GurobiAPI would send to the console.

Value

A list including the minimum violation of observationalequivalence, the solution to the LP problem, and the status ofthe solution.

Examples

dtm <- ivmte:::gendistMosquito()## Declare empty list to be updated (in the event multiple IV like## specifications are providedsSet <- list()## Declare MTR formulasformula0 = ~ 1 + uformula1 = ~ 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 polynomialspolynomials0 <- polyparse(formula = formula0,                          data = dtm,                          uname = u,                          as.function = FALSE)polynomials1 <- polyparse(formula = formula1,                          data = dtm,                          uname = u,                           as.function = FALSE)## Generate propensity score modelpropensityObj <- propensity(formula = d ~ z,                            data = dtm,                            link = "linear")## Generate IV estimatesivEstimates <- ivEstimate(formula = ey ~ d | z,                          data = dtm,                          components = l(intercept, d),                          treat = d,                          list = FALSE)## Generate target gamma momentstargetGamma <- 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 estimandssSet <- 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 requiredsSet <- 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 will minimize the criterionlpSetupCriterion(env = modelEnv,                sset = sSet)## Declare any LP solver options as a list.lpOptions <- optionsLpSolveAPI(list(epslevel = "tight"))## Minimize the criterion.obseqMin <- criterionMin(env = modelEnv,                         sset = sSet,                         solver = "lpsolveapi",                         solver.options = lpOptions)obseqMincat("The minimum criterion is",  obseqMin$obj, "\n")

Generating design matrices

Description

This function generates the design matrix given an IVspecification.

Usage

design(formula, data, subset, treat, orig.names)

Arguments

formula

Formula with which to generate the design matrix.

data

data.frame with which to generate the designmatrix.

subset

Condition to select subset of data.

treat

The name of the treatment variable. This should onlybe passed when constructing OLS weights.

orig.names

character vector of the terms in the final designmatrix. This is required when the user declares an IV-likeformula where the treatment variable is passed into thefactor function. Since the treatment variable has to befixed to 0 or 1, the design matrix will be unable to constructthe contrasts. The argumentorig.names is a vector ofthe terms in the IV-like specification prior to fixing thetreatment variable.

Value

Three matrices are returned: one for the outcome variable,Y; one for the second stage covariates, X; and one for thefirst stage covariates, Z.

Examples

dtm <- ivmte:::gendistMosquito()design(formula = ey ~ d | z,           data = dtm,           subset = z %in% c(1, 2))

Auxiliary function: extracting columns by component names

Description

Auxiliary function to extract columns from a matrix based on columnnames.

Usage

extractcols(M, components)

Arguments

M

The matrix to extract from.

components

The vector of variable names.


Format result for display

Description

This function simply takes a number and formats it for beingdisplayed. Numbers less than 1 in absolute value are rounded to 6significant figure. Numbers larger than

Usage

fmtResult(x)

Arguments

x

The scalar to be formated

Value

A scalar.


Evaluate a particular function

Description

This function evaluates a single function in a list of functions.

Usage

funEval(fun, values = NULL, argnames = NULL)

Arguments

fun

the function to be evaluated.

values

the values of the arguments to the function. Orderingis assumed to be the same as inargnames.

argnames

the argument names corresponding tovalues.

Value

the output of the function evaluated.


Generate basis matrix for splines

Description

The user can declare that the unobservable enters into the MTRs inthe form of splines. This function generates the basis matrix forthe splines. The specifications for the spline must be passed asthe$splineslist object generated byremoveSplines. Note that this function does notaccount for any interactions between the splines and thecovariates. Interactions can be added simply by sweeping the basismatrix by a vector for the values of the covariates.

Usage

genBasisSplines(splines, x, d = NULL)

Arguments

splines

a list. The name of each element should be thespline command, and each element should be a vector. Each entryof the vector is a covariate that the spline should beinteracted with. Such an object can be generated byremoveSplines, and accessed using$splineslist.

x

the values of the unobservable at which the splines basisshould be evaluated.

d

either 0 or 1, indicating the treatment status.

Value

a matrix. The number of rows is equal to the length ofx, and the number of columns depends on thespecifications of the spline. The name of each column takes thefollowing form: "u[d]S[j].[b]", where "u" and "S" are fixed andstand for "unobservable" and "Splines" respectively. "[d]" willbe either 0 or 1, depending on the treatment status. "[j]" willbe an integer indicating which element of the listsplines the column pertains to. "[b]" will be an integerreflect which component of the basis the column pertains to.


Estimating expectations of terms in the MTR (gamma objects)

Description

This function generates the gamma objects defined in the paper,i.e. each additive term in E[md], where md is a MTR.

Usage

genGamma(  monomials,  lb,  ub,  multiplier = 1,  subset = NULL,  means = TRUE,  late.rows = NULL)

Arguments

monomials

[UPDATE DESCRIPTION] object containing list oflist of monomials. Each element of the outer list represents anobservation in the data set, each element in the inner list isa monomial from the MTR. The variable is the unobservable u,and the coefficient is the evaluation of any interactions withu.

lb

vector of lower bounds for the interval ofintegration. Each element corresponds to an observation.

ub

vector of upper bounds for the interval ofintegration. Each element corresponds to an observation.

multiplier

a vector of the weights that enter into theintegral. Each element corresponds to an observation.

subset

The row names/numbers of the subset of observationsto use.

means

logical, if TRUE then function returns the terms ofE[md]. If FALSE, then function instead returns each term ofE[md | D, X, Z]. This is useful for testing the code,i.e. obtaining population estimates.

late.rows

Boolean vector indicating which observations toinclude when conditioning on covariates X.

Value

Ifmeans = TRUE, then the function returns a vectorof the additive terms in Gamma (i.e. the expectation is over D,X, Z, and u). Ifmeans = FALSE, then the functionreturns a matrix, where each row corresponds to an observation,and each column corresponds to an additive term in E[md | D, X,Z] (i.e. only the integral with respect to u is performed).

Examples

dtm <- ivmte:::gendistMosquito()## Declare MTR formulaformula0 = ~ 1 + u## Construct MTR polynomialspolynomials0 <- polyparse(formula = formula0,                data = dtm,                uname = u,                as.function = FALSE)## Construct propensity score modelpropensityObj <- propensity(formula = d ~ z,                            data = dtm,                            link = "linear")## Generate gamma moments, with S-weight equal to its default value## of 1genGamma(monomials = polynomials0,         lb = 0,         ub = propensityObj$phat)

Generate Gamma moments for splines

Description

The user can declare that the unobservable enters into the MTRs inthe form of splines. This function generates the gamma moments forthe splines. The specifications for the spline must be passed as anelement generated byremoveSplines. This functionaccounts for the interaction between covariates and splines.

Usage

genGammaSplines(  splinesobj,  data,  lb,  ub,  multiplier = 1,  subset,  d = NULL,  means = TRUE,  late.rows = NULL)

Arguments

splinesobj

a list generated byremoveSplinesapplied to either them0 andm1 argument.

data

adata.frame object containing all the variablesthat interact with the spline components.

lb

vector of lower bounds for the interval ofintegration. Each element corresponds to an observation.

ub

vector of upper bounds for the interval ofintegration. Each element corresponds to an observation.

multiplier

a vector of the weights that enter into theintegral. Each element corresponds to an observation.

subset

Subset condition used to select observations withwhich to estimate gamma.

d

either 0 or 1, indicating the treatment status.

means

boolean, default set toTRUE. Set toTRUE if estimates of the gamma moments should bereturned. Set toFALSE if the gamma estimates for eachobservation should be returned.

late.rows

Boolean vector indicating which observations toinclude when conditioning on covariates X.

Value

a matrix, corresponding to the splines being integratedover the region specified bylb andub,accounting for the interaction terms. The number of rows isequal to the number of rows indata. The number ofcolumns depends on the specifications of the spline. The nameof each column takes the following form: "u[d]S[j].[b]", where"u" and "S" are fixed and stand for "unobservable" and"Splines" respectively. "[d]" will be either 0 or 1, dependingon the treatment status. "[j]" will be an integer indicatingwhich element of the listsplines the column pertainsto. "[b]" will be an integer reflect which component of thebasis the column pertains to.


Generating the Gamma moments for splines, for 'testthat'

Description

This function generates the Gamma moments for a given set ofweights. This funciton is written specifically for tests.

Usage

genGammaSplinesTT(distr, weight, zvars, u1s1, u0s1, u0s2, target = FALSE, ...)

Arguments

distr

data.frame, the distribution of the data.

weight

function, the S-function corresponding to aparticular IV-like estimand.

zvars

vector, string names of the covariates, other than theintercept and treatment variable.

u1s1

matrix, the spline basis for the treated group ("u1")corresponding to the first (and only) spline specification("s1").

u0s1

matrix, the spline basis for the control group ("u0")corresponding to the first spline specification ("s1").

u0s2

matrix, the spline basis for the control group ("u0")corresponding to the second spline specification ("s2").

target

boolean, set toTRUE if the gamma moment beinggenerated corresponds to the target parameter.

...

all other arguments that enter intoweight,excluding the argumentd for treatment indicator.

Value

vector, the Gamma moments associated withweight.


Function to generate gamma moments for 'testthat'

Description

This function generates the gamma moments from a population leveldata set. This is specifically constructed to carry out tests.

Usage

genGammaTT(data, s0, s1, lb, ub)

Arguments

data

data.table.

s0

variable name (contained in the data) for the S-weightused to generate the Gamma moments for the control group.

s1

variable name (contained in the data) for the S-weightused to generate the Gamma moments for the treated group.

lb

scalar, lower bound for integration.

ub

scalar, upper bound for integration.

Value

list, contains the vectors of the Gamma moments for controland treated observations.


Generating moments/data for IV-like estimands

Description

This function takes in the IV estimate and its IV-likespecification, and generates a list containing the correspondingIV-like point estimate, and the corresponding moments (gammas) thatwill enter into the constraint matrix of the LP problem. If theoptionmeans = FALSE, then the data are not averaged togenerate the gamma moments and may be used for GMM. The functionrequires the user to provide a list (i.e. the list the pointestimates and moments corresponding to other IV-likespecifications; or an empty list) to append these point estimatesand moments to.

Usage

genSSet(  data,  sset,  sest,  splinesobj,  pmodobj,  pm0,  pm1,  ncomponents,  scount,  subset_index,  means = TRUE,  yvar,  dvar,  noisy = TRUE,  ivn = NULL,  redundant = NULL)

Arguments

data

data.frame used to estimate the treatmenteffects.

sset

list, which is modified and returned as theoutput. This object will contain all the information from theIV-like specifications that can be used for estimating thetreatment effect.

sest

list containing the point estimates and S-weightscorresponding to a particular IV-like estimand.

splinesobj

list of spline components in the MTRs for treatedand control groups. Spline terms are extracted usingremoveSplines.

pmodobj

vector of propensity scores.

pm0

list of the monomials in the MTR for the control group.

pm1

list of the monomials in the MTR for the treated group.

ncomponents

The number of components from the IV regressionto include in the S-set.

scount

integer, an index for the elements in the S-set.

subset_index

vector of integers, a row index for the subset ofthe data the IV regression is restricted to.

means

boolean, set toTRUE by default. If set toTRUE, then the gamma moments are returned, i.e. sampleaverages are taken. If set toFALSE, then no sampleaverages are taken, and a matrix is returned. The sampleaverage of each column of the matrix corresponds to aparticular gamma moment.

yvar

name of outcome variable. This is only used ifmeans = FALSE, which occurs when the user believes thetreatment effect is point identified.

dvar

name of treatment indicator. This is only used ifmeans = FALSE, which occurs when the user believes thetreatment effect is point identified.

noisy

boolean, default set toTRUE. IfTRUE,then messages are provided throughout the estimationprocedure. Set toFALSE to suppress all messages,e.g. when performing the bootstrap.

ivn

integer, the number indicating which IV specificationthe component corresponds to.

redundant

vector of integers indicating which components inthe S-set are redundant.

Value

A list containing the point estimate for the IV regression,and the expectation of each monomial term in the MTR.

Examples

dtm <- ivmte:::gendistMosquito()## Declare empty list to be updated (in the event multiple IV like## specifications are provided)sSet <- list()## Declare MTR formulasformula1 = ~ 1 + uformula0 = ~ 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 polynomialspolynomials0 <- polyparse(formula = formula0,                 data = dtm,                 uname = u,                 as.function = FALSE)polynomials1 <- polyparse(formula = formula0,                 data = dtm,                 uname = u,                 as.function = FALSE)## Generate propensity score modelpropensityObj <- propensity(formula = d ~ z,                            data = dtm,                            link = "linear")## Generate IV estimatesivEstimates <- ivEstimate(formula = ey ~ d | z,                          data = dtm,                          components = l(d),                          treat = d,                          list = FALSE)## Construct S-set, which contains the coefficients and weights## corresponding to various IV-like estimandsgenSSet(data = dtm,        sset = sSet,        sest = ivEstimates,        splinesobj = splinesList,        pmodobj = propensityObj$phat,        pm0 = polynomials0,        pm1 = polynomials1,        ncomponents = 1,        scount = 1)

Generating target MTR moments

Description

This function estimates the moment of each MTR term under thetarget weight.

Usage

genTarget(  treat,  m0,  m1,  target,  target.weight0,  target.weight1,  target.knots0,  target.knots1,  late.Z,  late.from,  late.to,  late.X,  eval.X,  genlate.lb,  genlate.ub,  data,  splinesobj,  pmodobj,  pm0,  pm1,  noisy = TRUE)

Arguments

treat

variable name for treatment indicator. The name can beprovided with or without quotation marks.

m0

one-sided formula for the marginal treatment responsefunction for the control group. Splines may also beincorporated using the expressionuSpline, e.g.uSpline(degree = 2, knots = c(0.4, 0.8), intercept =TRUE). Theintercept argument may be omitted, and isset toTRUE by default.

m1

one-sided formula for the marginal treatment responsefunction for the treated group. Seem0 for details.

target

character, target parameter to be estimated. Thefunction allows for ATE ('ate'), ATT ('att'), ATU('atu'), LATE ('late'), and generalized LATE('genlate').

target.weight0

user-defined weight function for the controlgroup defining the target parameter. A list of functions can besubmitted if the weighting function is in fact a spline. Thearguments of the function should be variable names indata. If the weight is constant across all observations,then the user can instead submit the value of the weightinstead of a function.

target.weight1

user-defined weight function for the treatedgroup defining the target parameter. Seetarget.weight0for details.

target.knots0

user-defined set of functions defining theknots associated with spline weights for the control group. Thearguments of the function should consist only of variable namesindata. If the knots are constant across allobservations, then the user can instead submit the vector ofknots instead of a function.

target.knots1

user-defined set of functions defining theknots associated with spline weights for the treated group. Seetarget.knots0 for details.

late.Z

vector of variable names used to define the LATE.

late.from

baseline set of values of Z used to define theLATE.

late.to

comparison set of values of Z used to define theLATE.

late.X

vector of variable names of covariates to conditionon when defining the LATE.

eval.X

numeric vector of the values to condition variablesinlate.X on when estimating the LATE.

genlate.lb

lower bound value of unobservableu forestimating the generalized LATE.

genlate.ub

upper bound value of unobservableu forestimating the generalized LATE.

data

data.frame ordata.table used to estimatethe treatment effects.

splinesobj

list of spline components in the MTRs for treatedand control groups. Spline terms are extracted usingremoveSplines. This object is supposed to be adictionary of splines, containing the original calls of eachspline in the MTRs, their specifications, and the index usedfor naming each basis spline.

pmodobj

A vector of propensity scores.

pm0

A list of the monomials in the MTR for d = 0.

pm1

A list of the monomials in the MTR for d = 1.

noisy

boolean, default set toTRUE. IfTRUE,then messages are provided throughout the estimationprocedure. Set toFALSE to suppress all messages,e.g. when performing the bootstrap.

Value

A list containing either the vectors of gamma moments forD = 0 andD = 1, or a matrix of individual gammavalues forD = 0 andD = 1. Additoinally, twovectors are returned.xindex0 andxindex1 listthe variables that interact with the unobservableu inm0 andm1.uexporder0 anduexporder1 lists the exponents of the unobservableu in each term it appears in.

Examples

dtm <- ivmte:::gendistMosquito()## Declare MTR functionsformula1 = ~ 1 + uformula0 = ~ 1 + usplinesList = list(removeSplines(formula0), removeSplines(formula1))## Declare propensity score modelpropensityObj <- propensity(formula = d ~ z,                            data = dtm,                            link = "linear")## Construct MTR polynomialspolynomials0 <- polyparse(formula = formula0,                 data = dtm,                 uname = u,                 as.function = FALSE)polynomials1 <- polyparse(formula = formula0,                 data = dtm,                 uname = u,                 as.function = FALSE)## Generate target gamma momentsgenTarget(treat = "d",          m0 = ~ 1 + u,          m1 = ~ 1 + u,          target = "atu",          data = dtm,          splinesobj = splinesList,          pmodobj = propensityObj,          pm0 = polynomials0,          pm1 = polynomials1)

Generating list of target weight functions

Description

This function takes in the user-defined target weight functions andthe data set, and generates the weight functions for eachobservation.

Usage

genWeight(fun, fun.name, uname, data)

Arguments

fun

custom weight function defined by the user. Arguments ofthe weight function must only be names of variables enteringinto the function, and can include the unobserved variable.

fun.name

string, name of function.

uname

the name assigned to the unobserved variable enteringinto the MTR.

data

a named vector containing the values of the variablesdefining the 'fun', excluding the value of the unobservable(generated from applying split() to a data.frame).

Value

The weight function 'fun', where all arguments other thanthat of the unobserved variable are fixed according to thevector 'data'.


Generating the constraint matrix

Description

This function generates the component of the constraint matrix inthe LP/QCQP problem pertaining to the lower and upper bounds on the MTRsand MTEs. These bounds are declared by the user.

Usage

genboundA(  A0,  A1,  sset,  gridobj,  uname,  m0.lb,  m0.ub,  m1.lb,  m1.ub,  mte.lb,  mte.ub,  solution.m0.min = NULL,  solution.m1.min = NULL,  solution.m0.max = NULL,  solution.m1.max = NULL,  audit.tol,  direct = FALSE)

Arguments

A0

the matrix of values from evaluating the MTR for controlobservations over the grid generated to perform the audit. Thismatrix will be incorporated into the final constraint matrixfor the bounds.

A1

the matrix of values from evaluating the MTR for controlobservations over the grid generated to perform the audit. Thismatrix will be incorporated into the final constraint matrixfor the bounds.

sset

a list containing the point estimates and gammacomponents associated with each element in the S-set.

gridobj

a list containing the grid over which themonotonicity and boundedness conditions are imposed on.

uname

name declared by user to represent the unobservableterm.

m0.lb

scalar, lower bound on MTR for control group.

m0.ub

scalar, upper bound on MTR for control group.

m1.lb

scalar, lower bound on MTR for treated group.

m1.ub

scalar, upper bound on MTR for treated group.

mte.lb

scalar, lower bound on MTE.

mte.ub

scalar, upper bound on MTE.

solution.m0.min

vector, the coefficients for the MTR forD = 0 corresponding to the lower bound of the targetparameter. If passed, this will initiate checks of shapeconstraints.

solution.m1.min

vector, the coefficients for the MTR forD = 1 corresponding to the lower bound of the targetparameter. If passed, this will initiate checks of shapeconstraints.

solution.m0.max

vector, the coefficients for the MTR forD = 0 corresponding to the upper bound of the targetparameter. If passed, this will initiate checks of shapeconstraints.

solution.m1.max

vector, the coefficients for the MTR forD = 1 corresponding to the upper bound of the targetparameter. If passed, this will initiate checks of shapeconstraints.

audit.tol

feasibility tolerance when performing theaudit. By default to set to be equal1e-06. Thisparameter should only be changed if the feasibility toleranceof the solver is changed, or if numerical issues result indiscrepancies between the solver's feasibility check and theaudit.

direct

boolean, set toTRUE if the direct MTRregression is used.

Value

a constraint matrix for the LP/QCQP problem, the associatedvector of inequalities, and the RHS vector in the inequalityconstraint. The objects pertain only to the boundednessconstraints declared by the user.


Generate test distribution 1

Description

This function generates a data set for testing purposes. There is asingle instrument that takes on values of 1 or 2, and thedistribution of the values for the binary instrument isuniform. The MTRs are m0 ~ 0 + u and m1 ~ 1 + u. All unobservablesu are integrated out.

Usage

gendist1(subN = 5, p1 = 0.4, p2 = 0.6)

Arguments

subN

integer, default set to 5. This is the number ofindividuals possessing each value of the instrument. So thetotal number of observations is subN * 2.

p1

the probability of treatment for those with theinstrument Z = 1.

p2

the probability of treatment for those with theinstrument Z = 2.

Value

a data.frame.


Generate test distribution 1 with errors

Description

This function generates a data set for testing purposes. There is asingle instrument that takes on values of 1 or 2, and thedistribution of the values for the binary instrument isuniform. The MTRs are m0 ~ 0 + u and m1 ~ 1 + u.

Usage

gendist1e(N = 100, subN = 0.5, p1 = 0.4, p2 = 0.6, v0.sd = 0.5, v1.sd = 0.75)

Arguments

N

integer, default set to 100. Total number of observationsin the data.

subN

, default set to 0.5. This is the probability the agentwill have Z = 1.

p1

the probability of treatment for those with theinstrument Z = 1.

p2

the probability of treatment for those with theinstrument Z = 2.

v0.sd

numeric, standard deviation of error term forcounterfactualD = 0

v1.sd

numeric, standard deviation of error term forcounterfactualD = 1

Value

a data.frame.


Generate test distribution 2

Description

This function generates a data set for testing purposes. There is asingle instrument that takes on values of 1, 2, or 3, and thedistribution of the values for the binary instrument isuniform. The MTRs are m0 ~ 1 + u and m1 ~ 1 + u. All unobservablesu are integrated out.

Usage

gendist2(subN = 5, p1 = 0.4, p2 = 0.6, p3 = 0.8)

Arguments

subN

integer, default set to 5. This is the number ofindividuals possessing each value of the instrument. So thetotal number of observations is subN * 2.

p1

the probability of treatment for those with theinstrument Z = 1.

p2

the probability of treatment for those with theinstrument Z = 2.

p3

the probability of treatment for those with theinstrument Z = 3.

Value

a data.frame.


Generate test distribution 3

Description

This function generates a data set for testing purposes. There is asingle instrument that takes on values of 1 and 2, and thedistribution of the values for the binary instrument isuniform. The MTRs are m0 ~ 1 and m1 ~ 1. All unobservables u areintegrated out.

Usage

gendist3(subN = 5, p1 = 0.4, p2 = 0.6)

Arguments

subN

integer, default set to 5. This is the number ofindividuals possessing each value of the instrument. So thetotal number of observations is subN * 2.

p1

the probability of treatment for those with theinstrument Z = 1.

p2

the probability of treatment for those with theinstrument Z = 2.

Value

a data.frame.


Generate test distribution 3 with errors

Description

This function generates a data set for testing purposes. There is asingle instrument that takes on values of 1 or 2, and thedistribution of the values for the binary instrument isuniform. The MTRs are m0 ~ 0 + u and m1 ~ 1 + u.

Usage

gendist3e(N = 100, subN = 0.5, p1 = 0.4, p2 = 0.6, v0.sd = 0.5, v1.sd = 0.75)

Arguments

N

integer, default set to 100. Total number of observationsin the data.

subN

, default set to 0.5. This is the probability the agentwill have Z = 1.

p1

the probability of treatment for those with theinstrument Z = 1.

p2

the probability of treatment for those with theinstrument Z = 2.

v0.sd

numeric, standard deviation of error term forcounterfactualD = 0

v1.sd

numeric, standard deviation of error term forcounterfactualD = 1

Value

a data.frame.


Generate test distribution 4

Description

This function generates a data set for testing purposes. There is asingle instrument that takes on values of 1, 2, and 3, and thedistribution of the values for the binary instrument isuniform. The MTRs are m0 ~ 1 and m1 ~ 1. All unobservables u areintegrated out.

Usage

gendist4(subN = 5, p1 = 0.4, p2 = 0.6, p3 = 0.8)

Arguments

subN

integer, default set to 5. This is the number ofindividuals possessing each value of the instrument. So thetotal number of observations is subN * 2.

p1

the probability of treatment for those with theinstrument Z = 1.

p2

the probability of treatment for those with theinstrument Z = 2.

p3

the probability of treatment for those with theinstrument Z = 3.

Value

a data.frame.


Generate test distribution 5 (has errors and a covariate)

Description

This function generates a data set for testing purposes. There is asingle instrument that takes on values of 1 or 2, and thedistribution of the values for the binary instrument isuniform. The MTRs are both of the form m ~ 1 + x + u.

Usage

gendist5e(N = 100, subN = 0.5, p1 = 0.4, p2 = 0.6, v0.sd = 1, v1.sd = 1.55)

Arguments

N

integer, default set to 100. Total number of observationsin the data.

subN

, default set to 0.5. This is the probability the agentwill have Z = 1.

p1

the probability of treatment for those with theinstrument Z = 1.

p2

the probability of treatment for those with theinstrument Z = 2.

v0.sd

numeric, standard deviation of error term forcounterfactualD = 0

v1.sd

numeric, standard deviation of error term forcounterfactualD = 1

Value

a data.frame.


Generate test distribution 6 (has errors and a covariate)

Description

This function generates a data set for testing purposes. There is asingle instrument that is uniformly distributed over [0, 1]. TheMTRs are both of the form m ~ 1 + x + x:u.

Usage

gendist6e(N = 100, v0.sd = 1, v1.sd = 1.55)

Arguments

N

integer, default set to 100. Total number of observationsin the data.

v0.sd

numeric, standard deviation of error term forcounterfactualD = 0

v1.sd

numeric, standard deviation of error term forcounterfactualD = 1

Value

a data.frame.


Generate basic data set for testing

Description

This code generates population level data to test the estimationfunction. This is a simpler dataset, one in which we can moreeasily estimate a correctly specified model. The data presentedbelow will have already integrated over the # unobservable termsU, where U | X, Z ~ Unif[0, 1].

Usage

gendistBasic()

Value

a list of two data.frame objects. One is the distributionof the simulated data, the other is the full simulated dataset.


Generate test data set with covariates

Description

This code generates population level data to test the estimationfunction. This data includes covariates. The data generated willhave already integrated over the unobservable terms U, where U | X,Z ~ Unif[0, 1].

Usage

gendistCovariates()

Value

a list of two data.frame objects. One is the distributionof the simulated data, the other is the full simulated dataset.


Generate mosquito data set

Description

This code generates the population level data in Mogstad, Santos,Torgovitsky (2018), i.e. the mosquito data set used as the runningexample.

Usage

gendistMosquito()

Value

data.frame.


Generate test data set with splines

Description

This code generates population level data to test theestimation function. This data set incorporates splines in theMTRs.

Usage

gendistSplines()

Details

The distribution of the data is as follows

| ZX/Z | 0 1_______|___________-1 | 0.1 0.1|X 0 | 0.2 0.2|1 | 0.1 0.2

The data presented below will have already integrated over theunobservable terms U, and U | X, Z ~ Unif[0, 1].

The propensity scores are generated according to the model

p(x, z) = 0.5 - 0.1 * x + 0.2 * z

| Zp(X,Z) | 0 1_______|___________-1 | 0.6 0.8|X 0 | 0.5 0.7|1 | 0.4 0.6

The lowest common multiple of the first table is 12. The lowestcommon multiple of the second table is 84. It turns out that 840 *5 = 4200 observations is enough to generate the population dataset, such that each group has a whole-number of observations.

The MTRs are defined as follows:

y1 ~ beta0 + beta1 * x + uSpline(degree = 2,knots = c(0.3, 0.6),intercept = FALSE)

The coefficients (beta1, beta2), and the coefficients on thesplines, will be defined below.

y0 = x : uSpline(degree = 0,knots = c(0.2, 0.5, 0.8),intercept = TRUE)+ uSpline(degree = 1,knots = c(0.4),intercept = TRUE)+ beta3 * I(u ^ 2)

The coefficient beta3, and the coefficients on the splines, will bedefined below.

Value

a list of two data.frame objects. One is the distributionof the simulated data, the other is the full simulated dataset.


Auxiliary function: generating basis vectors

Description

Auxiliary function to generate standard basis vectors.

Usage

genej(pos, length)

Arguments

pos

The position of the non-zero entry/dimension the basisvector corresponds to

length

Number of dimensions in total/length of vector.

Value

Vector containing 1 in a single position, and 0 elsewhere.


Generating the grid for the audit procedure

Description

This function takes in a matrix summarizing the support of thecovariates, as well as set of points summarizing the support of theunobservable variable. A Cartesian product of the subset of thesupport of the covariates and the points in the support of theunobservable generates the grid that is used for the auditprocedure.

Usage

gengrid(index, xsupport, usupport, uname)

Arguments

index

a vector whose elements indicate the rows in thematrixxsupport to include in the grid.

xsupport

a matrix containing all the unique combinations ofthe covariates included in the MTRs.

usupport

a vector of points in the interval [0, 1],including 0 and 1. The number of points is decided by theuser. The function generates these points using a Haltonsequence.

uname

name declared by user to represent the unobservableterm.

Value

a list containing the grid used in the audit; a vectormapping the elements in the support of the covariates toindex.


Generate components of the monotonicity constraints

Description

This function generates the matrix and vectors associated with themonotonicity constraints declared by the user. It takes in a gridof the covariates on which the shape constraints are defined, and thencalculates the values of the MTR and MTE over the grid. Thematrices characterizing the monotonicity conditions can then beobtained by taking first differences over the grid of theunobservable term, within each set of values in the grid ofcovariate values.

Usage

genmonoA(  A0,  A1,  sset,  uname,  gridobj,  gstar0,  gstar1,  m0.dec,  m0.inc,  m1.dec,  m1.inc,  mte.dec,  mte.inc,  solution.m0.min = NULL,  solution.m1.min = NULL,  solution.m0.max = NULL,  solution.m1.max = NULL,  audit.tol,  direct)

Arguments

A0

the matrix of values from evaluating the MTR for controlobservations over the grid generated to perform the audit. Thismatrix will be incorporated into the final constraint matrixfor the monotonicity conditions.

A1

the matrix of values from evaluating the MTR for controlobservations over the grid generated to perform the audit. Thismatrix will be incorporated into the final constraint matrixfor the monotonicity conditions.

sset

a list containing the point estimates and gammacomponents associated with each element in the S-set.

uname

Name of unobserved variable.

gridobj

a list containing the grid over which themonotonicity and boundedness conditions are imposed on.

gstar0

set of expectations for each terms of the MTR for thecontrol group.

gstar1

set of expectations for each terms of the MTR for thecontrol group.

m0.dec

boolean, indicating whether the MTR for the controlgroup is monotone decreasing.

m0.inc

boolean, indicating whether the MTR for the controlgroup is monotone increasing.

m1.dec

boolean, indicating whether the MTR for the treatedgroup is monotone decreasing.

m1.inc

boolean, indicating whether the MTR for the treatedgroup is monotone increasing.

mte.dec

boolean, indicating whether the MTE is monotonedecreasing.

mte.inc

boolean, indicating whether the MTE is monotoneincreasing.

solution.m0.min

vector, the coefficients for the MTR forD = 0 corresponding to the lower bound of the targetparameter. If passed, this will initiate checks of shapeconstraints.

solution.m1.min

vector, the coefficients for the MTR forD = 1 corresponding to the lower bound of the targetparameter. If passed, this will initiate checks of shapeconstraints.

solution.m0.max

vector, the coefficients for the MTR forD = 0 corresponding to the upper bound of the targetparameter. If passed, this will initiate checks of shapeconstraints.

solution.m1.max

vector, the coefficients for the MTR forD = 1 corresponding to the upper bound of the targetparameter. If passed, this will initiate checks of shapeconstraints.

audit.tol

feasibility tolerance when performing theaudit. By default to set to be equal1e-06. Thisparameter should only be changed if the feasibility toleranceof the solver is changed, or if numerical issues result indiscrepancies between the solver's feasibility check and theaudit.

direct

boolean, set toTRUE if the direct MTRregression is used.

Value

constraint matrix for the LP/QCQP problem. The matrix pertainsonly to the monotonicity conditions on the MTR and MTE declaredby the user.


Generating monotonicity and boundedness constraints

Description

This is a wrapper function generating the matrices and vectorsassociated with the monotonicity and boundedness constraintsdeclared by the user. Since this function generates all thecomponents required for the shape constraints, it is also thefunction that performs the audit. That is, MTR coefficients arepassed, then this function will verify whether they satisfy theshape constraints.

Usage

genmonoboundA(  pm0,  pm1,  support,  grid_index,  uvec,  splinesobj,  monov,  uname,  m0,  m1,  sset,  gstar0,  gstar1,  m0.lb,  m0.ub,  m1.lb,  m1.ub,  mte.lb,  mte.ub,  m0.dec,  m0.inc,  m1.dec,  m1.inc,  mte.dec,  mte.inc,  solution.m0.min = NULL,  solution.m1.min = NULL,  solution.m0.max = NULL,  solution.m1.max = NULL,  audit.tol,  direct)

Arguments

pm0

A list of the monomials in the MTR for d = 0.

pm1

A list of the monomials in the MTR for d = 1.

support

a matrix for the support of all variables that enterinto the MTRs.

grid_index

a vector, the row numbers ofsupport usedto generate the grid preceding the audit.

uvec

a vector, the points in the interval [0, 1] that theunobservable takes on.

splinesobj

a list of lists. Each of the inner lists containsdetails on the splines declared in the MTRs.

monov

name of variable for which the monotonicity conditionsapplies to.

uname

name declared by user to represent the unobservableterm in the MTRs.

m0

one-sided formula for marginal treatment responsefunction for the control group. The formula may differ fromwhat the user originally input inivmte, as thespline components should have been removed. This formula issimply a linear combination of all covariates that enter intothe originalm0 declared by the user inivmte.

m1

one-sided formula for marginal treatment responsefunction for the treated group. The formula may differ fromwhat the user originally input inivmte, as thespline components should have been removed. This formula issimply a linear combination of all covariates that enter intothe originalm1 declared by the user inivmte.

sset

a list containing the point estimates and gammacomponents associated with each element in the S-set.

gstar0

set of expectations for each terms of the MTR for thecontrol group.

gstar1

set of expectations for each terms of the MTR for thecontrol group.

m0.lb

scalar, lower bound on MTR for control group.

m0.ub

scalar, upper bound on MTR for control group.

m1.lb

scalar, lower bound on MTR for treated group.

m1.ub

scalar, upper bound on MTR for treated group.

mte.lb

scalar, lower bound on MTE.

mte.ub

scalar, upper bound on MTE.

m0.dec

boolean, indicating whether the MTR for the controlgroup is monotone decreasing.

m0.inc

boolean, indicating whether the MTR for the controlgroup is monotone increasing.

m1.dec

boolean, indicating whether the MTR for the treatedgroup is monotone decreasing.

m1.inc

boolean, indicating whether the MTR for the treatedgroup is monotone increasing.

mte.dec

boolean, indicating whether the MTE is monotonedecreasing.

mte.inc

boolean, indicating whether the MTE is monotoneincreasing.

solution.m0.min

vector, the coefficients for the MTR forD = 0 corresponding to the lower bound of the targetparameter. If passed, this will initiate checks of shapeconstraints.

solution.m1.min

vector, the coefficients for the MTR forD = 1 corresponding to the lower bound of the targetparameter. If passed, this will initiate checks of shapeconstraints.

solution.m0.max

vector, the coefficients for the MTR forD = 0 corresponding to the upper bound of the targetparameter. If passed, this will initiate checks of shapeconstraints.

solution.m1.max

vector, the coefficients for the MTR forD = 1 corresponding to the upper bound of the targetparameter. If passed, this will initiate checks of shapeconstraints.

audit.tol

feasibility tolerance when performing theaudit. By default to set to be equal1e-06. Thisparameter should only be changed if the feasibility toleranceof the solver is changed, or if numerical issues result indiscrepancies between the solver's feasibility check and theaudit.

direct

boolean, set toTRUE if the direct MTRregression is used.

Value

a list containing a unified constraint matrix, unifiedvector of inequalities, and unified RHS vector for theboundedness and monotonicity constraints of an LP/QCQP problem.


Auxiliary function: extract X and Z covariates from a formula

Description

Auxiliary function that takes in a two-sided formula, and extractsthe variable names of either the covariates or instruments. Thefunction returns an error if the formula includes a variable called'intercept'.

Usage

getXZ(fm, inst = FALSE, terms = FALSE, components = FALSE)

Arguments

fm

the formula.

inst

boolean expression, set to TRUE if the instrument namesare to be extracted. Otherwise, the covariate names areextracted.

terms

boolean expression, set to TRUE if the terms in theformulafm should be returned instead of the variablenames.

components

boolean expression, set to FALSE bydefault. Indicates that the formula being considered isconstructed from a list of components, and thus the term'intercept' is permitted.

Value

vector of variable names.


GMM estimate of TE under point identification

Description

If the user sets the argumentpoint = TRUE in the functionivmte, then it is assumed that the treatment effectparameter is point identified. The observational equivalencecondition is then set up as a two-step GMM problem. Solving thisGMM problem recovers the coefficients on the MTR functions m0 andm1. Combining these coefficients with the target gamma momentsallows one to estimate the target treatment effect.

Usage

gmmEstimate(  sset,  gstar0,  gstar1,  center = NULL,  subsetList = NULL,  n = NULL,  redundant = NULL,  identity = FALSE,  nMoments,  splines,  noisy = TRUE)

Arguments

sset

a list of lists constructed from the functiongenSSet. Each inner list should include a coefficientcorresponding to a term in an IV specification, a matrix of theestimates of the gamma moments conditional on (X, Z) for thecontrol group, and a matrix of the estimates of the gammamoments conditional on (X, Z) for the treated group. The columnmeans of the last two matrices is what is used to generate thegamma moments.

gstar0

vector, the target gamma moments for the controlgroup.

gstar1

vector, the target gamma moments for the treatedgroup.

center

numeric, the GMM moment equations from the originalsample. When bootstrapping, the solution to the pointidentified case obtained from the original sample can be passedthrough this argument to recenter the bootstrap distribution ofthe J-statistic.

subsetList

list of subset indexes, one for each IV-likespecification.

n

number of observations in the data. This option is onlyused when subsetting is involved.

redundant

vector of integers indicating which components inthe S-set are redundant.

identity

boolean, default set toFALSE. Set toTRUE if GMM point estimate should use the identityweighting matrix (i.e. one-step GMM).

nMoments

number of linearly independent moments. This optionis used to determine the cause of underidentified cases.

splines

boolean, set toTRUE if the MTRs involvesplines. This option is used to determine the cause ofunderidentified cases.

noisy

boolean, default set toTRUE. IfTRUE,then messages are provided throughout the estimationprocedure. Set toFALSE to suppress all messages,e.g. when performing the bootstrap.

Value

a list containing the point estimate of the treatmenteffects, and the MTR coefficient estimates. The momentconditions evaluated at the solution are also returned, alongwith the J-test results. However, if the optioncenteris passed, then the moment conditions and J-test are centered(this is to perform the J-test via bootstrap).

Examples

dtm <- ivmte:::gendistMosquito()## Declare empty list to be updated (in the event multiple IV like## specifications are providedsSet <- list()## Declare MTR formulasformula1 = ~ 0 + uformula0 = ~ 0 + 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 polynomialspolynomials0 <- polyparse(formula = formula0,                 data = dtm,                 uname = u,                 as.function = FALSE)polynomials1 <- polyparse(formula = formula0,                 data = dtm,                 uname = u,                 as.function = FALSE)## Generate propensity score modelpropensityObj <- propensity(formula = d ~ z,                            data = dtm,                            link = "linear")## Generate IV estimatesivEstimates <- ivEstimate(formula = ey ~ d | z,                          data = dtm,                          components = l(intercept, d),                          treat = d,                          list = FALSE)## Generate target gamma momentstargetGamma <- 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 estimandssSet <- 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 = FALSE)## Obtain point estimates using GMMgmmEstimate(sset = sSet$sset,            gstar0 = targetGamma$gstar0,            gstar1 = targetGamma$gstar1)

Update splines object with list of interactions

Description

Certain interactions between factor variables and splines should bedropped to avoid collinearity. Albeit collinearity in the MTRspecification will not impact the bounds, it can substantiallyimpact how costly it is to carry out the estimation. What thisfunction does is map each spline to a temporary variable. A designmatrix is then constructed using these temporary variables in placethe splines. If an interaction involving one of the temporaryvariables is dropped, then one knows to also drop the correspondinginteraction with the spline. Note that only interaction terms needto be omitted, so one does not need to worry about the formulacontained in removeSplines$formula.

Usage

interactSplines(splinesobj, m0, m1, data, uname)

Arguments

splinesobj

list, consists of two elelments. The first isremoveSplines(m0), the second isremoveSplines(m1).

m0

one-sided formula for the marginal treatment responsefunction for the control group. This should be the full MTRspecificaiton (i.e. not the specification after removing thesplines).

m1

one-sided formula for the marginal treatment responsefunction for the treated group. This should be the full MTRspecificaiton (i.e. not the specification after removing thesplines).

data

data.frame, restricted to complete observations.

uname

string, name of the unobserved variable.

Value

An updated version ofsplinesobj.


Auxiliary function: check if string is command

Description

Auxiliary function to check if a string is in fact a command, butin string form.

Usage

isfunctionstring(string)

Arguments

string

the string object to be checked.

Value

boolean expression.


Obtaining IV-like specifications

Description

This function estimates the IV-like estimands, as well as generatesthe weights associated with the IV-like specifications.

Usage

ivEstimate(  formula,  data,  subset,  components,  treat,  list = FALSE,  order = NULL)

Arguments

formula

formula to be estimated using OLS/IV.

data

data.frame with which to perform the estimation.

subset

subset condition with which to perform the estimate.

components

vector of variable names whose coefficients wewant to include in the set of IV-like estimands.

treat

name of treatment indicator variable.

list

logical, set to TRUE if this function is being used toloop over a list of formulas.

order

integer, default set toNULL. This is simply anindex of which IV-like specification the estimate correspondsto.

Value

Returns a list containing the matrices of IV-likespecifications forD = 0 andD = 1; and theestimates of the IV-like estimands.

Examples

dtm <- ivmte:::gendistMosquito()ivEstimate(formula = ey ~ d | z,           data = dtm,           components = l(d),           treat = d,           list = FALSE)

Instrumental Variables: Extrapolation by Marginal Treatment Effects

Description

This function provides a general framework for using the marginaltreatment effect (MTE) to extrapolate. The model is the same binarytreatment instrumental variable (IV) model considered by Imbens andAngrist (1994) (doi:10.2307/2951620) and Heckman and Vytlacil(2005) (doi:10.1111/j.1468-0262.2005.00594.x). The framework onwhich this function is based was developed by Mogstad, Santos andTorgovitsky (2018) (doi:10.3982/ECTA15463). See also the recentsurvey paper on extrapolation in IV models by Mogstad andTorgovitsky (2018)(doi:10.1146/annurev-economics-101617-041813). A detaileddescription of the module and its features can be found inSheaand Torgovitsky (2021).

Usage

ivmte(  data,  target,  late.from,  late.to,  late.X,  genlate.lb,  genlate.ub,  target.weight0 = NULL,  target.weight1 = NULL,  target.knots0 = NULL,  target.knots1 = NULL,  m0,  m1,  uname = u,  m1.ub,  m0.ub,  m1.lb,  m0.lb,  mte.ub,  mte.lb,  m0.dec,  m0.inc,  m1.dec,  m1.inc,  mte.dec,  mte.inc,  equal.coef,  ivlike,  components,  subset,  propensity,  link = "logit",  treat,  outcome,  solver,  solver.options,  solver.presolve,  solver.options.criterion,  solver.options.bounds,  lpsolver,  lpsolver.options,  lpsolver.presolve,  lpsolver.options.criterion,  lpsolver.options.bounds,  criterion.tol = 1e-04,  initgrid.nx = 20,  initgrid.nu = 20,  audit.nx = 2500,  audit.nu = 25,  audit.add = 100,  audit.max = 25,  audit.tol,  rescale,  point,  point.eyeweight = FALSE,  bootstraps = 0,  bootstraps.m,  bootstraps.replace = TRUE,  levels = c(0.99, 0.95, 0.9),  ci.type = "backward",  specification.test = TRUE,  noisy = FALSE,  smallreturnlist = FALSE,  debug = FALSE)

Arguments

data

data.frame ordata.table used to estimatethe treatment effects.

target

character, target parameter to be estimated. Thefunction allows for ATE ('ate'), ATT ('att'), ATU('atu'), LATE ('late'), and generalized LATE('genlate').

late.from

a named vector or a list declaring the baselinevalues of Z used to define the LATE. The name associated witheach value should be the name of the corresponding variable.

late.to

a named vector or a list declaring the comparisonset of values of Z used to define the LATE. The name associatedwith each value should be the name of the correspondingvariable.

late.X

a named vector or a list declaring the values tocondition on. The name associated with each value should be thename of the corresponding variable.

genlate.lb

lower bound value of unobservableu forestimating the generalized LATE.

genlate.ub

upper bound value of unobservableu forestimating the generalized LATE.

target.weight0

user-defined weight function for the controlgroup defining the target parameter. A list of functions can besubmitted if the weighting function is in fact a spline. Thearguments of the function should be variable names indata. If the weight is constant across all observations,then the user can instead submit the value of the weightinstead of a function.

target.weight1

user-defined weight function for the treatedgroup defining the target parameter. Seetarget.weight0for details.

target.knots0

user-defined set of functions defining theknots associated with spline weights for the control group. Thearguments of the function should consist only of variable namesindata. If the knots are constant across allobservations, then the user can instead submit the vector ofknots instead of a function.

target.knots1

user-defined set of functions defining theknots associated with spline weights for the treated group. Seetarget.knots0 for details.

m0

one-sided formula for the marginal treatment responsefunction for the control group. Splines may also beincorporated using the expressionuSpline, e.g.uSpline(degree = 2, knots = c(0.4, 0.8), intercept =TRUE). Theintercept argument may be omitted, and isset toTRUE by default.

m1

one-sided formula for the marginal treatment responsefunction for the treated group. Seem0 for details.

uname

variable name for the unobservable used in declaringthe MTRs. The name can be provided with or without quotationmarks.

m1.ub

numeric value for upper bound on MTR for the treatedgroup. By default, this will be set to the largest value of theobserved outcome in the estimation sample.

m0.ub

numeric value for upper bound on MTR for the controlgroup. By default, this will be set to the largest value of theobserved outcome in the estimation sample.

m1.lb

numeric value for lower bound on MTR for the treatedgroup. By default, this will be set to the smallest value ofthe observed outcome in the estimation sample.

m0.lb

numeric value for lower bound on MTR for the controlgroup. By default, this will be set to the smallest value ofthe observed outcome in the estimation sample.

mte.ub

numeric value for upper bound on treatment effectparameter of interest.

mte.lb

numeric value for lower bound on treatment effectparameter of interest.

m0.dec

logical, set toFALSE by default. Set equal toTRUE if the MTR for the control group should be weaklymonotone decreasing.

m0.inc

logical, set toFALSE by default. Set equal toTRUE if the MTR for the control group should be weaklymonotone increasing.

m1.dec

logical, set toFALSE by default. Set equal toTRUE if the MTR for the treated group should be weaklymonotone decreasing.

m1.inc

logical, set toFALSE by default. Set equal toTRUE if the MTR for the treated group should be weaklymonotone increasing.

mte.dec

logical, set toFALSE by default. Set equaltoTRUE if the MTE should be weakly monotone decreasing.

mte.inc

logical, set toFALSE by default. Set equaltoTRUE if the MTE should be weakly monotone increasing.

equal.coef

one-sided formula to indicate which terms inm0 andm1 should be constrained to have the samecoefficients. These terms therefore have no effect on the MTE.

ivlike

formula or vector of formulas specifying theregressions for the IV-like estimands. Which coefficients touse to define the constraints determining the treatment effectbounds (alternatively, the moments determining the treatmenteffect point estimate) can be selected in the argumentcomponents. If no argument is passed, then a linearregression will be performed to estimate the MTR coefficients.

components

a list of vectors of the terms in the regressionspecifications to include in the set of IV-like estimands. Noterms should be in quotes. To select the intercept term,include the nameintercept. If the factorizedcounterpart of a variable is included in the IV-likespecifications, e.g.factor(x) wherex = 1, 2, 3,the user can select the coefficients for specific factors bydeclaring the componentsfactor(x)-1, factor(x)-2,factor(x)-3. Seel on how to input theargument. If no components for a IV specification are given,then all coefficients from that IV specification will be usedto define constraints in the partially identified case, or todefine moments in the point identified case.

subset

a single subset condition or list of subsetconditions corresponding to each regression specified inivlike. The input must be logical. Seelon how to input the argument. If the user wishes to selectspecific rows, construct a binary variable in the data set, andset the condition to use only those observations for which thebinary variable is 1, e.g. the binary variable isuse,and the subset condition isuse == 1.

propensity

formula or variable name corresponding topropensity to take up treatment. If a formula is declared, thenthe function estimates the propensity score according to theformula and link specified inlink. If a variable nameis declared, then the corresponding column in the data is takenas the vector of propensity scores. A variable name can bepassed either as a string (e.gpropensity = 'p'), avariable (e.g.propensity = p), or a one-sided formula(e.g.propensity = ~p).

link

character, name of link function to estimate propensityscore. Can be chosen from'linear','probit', or'logit'. Default is set to'logit'. The linkshould be provided with quoation marks.

treat

variable name for treatment indicator. The name can beprovided with or without quotation marks.

outcome

variable name for outcome variable. The name can beprovided with or without quotation marks.

solver

character, name of the programming package in R usedto obtain the bounds on the treatment effect. The functionsupports'gurobi','cplexapi',rmosek,'lpsolveapi'. The name of the solver should be providedwith quotation marks.

solver.options

list, each item of the list should correspondto an option specific to the solver selected.

solver.presolve

boolean, default set toTRUE. Setthis parameter toFALSE if presolve should be turned offfor the LP/QCQP problems.

solver.options.criterion

list, each item of the list shouldcorrespond to an option specific to the solver selected. Theseoptions are specific for finding the minimum criterion.

solver.options.bounds

list, each item of the list shouldcorrespond to an option specific to the solver selected. Theseoptions are specific for finding the bounds.

lpsolver

character, deprecated argument forlpsolver.

lpsolver.options

list, deprecated argument forsolver.options.

lpsolver.presolve

boolean, deprecated argument forsolver.presolve.

lpsolver.options.criterion

list, deprecated argument forsolver.options.criterion.

lpsolver.options.bounds

list, deprecated argument forsolver.options.bounds.

criterion.tol

tolerance for the criterion function, and isset to 1e-4 by default. The criterion measures how well theIV-like moments/conditional means are matched using thel1-norm. Statistical noise may prohibit the theoretical LP/QCQPproblem from being feasible. That is, there may not exist a setof MTR coefficients that are able to match all the specifiedmoments. The function thus first estimates the minimumcriterion, which is reported in the output under the name'minimum criterion', with a criterion of 0 meaning that allmoments were able to be matched. The function then relaxes theconstraints by tolerating a criterion up tominimumcriterion * (1 + criterion.tol). Setcriterion.tol to avalue greater than 0 to allow for more conservative bounds.

initgrid.nx

integer determining the number of points of thecovariates used to form the initial constraint grid forimposing shape restrictions on the MTRs.

initgrid.nu

integer determining the number of points in theopen interval (0, 1) drawn from a Halton sequence. The endpoints 0 and 1 are additionally included. These points arealways a subset of the points defining the audit grid (seeaudit.nu). These points are used to form the initialconstraint grid for imposing shape restrictions on theucomponents of the MTRs.

audit.nx

integer determining the number of points on thecovariates space to audit in each iteration of the auditprocedure.

audit.nu

integer determining the number of points in theopen interval (0, 1) drawn from a Halton sequence. The endpoints 0 and 1 are additionally included. These points are usedto audit whether the shape restrictions on theucomponents of the MTRs are satisfied. The initial grid used toimpose the shape constraints in the LP/QCQP problem areconstructed from a subset of these points.

audit.add

maximum number of points to add to the initialconstraint grid for imposing each kind of shape constraint. Forexample, if there are 5 different kinds of shape constraints,there can be at mostaudit.add * 5 additional pointsadded to the constraint grid.

audit.max

maximum number of iterations in the auditprocedure.

audit.tol

feasibility tolerance when performing theaudit. By default to set to be 1e-06, which is equal to thedefault feasibility tolerances of Gurobi (solver ="gurobi"), CPLEX (solver = "cplexapi"), and Rmosek(solver = "rmosek"). This parameter should only bechanged if the feasibility tolerance of the solver is changed,or if numerical issues result in discrepancies between thesolver's feasibility check and the audit.

rescale

boolean, set toTRUE by default. Thisrescalels the MTR components to improve stability in theLP/QCQP optimization.

point

boolean. Set toTRUE if it is believed that thetreatment effects are point identified. If set toTRUEand IV-like formulas are passed, then a two-step GMM procedureis implemented to estimate the treatment effects. Shapeconstraints on the MTRs will be ignored under pointidentification. If set toTRUE and the regression-basedcriteria is used instead, then OLS will be used to estimate theMTR coefficients used to estimate the treatment effect. If notdeclared, then the function will determine whether or not thetarget parameter is point identified.

point.eyeweight

boolean, default set toFALSE. Set toTRUE if the GMM point estimate should use the identityweighting matrix (i.e. one-step GMM).

bootstraps

integer, default set to 0. This determines thenumber of bootstraps used to perform statistical inference.

bootstraps.m

integer, default set to size of dataset. Determines the size of the subsample drawn from theoriginal data set when performing inference via thebootstrap. This option applies only to the case of constructingconfidence intervals for treatment effect bounds, i.e. it doesnot apply whenpoint = TRUE.

bootstraps.replace

boolean, default set toTRUE. Thisdetermines whether the resampling procedure used for inferencewill sample with replacement.

levels

vector of real numbers between 0 and 1. Valuescorrespond to the level of the confidence intervals constructedvia bootstrap.

ci.type

character, default set to'both'. Set to'forward' to construct the forward confidence intervalfor the treatment effect bound. Set to'backward' toconstruct the backward confidence interval for the treatmenteffect bound. Set to'both' to construct both types ofconfidence intervals.

specification.test

boolean, default set toTRUE. Function performs a specification test for thepartially identified case whenbootstraps > 0.

noisy

boolean, default set toTRUE. IfTRUE,then messages are provided throughout the estimationprocedure. Set toFALSE to suppress all messages,e.g. when performing the bootstrap.

smallreturnlist

boolean, default set toFALSE. Set toTRUE to exclude large intermediary components(i.e. propensity score model, LP/QCQP model, bootstrapiterations) from being included in the return list.

debug

boolean, indicates whether or not the function shouldprovide output when obtaining bounds. The option is onlyapplied whensolver = 'gurobi' orsolver ='rmosek'. The output provided is the same as what the GurobiAPI would send to the console.

Details

When the function is used to estimate bounds, andstatistical inference is not performed, the function returnsthe following objects.

audit.count

the number of audits required until there wereno more violations; or the number of audits performed before the auditprocedure was terminated.

audit.criterion

the minimum criterion.

audit.grid

a list containing the points used to define the auditgrid, as well as a table of points where the shape constraints wereviolated.

bounds

a vector with the estimated lower and upper bounds ofthe target treatment effect.

call.options

a list containing all the model specifications andcall options generating the results.

gstar

a list containing the estimate of the weighted meansfor each component in the MTRs. The weights are determined by thetarget parameter declared intarget, or the weights definedbytarget.weight1,target.knots1,target.weight0,target.knots0.

gstar.coef

a list containing the coefficients on the treatedand control group MTRs.

gstar.weights

a list containing the target weights used toestimategstar.

result

a list containing the LP/QCQP model, and the full outputfrom solving the problem.

solver

the solver used in estimation.

moments

the number of elements in the S-set used to generateachieve (partial) identification.

propensity

the propensity score model. If a variable is fedto thepropensity argument when callingivmte, thenthe returned object is a list containing the name of variable givenby the user, and the values of that variable used in estimation.

s.set

a list of all the coefficient estimates and weightscorresponding to each element in the S-set.

splines.dict

a list including the specifications of eachspline declared in each MTR.

messages

a vector of character strings logging the output ofthe estimation procedure.

Ifbootstraps is greater than 0, then statistical inferencewill be performed and the output will additionally contain thefollowing objects.

bootstraps

the number of bootstraps.

bootstraps.failed

the number of bootstraps that failed (e.g.due to collinearity) and had to be repeated.

bounds.bootstraps

the estimates of the bounds from everybootstrap draw.

bounds.ci

forward and/or backward confidence intervals forthe bound estimates at the levels specified inlevels.

bounds.se

bootstrap standard errors on the lower and upperbound estimates.

p.value

p-value for the estimated bounds. p-values areconstructed by finding the level at which the confidence intervalno longer contains 0.

propensity.ci

confidence interval for coefficient estimatesof the propensity score model.

propensity.se

standard errors for the coefficient estimatesof the propensity score model.

specification.p.value

p-value from a specification test.The specification test is only performed if the minimum criterionis not 0.

Ifpoint = TRUE andbootstraps = 0, then pointestimation is performed using two-step GMM. The output will containthe following objects.

j.test

test statistic and results from the asymptotic J-test.

moments

a vector. Each element is the GMM criterion for eachmoment condition used in estimation.

mtr.coef

coefficient estimates for the MTRs.

point.estimate

point estimate of the treatment effect.

redundant

indexes for the moment conditions (i.e. elementsin the S set) that were linearly independent and could be dropped.

Ifpoint = TRUE andbootstraps is not 0, thenpoint estimation is performed using two-step GMM, and additionalstatistical inference is performed using the bootstrap samples.The output will contain the following additional objects.

bootstraps

the number of bootstraps.

bootstraps.failed

the number of bootstraps that failed (e.g.due to collinearity) and had to be repeated.

j.test

test statistic and result from the J-test performedusing the bootstrap samples.

j.test.bootstraps

J-test statistic from each bootstrap.

mtr.bootstraps

coefficient estimates for the MTRs fromeach bootstrap sample. These are used to construct the confidenceintervals and standard errors for the MTR coefficients.

mtr.ci

confidence intervals for each MTR coefficient.

mtr.se

standard errors for each MTR coefficient estimate.

p.value

p-value for the treatment effect point estimateestimated using the bootstrap.

point.estimate.bootstraps

treatment effect point estimatefrom each bootstrap sample. These are used to construct theconfidence interval, standard error, and p-value for the treatmenteffect.

point.estimate.ci

confidence interval for the treatmenteffect.

point.estimate.se

standard error for the treatment effectestimate.

propensity.ci

confidence interval for the coefficients inthe propensity score model, constructed using the bootstrap.

propensity.se

standard errors for the coefficient estimatesof the propensity score model.

Value

Returns a list of results from throughout the estimationprocedure. This includes all IV-like estimands; the propensityscore model; bounds on the treatment effect; the estimatedexpectations of each term in the MTRs; the components andresults of the LP/QCQP problem.

Examples

dtm <- ivmte:::gendistMosquito()ivlikespecs <- c(ey ~ d | z,                 ey ~ d | factor(z),                 ey ~ d,                 ey ~ d | factor(z))jvec <- l(d, d, d, d)svec <- l(, , , z %in% c(2, 4))ivmte(ivlike = ivlikespecs,      data = dtm,      components = jvec,      propensity = d ~ z,      subset = svec,      m0 = ~  u + I(u ^ 2),      m1 = ~  u + I(u ^ 2),      uname = u,      target = "att",      m0.dec = TRUE,      m1.dec = TRUE,      bootstraps = 0,      solver = "lpSolveAPI")

Single iteration of estimation procedure from Mogstad, Torgovitsky,Santos (2018)

Description

This function estimates the treatment effect parameters, followingthe procedure described in Mogstad, Santos and Torgovitsky (2018)(doi:10.3982/ECTA15463). A detailed description of the module andits features can be found inSheaand Torgovitsky (2021). However, this is not the main function ofthe module. Seeivmte for the main function. Forexamples of how to use the package, see the vignette, which isavailable on the module'sGitHub page.

Usage

ivmteEstimate(  data,  target,  late.Z,  late.from,  late.to,  late.X,  eval.X,  genlate.lb,  genlate.ub,  target.weight0,  target.weight1,  target.knots0 = NULL,  target.knots1 = NULL,  m0,  m1,  uname = u,  m1.ub,  m0.ub,  m1.lb,  m0.lb,  mte.ub,  mte.lb,  m0.dec,  m0.inc,  m1.dec,  m1.inc,  mte.dec,  mte.inc,  equal.coef,  ivlike,  components,  subset,  propensity,  link = "logit",  treat,  solver,  solver.options,  solver.presolve,  solver.options.criterion,  solver.options.bounds,  criterion.tol = 0.01,  initgrid.nx = 20,  initgrid.nu = 20,  audit.nx = 2500,  audit.nu = 25,  audit.add = 100,  audit.max = 25,  audit.tol,  audit.grid = NULL,  rescale = TRUE,  point = FALSE,  point.eyeweight = FALSE,  point.center = NULL,  point.redundant = NULL,  bootstrap = FALSE,  count.moments = TRUE,  orig.sset = NULL,  orig.criterion = NULL,  vars_y,  vars_mtr,  terms_mtr0,  terms_mtr1,  vars_data,  splinesobj,  splinesobj.equal,  noisy = TRUE,  smallreturnlist = FALSE,  debug = FALSE,  environments)

Arguments

data

data.frame ordata.table used to estimatethe treatment effects.

target

character, target parameter to be estimated. Thefunction allows for ATE ('ate'), ATT ('att'), ATU('atu'), LATE ('late'), and generalized LATE('genlate').

late.Z

vector of variable names used to define the LATE.

late.from

baseline set of values of Z used to define theLATE.

late.to

comparison set of values of Z used to define theLATE.

late.X

vector of variable names of covariates to conditionon when defining the LATE.

eval.X

numeric vector of the values to condition variablesinlate.X on when estimating the LATE.

genlate.lb

lower bound value of unobservableu forestimating the generalized LATE.

genlate.ub

upper bound value of unobservableu forestimating the generalized LATE.

target.weight0

user-defined weight function for the controlgroup defining the target parameter. A list of functions can besubmitted if the weighting function is in fact a spline. Thearguments of the function should be variable names indata. If the weight is constant across all observations,then the user can instead submit the value of the weightinstead of a function.

target.weight1

user-defined weight function for the treatedgroup defining the target parameter. Seetarget.weight0for details.

target.knots0

user-defined set of functions defining theknots associated with spline weights for the control group. Thearguments of the function should consist only of variable namesindata. If the knots are constant across allobservations, then the user can instead submit the vector ofknots instead of a function.

target.knots1

user-defined set of functions defining theknots associated with spline weights for the treated group. Seetarget.knots0 for details.

m0

one-sided formula for the marginal treatment responsefunction for the control group. Splines may also beincorporated using the expressionuSpline, e.g.uSpline(degree = 2, knots = c(0.4, 0.8), intercept =TRUE). Theintercept argument may be omitted, and isset toTRUE by default.

m1

one-sided formula for the marginal treatment responsefunction for the treated group. Seem0 for details.

uname

variable name for the unobservable used in declaringthe MTRs. The name can be provided with or without quotationmarks.

m1.ub

numeric value for upper bound on MTR for the treatedgroup. By default, this will be set to the largest value of theobserved outcome in the estimation sample.

m0.ub

numeric value for upper bound on MTR for the controlgroup. By default, this will be set to the largest value of theobserved outcome in the estimation sample.

m1.lb

numeric value for lower bound on MTR for the treatedgroup. By default, this will be set to the smallest value ofthe observed outcome in the estimation sample.

m0.lb

numeric value for lower bound on MTR for the controlgroup. By default, this will be set to the smallest value ofthe observed outcome in the estimation sample.

mte.ub

numeric value for upper bound on treatment effectparameter of interest.

mte.lb

numeric value for lower bound on treatment effectparameter of interest.

m0.dec

logical, set toFALSE by default. Set equal toTRUE if the MTR for the control group should be weaklymonotone decreasing.

m0.inc

logical, set toFALSE by default. Set equal toTRUE if the MTR for the control group should be weaklymonotone increasing.

m1.dec

logical, set toFALSE by default. Set equal toTRUE if the MTR for the treated group should be weaklymonotone decreasing.

m1.inc

logical, set toFALSE by default. Set equal toTRUE if the MTR for the treated group should be weaklymonotone increasing.

mte.dec

logical, set toFALSE by default. Set equaltoTRUE if the MTE should be weakly monotone decreasing.

mte.inc

logical, set toFALSE by default. Set equaltoTRUE if the MTE should be weakly monotone increasing.

equal.coef

one-sided formula to indicate which terms inm0 andm1 should be constrained to have the samecoefficients. These terms therefore have no effect on the MTE.

ivlike

formula or vector of formulas specifying theregressions for the IV-like estimands. Which coefficients touse to define the constraints determining the treatment effectbounds (alternatively, the moments determining the treatmenteffect point estimate) can be selected in the argumentcomponents. If no argument is passed, then a linearregression will be performed to estimate the MTR coefficients.

components

a list of vectors of the terms in the regressionspecifications to include in the set of IV-like estimands. Noterms should be in quotes. To select the intercept term,include the nameintercept. If the factorizedcounterpart of a variable is included in the IV-likespecifications, e.g.factor(x) wherex = 1, 2, 3,the user can select the coefficients for specific factors bydeclaring the componentsfactor(x)-1, factor(x)-2,factor(x)-3. Seel on how to input theargument. If no components for a IV specification are given,then all coefficients from that IV specification will be usedto define constraints in the partially identified case, or todefine moments in the point identified case.

subset

a single subset condition or list of subsetconditions corresponding to each regression specified inivlike. The input must be logical. Seelon how to input the argument. If the user wishes to selectspecific rows, construct a binary variable in the data set, andset the condition to use only those observations for which thebinary variable is 1, e.g. the binary variable isuse,and the subset condition isuse == 1.

propensity

formula or variable name corresponding topropensity to take up treatment. If a formula is declared, thenthe function estimates the propensity score according to theformula and link specified inlink. If a variable nameis declared, then the corresponding column in the data is takenas the vector of propensity scores. A variable name can bepassed either as a string (e.gpropensity = 'p'), avariable (e.g.propensity = p), or a one-sided formula(e.g.propensity = ~p).

link

character, name of link function to estimate propensityscore. Can be chosen from'linear','probit', or'logit'. Default is set to'logit'. The linkshould be provided with quoation marks.

treat

variable name for treatment indicator. The name can beprovided with or without quotation marks.

solver

character, name of the programming package in R usedto obtain the bounds on the treatment effect. The functionsupports'gurobi','cplexapi',rmosek,'lpsolveapi'. The name of the solver should be providedwith quotation marks.

solver.options

list, each item of the list should correspondto an option specific to the solver selected.

solver.presolve

boolean, default set toTRUE. Setthis parameter toFALSE if presolve should be turned offfor the LP/QCQP problems.

solver.options.criterion

list, each item of the list shouldcorrespond to an option specific to the solver selected. Theseoptions are specific for finding the minimum criterion.

solver.options.bounds

list, each item of the list shouldcorrespond to an option specific to the solver selected. Theseoptions are specific for finding the bounds.

criterion.tol

tolerance for the criterion function, and isset to 1e-4 by default. The criterion measures how well theIV-like moments/conditional means are matched using thel1-norm. Statistical noise may prohibit the theoretical LP/QCQPproblem from being feasible. That is, there may not exist a setof MTR coefficients that are able to match all the specifiedmoments. The function thus first estimates the minimumcriterion, which is reported in the output under the name'minimum criterion', with a criterion of 0 meaning that allmoments were able to be matched. The function then relaxes theconstraints by tolerating a criterion up tominimumcriterion * (1 + criterion.tol). Setcriterion.tol to avalue greater than 0 to allow for more conservative bounds.

initgrid.nx

integer determining the number of points of thecovariates used to form the initial constraint grid forimposing shape restrictions on the MTRs.

initgrid.nu

integer determining the number of points in theopen interval (0, 1) drawn from a Halton sequence. The endpoints 0 and 1 are additionally included. These points arealways a subset of the points defining the audit grid (seeaudit.nu). These points are used to form the initialconstraint grid for imposing shape restrictions on theucomponents of the MTRs.

audit.nx

integer determining the number of points on thecovariates space to audit in each iteration of the auditprocedure.

audit.nu

integer determining the number of points in theopen interval (0, 1) drawn from a Halton sequence. The endpoints 0 and 1 are additionally included. These points are usedto audit whether the shape restrictions on theucomponents of the MTRs are satisfied. The initial grid used toimpose the shape constraints in the LP/QCQP problem areconstructed from a subset of these points.

audit.add

maximum number of points to add to the initialconstraint grid for imposing each kind of shape constraint. Forexample, if there are 5 different kinds of shape constraints,there can be at mostaudit.add * 5 additional pointsadded to the constraint grid.

audit.max

maximum number of iterations in the auditprocedure.

audit.tol

feasibility tolerance when performing theaudit. By default to set to be 1e-06, which is equal to thedefault feasibility tolerances of Gurobi (solver ="gurobi"), CPLEX (solver = "cplexapi"), and Rmosek(solver = "rmosek"). This parameter should only bechanged if the feasibility tolerance of the solver is changed,or if numerical issues result in discrepancies between thesolver's feasibility check and the audit.

audit.grid

list, contains theA matrix used in theaudit for the original sample, as well as the RHS vector usedin the audit from the original sample.

rescale

boolean, set toTRUE by default. Thisrescalels the MTR components to improve stability in theLP/QCQP optimization.

point

boolean. Set toTRUE if it is believed that thetreatment effects are point identified. If set toTRUEand IV-like formulas are passed, then a two-step GMM procedureis implemented to estimate the treatment effects. Shapeconstraints on the MTRs will be ignored under pointidentification. If set toTRUE and the regression-basedcriteria is used instead, then OLS will be used to estimate theMTR coefficients used to estimate the treatment effect. If notdeclared, then the function will determine whether or not thetarget parameter is point identified.

point.eyeweight

boolean, default set toFALSE. Set toTRUE if the GMM point estimate should use the identityweighting matrix (i.e. one-step GMM).

point.center

numeric, a vector of GMM moment conditionsevaluated at a solution. When bootstrapping, the momentconditions from the original sample can be passed through thisargument to recenter the bootstrap distribution of theJ-statistic.

point.redundant

vector of integers indicating whichcomponents in the S-set are redundant.

bootstrap

boolean, indicates whether the estimate isfor the bootstrap.

count.moments

boolean, indicate if number of linearlyindependent moments should be counted.

orig.sset

list, only used for bootstraps. The list containsthe gamma moments for each element in the S-set, as well as theIV-like coefficients.

orig.criterion

numeric, only used for bootstraps. The scalarcorresponds to the minimum observational equivalence criterionfrom the original sample.

vars_y

character, variable name of observed outcomevariable.

vars_mtr

character, vector of variables entering intom0 andm1.

terms_mtr0

character, vector of terms entering intom0.

terms_mtr1

character, vector of terms entering intom1.

vars_data

character, vector of variables that can be foundin the data.

splinesobj

list of spline components in the MTRs for treatedand control groups. Spline terms are extracted usingremoveSplines. This object is supposed to be adictionary of splines, containing the original calls of eachspline in the MTRs, their specifications, and the index usedfor naming each basis spline.

splinesobj.equal

list of spline components in the MTRs fortreated and control groups. The structure ofsplinesobj.equal is the same assplinesobj,except the splines are restricted to those whose MTR cofficientsshould be constrained to be equal across treatment groups.

noisy

boolean, default set toTRUE. IfTRUE,then messages are provided throughout the estimationprocedure. Set toFALSE to suppress all messages,e.g. when performing the bootstrap.

smallreturnlist

boolean, default set toFALSE. Set toTRUE to exclude large intermediary components(i.e. propensity score model, LP/QCQP model, bootstrapiterations) from being included in the return list.

debug

boolean, indicates whether or not the function shouldprovide output when obtaining bounds. The option is onlyapplied whensolver = 'gurobi' orsolver ='rmosek'. The output provided is the same as what the GurobiAPI would send to the console.

environments

a list containing the environments of the MTRformulas, the IV-like formulas, and the propensity scoreformulas. If a formula is not provided, and thus no environmentcan be found, then the parent.frame() is assigned by default.

Details

The treatment effects parameters the user can choose from are theATE, ATT, ATU, LATE, and generalized LATE. The user is required toprovide a polynomial expression for the marginal treatmentresponses (MTR), as well as a set of regressions.

There are two approaches to estimating the treatment effectparameters. The first approach restricts the set of MTRcoefficients on each term of the MTRs to be consistent with theregression estimates from the specifications passed throughivlike. The bounds on the treatment effect parametercorrespond to finding coefficients on the MTRs that maximize theiraverage difference. If the model is point identified, then GMM isused for estimation. Otherwise, the function solves an LPproblem. The second approach restricts the set of MTR coefficientsto fit the conditional mean of the outcome variable. If the modelis point identified, then constrained least squares is used forestimation. Otherwise, the function solves a QCQP.

The estimation procedure relies on the propensity to take uptreatment. The propensity scores can either be estimated as part ofthe estimation procedure, or the user can specify a variable in thedata set already containing the propensity scores.

Constraints on the shape of the MTRs and marginal treatment effects(MTE) can be imposed by the user. Specifically, bounds andmonotonicity restrictions are permitted. These constraints arefirst enforced over a subset of points in the data. An iterativeaudit procedure is then performed to ensure the constraints holdmore generally.

Value

Returns a list of results from throughout the estimationprocedure. This includes all IV-like estimands; the propensityscore model; bounds on the treatment effect; the estimatedexpectations of each term in the MTRs; the components andresults of the LP/QCQP problem.


ivmte Simulated Data

Description

ivmte Simulated Data

Usage

ivmteSimData

Format

A data frame with 5,000 rows and 14 columns.

y

binary outcome variable

d

binary treatment variable

z

instrument that takes the value 0, 1, 2, or 3

x

covariate x that takes integer values from 1 to 10

Source

Simulated — see code in data/ivmteSimData.R.


Listing subsets and components

Description

This function allows the user to declare a list of variable namesin non-character form and subsetting conditions. This is used toensure clean entry of arguments into thecomponents andsubset arguments of the function. When selecting componentsto include in the S set, selecting the intercept term and factorvariables requires special treatment. To select the intercept term,include in the vector of variable names, ‘intercept’. If the thefactorized counterpart of a variablex = 1, 2, 3 is includedin the IV-like specifications viafactor(x), the user canselect the coefficients for specific factors by declaring thecomponentsfactor(x)-1, factor(x)-2, factor(x)-3.

Usage

l(...)

Arguments

...

subset conditions or variable names

Value

list.

Examples

components <- l(d, x1, intercept, factor(x)-2)subsets <- l(, z %in% c(2, 4))

Constructing LP problem

Description

If the user passes IV-like moments to the function, then thefunction constructs the components of the LP problem. If no IV-likemoments are passed, then the function constructs the linearconstraints of the QCQP problem. Note that the LP/QCQP model willbe saved inside an environment variable, which is to be passedthrough the argumentenv. This is done for efficient use ofmemory. The environmentenv is supposed to already contain alist under the entry$mbobj containing the matrices definingthe shape constraints. This list of shape constraints$mbobjshould contain three entries corresponding to a system of linearequations of the formAx <=> b:mbA, the matrixdefining the constraints,A;mbs, a vector indicatingwhether a row inmbA is an equality or inequality constraint(for Gurobi and MOSEK, use '<=', '>=', '='; for CPLEX,use 'L', 'G', and 'E');mbrhs, a vector of the right handside values defining the constraint of the form i.e. the vectorb. Depending on the linear programming solver used, thisfunction will return different output specific to the solver.

Usage

lpSetup(  env,  sset,  orig.sset = NULL,  equal.coef0 = NULL,  equal.coef1 = NULL,  shape = TRUE,  direct = FALSE,  rescale = TRUE,  solver)

Arguments

env

environment containing the matrices defining the LP/QCQPproblem.

sset

List of IV-like estimates and the corresponding gammaterms.

orig.sset

list, only used for bootstraps. The list containsthe gamma moments for each element in the S-set, as well as theIV-like coefficients.

equal.coef0

character, name of terms inm0 thatshould have common coefficients with the corresponding terms inm1.

equal.coef1

character, name of terms inm1 thatshould have common coefficients with the corresponding terms inm0.

shape

boolean, default set to TRUE. Switch to determinewhether or not to include shape restrictions in the LP/QCQPproblem.

direct

boolean, set toTRUE if the direct MTRregression is used.

rescale

boolean, set toTRUE if the MTR componentsshould be rescaled to improve stability in the LP/QCQPoptimization.

solver

string, name of the package used to solve the LP/QCQPproblem.

Value

A list of matrices and vectors necessary to define anLP/QCQP problem.

Examples

dtm <- ivmte:::gendistMosquito()## Declare empty list to be updated (in the event multiple IV like## specifications are providedsSet <- list()## Declare MTR formulasformula0 = ~ 1 + uformula1 = ~ 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 polynomialspolynomials0 <- polyparse(formula = formula0,                          data = dtm,                          uname = u,                          as.function = FALSE)polynomials1 <- polyparse(formula = formula1,                          data = dtm,                          uname = u,                           as.function = FALSE)## Generate propensity score modelpropensityObj <- propensity(formula = d ~ z,                            data = dtm,                            link = "linear")## Generate IV estimatesivEstimates <- ivEstimate(formula = ey ~ d | z,                          data = dtm,                          components = l(intercept, d),                          treat = d,                          list = FALSE)## Generate target gamma momentstargetGamma <- 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 estimandssSet <- 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 requiredsSet <- 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")

Configure LP environment for obtaining the bounds

Description

This function sets up the LP model so that the bounds can beobtained. The LP model must be passed as an environment variable,under the entry$model. SeelpSetup.

Usage

lpSetupBound(  env,  g0,  g1,  sset,  criterion.tol,  criterion.min,  solver,  setup = TRUE)

Arguments

env

the environment containing the LP model.

g0

set of expectations for each terms of the MTR for thecontrol group.

g1

set of expectations for each terms of the MTR for thecontrol group.

sset

a list containing the point estimates and gammacomponents associated with each element in the S-set. Thisobject is only used to determine the names of terms. If it isno submitted, then no names are provided to the solutionvector.

criterion.tol

additional multiplicative factor for how muchmore the solution is permitted to violate observationalequivalence of the IV-like estimands, i.e.1 +criterion.tol will multiplycriterion.min directly.

criterion.min

minimum criterion, i.e. minimum deviation fromobservational equivalence while satisfying shape constraints.

solver

string, name of the package used to solve the LPproblem.

setup

boolean. IfTRUE, the function will modify theLP environment so that the LP solver can obtain the bounds. IfFALSE, then it will undo the changes made by thefunction ifsetup = TRUE.

Value

Nothing, as this modifies an environment variable to savememory.


Configure LP environment for minimizing the criterion

Description

This function sets up the objective function for minimizing thecriterion. The LP model must be passed as an environment variable,under the entry$model. SeelpSetup.

Usage

lpSetupCriterion(env, sset)

Arguments

env

The LP environment

sset

List of IV-like estimates and the corresponding gammaterms.

Value

Nothing, as this modifies an environment variable to savememory.


Configure LP environment for specification testing

Description

This function re-centers various objects in the LP environment sothat a specification test can be performed via the bootstrap. TheLP model must be passed as an environment variable, under the entry$model. SeelpSetup.

Usage

lpSetupCriterionBoot(  env,  sset,  orig.sset,  orig.criterion,  criterion.tol = 0,  setup = TRUE)

Arguments

env

the LP environment

sset

list of IV-like estimates and the corresponding gammaterms.

orig.sset

list, only used for bootstraps. The list caontainsthe gamma moments for each element in the S-set, as well as theIV-like coefficients.

orig.criterion

scalar, only used for bootstraps. This is theminimum criterion from the original sample.

criterion.tol

tolerance for violation of observationalequivalence, set to 0 by default.

setup

boolean. IfTRUE, the function will modify theLP environment so that the LP solver can obtain the teststatistic for the specification test. IfFALSE, then itwill undo the changes made by the function ifsetup =TRUE.

Value

Nothing, as this modifies an environment variable to savememory.


Generate equality constraints

Description

This function generates the linear constraints to ensure thatcertain MTR coefficients are constant across the treatment andcontrol group.

Usage

lpSetupEqualCoef(equal.coef0, equal.coef1, ANames)

Arguments

equal.coef0

character, name of terms inm0 thatshould have common coefficients with the corresponding terms inm1.

equal.coef1

character, name of terms inm1 thatshould have common coefficients with the corresponding terms inm0.

ANames

character, name of all terms inm0 andm1. The names of the terms corresponding to thetreatment and control groups should be distinguishable. Forexample, all terms form0 may contain a prefix '[m0]',and all terms form1 may contain a prefix '[m1]'. Allthe terms inequal.coef0 andequal.coef1 shouldbe contained inANames.

Value

A list, containing the matrix of linear equalityconstraints, a vector of equal signs, and a vector of 0s.


Configure LP environment for diagnostics

Description

This function separates the shape constraints from the LPenvironment. That way, the model can be solved without any shapeconstraints, which is the primary cause of infeasibility. This isdone in order to check which shape constraints are causing themodel to be infeasible. The LP model must be passed as anenvironment variable, under the entry$model. SeelpSetup.

Usage

lpSetupInfeasible(env, sset)

Arguments

env

The LP environment

sset

List of IV-like estimates and the corresponding gammaterms.

Value

Nothing, as this modifies an environment variable to savememory.


Configure LP environment to be compatible with solvers

Description

This alters the LP environment so the model will be compatible withspecific solvers. The LP model must be passed as an environmentvariable, under the entry$model. SeelpSetup.

Usage

lpSetupSolver(env, solver)

Arguments

env

The LP environment

solver

Character, the LP solver.

Value

Nothing, as this modifies an environment variable to savememory.


Function to generate integral of m0 and m1

Description

Function carries out integral for a polynomial of degree 3.

Usage

mInt(ub, lb, coef)

Arguments

ub

scalar, upper bound of the integral.

lb

scalar, lower bound of the integral.

coef

vector, polynomial coefficients.

Value

scalar.


Check magnitude of real number

Description

This function returns the order of magnitude of a a number.

Usage

magnitude(x)

Arguments

x

The number to be checked.

Value

An integer indicating the order of magnitude.


Convert matrix into triplet form

Description

This function converts matrices into triplet form for Mosek. Thisis required in order to declare quadratic programming problems andsecond-order cone programming problems.

Usage

matrixTriplets(mat, lower = TRUE)

Arguments

mat

A matrix.

lower

Boolean, set toTRUE if matrix is symmetric,and only its lower triangle should be returned.

Value

A list containing vectors of row and column indexes, andmatrix values.


Auxiliary function: modifying calls

Description

This function can be used to modify calls in several ways.

Usage

modcall(call, newcall, newargs, keepargs, dropargs)

Arguments

call

Call object to be modified.

newcall

New function to be called.

newargs

List, new arguments and their values.

keepargs

List, arguments in original call to keep, with therest being dropped.

dropargs

List, arguments in original call to drop, with therest being kept.

Value

New call object.


Construct pre-meaned moment matrix

Description

This function constructs the matrix to be fed into the GMMestimator to construct the moment conditions.

Usage

momentMatrix(sset, gn0, gn1, subsetList = NULL, n = NULL)

Arguments

sset

a list of lists constructed from the functiongenSSet. Each inner list should include a coefficientcorresponding to a term in an IV specification, a matrix of theestimates of the gamma moments conditional on (X, Z) for d = 0,and a matrix of the estimates of the gamma moments conditionalon (X, Z) for d = 1. The column means of the last two matricesis what is used to generate the gamma moments.

gn0

integer, number of terms in the MTR for control group.

gn1

integer, number of terms in the MTR for treated group.

subsetList

list of subset indexes, one for each IV-likespecification.

n

number of observations in the data. This option is onlyused when subsets are involved.

Value

matrix whose column means can be used to carry out the GMMestimation.


Integrating and evaluating monomials

Description

Analytically integrates monomials and evalates them at a givenpoint. It is assumed that there is no constant multiplying themonomial.

Usage

monoIntegral(u, exp)

Arguments

u

scalar, the point at which to evaluate the integral. If avector is passed, then the integral is evaluated at all theelements of the vector.

exp

The exponent of the monomial.

Value

scalar or vector, depending on whatu is.


Check if custom weights are negations of each other

Description

This function checks whether the user-declared weights for treatedand control groups are in fact negations of each other. This isproblematic for the GMM procedure when accounting for estimationerror of the target weights.

Usage

negationCheck(  data,  target.knots0,  target.knots1,  target.weight0,  target.weight1,  N = 20)

Arguments

data

data set used for estimation. The comparisons are madeonly on values in the support of the data set.

target.knots0

user-defined set of functions defining theknots associated with splines weights for the controlgroup. The arguments of the function should consist only ofvariable names indata. If the knot is constant acrossall observations, then the user can instead submit the value ofthe weight instead of a function.

target.knots1

user-defined set of functions defining theknots associated with splines weights for the treatedgroup. The arguments of the function should be variable namesindata. If the knot is constant across allobservations, then the user can instead submit the value of theweight instead of a function.

target.weight0

user-defined weight function for the controlgroup defining the target parameter. A list of functions can besubmitted if the weighting function is in fact a spline. Thearguments of the function should be variable names indata. If the weight is constant across all observations,then the user can instead submit the value of the weightinstead of a function.

target.weight1

user-defined weight function for the treatedgroup defining the target parameter. A list of functions can besubmitted if the weighting function is in fact a spline. Thearguments of the function should be variable names indata. If the weight is constant across all observations,then the user can instead submit the value of the weightinstead of a function.

N

integer, default set to 20. This is the maxmimum number ofpoints between treated and control groups to compare anddetermine whether or not the weights are indeed negations ofone another. If the data set contains fewer thanNunique values for a given set of variables, then all thoseunique values are used for the comparison.

Value

boolean. If the weights are negations of each other,TRUE is returned.


OLS weights

Description

Function generating the S-weights for OLS estimand, with controls.

Usage

olsj(X, X0, X1, components, treat, order = NULL)

Arguments

X

Matrix of covariates, including the treatment indicator.

X0

Matrix of covariates, once fixing treatment to be 0.

X1

Matrix of covariates, once fixing treatment to be 1.

components

Vector of variable names of which user wants theS-weights for.

treat

Variable name for the treatment indicator.

order

integer, default set toNULL. This is simply anindex of which IV-like specification the estimate correspondsto.

Value

A list of two vectors: one is the weight for D = 0, theother is the weight for D = 1.


Function to parse options for CPLEX

Description

This function constructs a list of options to be parsed whensolver is set tocplexapi.

Usage

optionsCplexAPI(options)

Arguments

options

list. The name of each item must be the name of thefunction to set the option, and is case sensitive. The valueassigned to each item is the value to set the option to. Theenv argument should always be omitted. If the optionaccepts a list of parameters, then these parameters should bepassed as using a named vector (e.g.list(setLogFileNameCPLEX = c(filename = "cpx.log", mode ="w"))). If the function to set the option can be usedmultiple times, then the value submitted should be a a list,with each entry being a named vector(e.g.list(setDblParmCPLEX = list(c(parm = 1016, value =1e-04), c(parm = 1084, value = 2)))). If the option onlyrequires theenv parameter, then anNA should bepassed as the parameter value (e.g.list(setDefaultParm= NA)).

Value

list, each element being the command to evaluate toimplement an option.


Function to parse a single set of options for CPLEX

Description

This function constructs a string to be parsed whensolveris set tocplexapi.

Usage

optionsCplexAPISingle(name, vector)

Arguments

name

string, name of thecplexapi function to call toimplement the option.

vector

a named vector, contains the argument names andvalues of the options. Theenv argument in thecplexapi documentation should always be omitted.

Value

string, the command to be evaluated to implement a singleoption.


Function to extract feasibility tolerance from CPLEX options

Description

This function parses through the user-submitted CPLEX options todetermine what the feasibility tolerance is. This tolerance canthen be used for the audit. If the user does not set the CPLEXfeasibility tolerance, then a default value of1e-06 isreturned.

Usage

optionsCplexAPITol(options)

Arguments

options

list, the set of options submitted by the user.

Value

scalar, the level to set the audit tolerance at.


Function to parse options for Gurobi

Description

This function constructs a list of options to be parsed whensolver is set toGurobi. This function reallyimplements some default values, and accounts for thedebugoption.

Usage

optionsGurobi(options, debug)

Arguments

options

list. The list should be structured the same way asif one were using thegurobi library directly. That is,the name of each item must be the name of the option, and iscase sensitive. The value assigned to each item is the value toset the option to.

debug

boolean, indicates whether or not the function shouldprovide output when obtaining bounds. The output provided isthe same as what the Gurobi API would send to the console.

Value

list, the set of options declared by the user, includingsome additional default values (if not assigned by the user)and accounting fordebug.


Function to parse options for lp_solve

Description

This function constructs a list of options to be parsed whensolver is set tolpsolveapi. The options permittedare those that can be set vialpSolveAPI::lp.control, andshould be passed as a named list (e.g.list(epslevel ="tight")).

Usage

optionsLpSolveAPI(options)

Arguments

options

list. The name of each item must be the name of theoption, and is case sensitive. The value assigned to each itemis the value to set the option to. Thelprec argumentshould always be omitted.

Value

string, the command to be evaluated to implement theoptions.


Function to parse options for Gurobi

Description

This function constructs a list of options to be parsed whensolver is set toRmosek. This function reallyimplements the default feasibility tolerances.

Usage

optionsRmosek(options, debug)

Arguments

options

list. Each set of options should be passed as alist, with the name of each entry being the name of the classof options. For example, options for double parameters shouldbe contained in the entrydparam = list(BASIS_TOL_X = 1e-06).

debug

boolean, indicates whether or not the function shouldprovide output when obtaining bounds. The output provided isthe same as what Mosek would send to the console.

Value

list, the set of options declared by the user, includingsome additional default values.


Correct boolean expressions in terms lists

Description

This function takes a vector of terms and places parentheses aroundboolean expressions.

Usage

parenthBoolean(termsList)

Arguments

termsList

character vector, the vector of terms.

Value

character vector.


Auxiliary function: generate all permutations of a vector

Description

This function generates every permutation of the elements in avector.

Usage

permute(vector)

Arguments

vector

The vector whose elements are to be permuted.

Value

a list of all the permutations ofvector.


Auxiliary function: generate all permutation orderings

Description

This function generates every permutation of the first n naturalnumbers.

Usage

permuteN(n)

Arguments

n

integer, the first n natural numbers one wishes topermute.

Value

a list of all the permutations of the first n naturalnumbers.


Obtaining IV-like estimands

Description

This function performs TSLS to obtain the estimates for the IV-likeestimands.

Usage

piv(  Y,  X,  Z,  lmcomponents = NULL,  weights = NULL,  order = NULL,  excluded = TRUE)

Arguments

Y

the vector of outcomes.

X

the matrix of covariates (includes endogenous andexogenous covariates).

Z

the matrix of instruments (includes exogenous covariatesin the second stage).

lmcomponents

vector of variable names from the second stagethat we want to include in the S-set of IV-like estimands. IfNULL is submitted, then all components will be included.

weights

vector of weights.

order

integer, the counter for which IV-like specificationand component the regression is for.

excluded

boolean, to indicate whether or not the regressioninvolves excluded variables.

Value

vector of select coefficient estimates.


Function to multiply polynomials

Description

This function takes in two vectors characterizing polynomials. Itthen returns a vector characterizing the product of the twopolynomials.

Usage

polyProduct(poly1, poly2)

Arguments

poly1

vector, characerizing a polynomial.

poly2

vector, characerizing a polynomial.

Value

vector, characterizing the product of the two polynomialscharacterizedpoly1 andpoly2.


Parsing marginal treatment response formulas

Description

This function takes in an MTR formula, and then parses the formulasuch that it becomes a polynomial in the unobservableu. Itthen breaks these polynomials into monomials, and then integrateseach of them with respect tou. Each integral corresponds toE[md | D, X, Z].

Usage

polyparse(  formula,  data,  uname = "u",  env = parent.frame(),  as.function = FALSE)

Arguments

formula

the MTR.

data

data.frame for which we obtain E[md | D, X, Z]for each observation.

uname

variable name for unobservable used in declaring theMTR.

env

environment, the original environment in whichthe formula was declared.

as.function

boolean, ifFALSE then a list of thepolynomial terms are returned; ifTRUE then a list offunctions corresponding to the polynomials are returned.

Value

A list (of lists) of monomials corresponding to theoriginal MTR (for each observation); a list (of lists) of theintegrated monomials; a vector for the degree of each of theoriginal monomials in the MTR; and a vector for the names ofeach variable entering into the MTR (notex^2 + x hasonly one term,x).

Examples

dtm <- ivmte:::gendistMosquito()## Declare MTR functionsformula1 = ~ 1 + uformula0 = ~ 1 + u## Construct MTR polynomialspolynomials0 <- polyparse(formula = formula0,                          data = dtm,                          uname = u,                          as.function = FALSE)polynomials1 <- polyparse(formula = formula0,                          data = dtm,                          uname = u,                          as.function = FALSE)

Calulating population mean

Description

Given a distribution, this function calculates the population meanfor each term in a formula.

Usage

popmean(formula, distribution, density = "f")

Arguments

formula

formula, each term of which will have its meancalculated.

distribution

data.table, characterizing the distribution ofthe variables entering intoformula.

density

string, name of the variabledatacharacterizing the density.

Value

vector, the means for each term informula.


Print results

Description

This function uses the print method on the ivmte return list.

Usage

## S3 method for class 'ivmte'print(x, ...)

Arguments

x

an object returned from 'ivmte'.

...

additional arguments.

Value

basic set of results.


Estimating propensity scores

Description

This function estimates the propensity of taking up treatment. Theuser can choose from fitting a linear probability model, a logitmodel, or a probit model. The function can also be used to generatea table of propensity scores for a given set of covariates andexcluded variables. This was incorporated to account for the LATEbeing a target parameter. Specifically, if the argumentformula is the name of a variable indata, but thetarget parameter is not the LATE, then no propensity model isreturned. If the target parameter is the LATE, then then thepropensity model is simply the empirical distribution of propensityscores in the data conditioned on the set of covariates declared inlate.X andlate.Z.

Usage

propensity(formula, data, link = "logit", late.Z, late.X, env = parent.frame())

Arguments

formula

Formula characterizing probability model. If avariable in the data already contains the propensity scores,input the variable as a one-sided formula. For example, if thevariablepz contains the propensity score, inputformula = ~ pz.

data

data.frame with which to estimate the model.

link

Link function with which to estimate probabilitymodel. Can be chosen from "linear", "logit", or "probit".

late.Z

A vector of variable names of excludedvariables. This is required when the target parameter is theLATE.

late.X

A vector of variable names of non-excludedvariables. This is required when the target parameter is theLATE, and the estimation procedure will condition on thesevariables.

env

environment, the environment for the originalpropensity score formula.

Value

A vector of propensity scores for each observation, as wellas a 'model'. If the user inputs a formula characterizing themodel for taking up treatment, then thelm/glmobject is returned. If the user declares a variable in the dataset to be used as the propensity score, then adata.frame containing the propensity score for eachvalue of the covariates in the probability model is returned.

Examples

dtm <- ivmte:::gendistMosquito()## Declaring a probability model.propensity(formula = d ~ z,               data = dtm,               link = "linear")## Declaring a variable to be used insteadpropensity(formula = ~ pz,               data = dtm,               link = "linear")

Constructing QCQP problem

Description

This function is only used when the direct MTR regression procedureis used. This function simply constructs the quadratic constraint,and adds it to the LP problem defined by the linear optimization problemfor the bounds and the linear shape constraints.

Usage

qpSetup(env, sset, rescale = TRUE)

Arguments

env

environment containing the matrices defining the LPproblem.

sset

A list containing the covariats and outcome variablefor the direct MTR regression.

rescale

boolean, set toTRUE if the MTR componentsshould be rescaled to improve stability in the LP/QP/QCPoptimization.


Constructing QCQP problem for bounding

Description

This function is only used when the direct MTR regression procedureis used. This function simply constructs the quadratic constraint,and adds it to the LP problem defined by the linear optimization problemfor the bounds and the linear shape constraints.

Usage

qpSetupBound(  env,  g0,  g1,  criterion.tol,  criterion.min,  rescale = FALSE,  setup = TRUE)

Arguments

env

environment containing the matrices defining the LPproblem.

g0

set of expectations for each terms of the MTR for thecontrol group.

g1

set of expectations for each terms of the MTR for thecontrol group.

criterion.tol

non-negative scalar, determines how much thequadratic constraint should be relaxed by. If set to 0, theconstraint is not relaxed at all.

criterion.min

minimum of (SSR - SSY) of a linear regressionwith shape constraints.

rescale

boolean, set toTRUE if the MTR componentsshould be rescaled to improve stability in the LP/QP/QCPoptimization.

setup

boolean, set toTRUE if the QP problem shouldbe set up for solving the bounds, which includes the quadraticconstraint. Set toFALSE if the quadratic constraintshould be removed.

Value

A list of matrices and vectors necessary to define an LPproblem for Gurobi or MOSEK.


Configure QCQP problem to find minimum criterion

Description

This function sets up the objective function for minimizing thecriterion. The QCQP model must be passed as an environment variable,under the entry$model. SeeqpSetup.

Usage

qpSetupCriterion(env)

Arguments

env

The LP environment

Value

Nothing, as this modifies an environment variable to savememory.


Configure QP environment for diagnostics

Description

This function separates the shape constraints from the QPenvironment. That way, the model can be solved without any shapeconstraints, which is the primary cause of infeasibility. This isdone in order to check which shape constraints are causing themodel to be infeasible. The QP model must be passed as anenvironment variable, under the entry$model. SeelpSetup.

Usage

qpSetupInfeasible(env, rescale)

Arguments

env

The LP environment

rescale

boolean, set toTRUE if the MTR componentsshould be rescaled to improve stability in the LP/QP/QCPoptimization.

Value

Nothing, as this modifies an environment variable to savememory.


Separating splines from MTR formulas

Description

This function separates out the function callsuSpline() anduSplines() potentially embedded in the MTR formulas from therest of the formula. The terms involving splines are treatedseparately from the terms that do not involve splines when creatingthe gamma moments.

Usage

removeSplines(formula, env = parent.frame())

Arguments

formula

the formula that is to be parsed.

env

environment in which to formulas. This is necessary assplines may be declared using objects, e.g.knots = x,wherex = c(0.3, 0.64, 0.9).

Value

a list containing two objects. One object isformulabut with the spline components removed. The second object is alist. The name of each element is theuSpline()/uSplines() command, and the elementsare a vector of the names of covariates that were interactedwith theuSpline()/uSplines() command.

Examples

## Declare and MTR with a sline component.m0 = ~ x1 + x1 : uSpline(degree = 2,                          knots = c(0.2, 0.4)) +            x2 : uSpline(degree = 2,                          knots = c(0.2, 0.4)) +            x1 : x2 : uSpline(degree = 2,                               knots = c(0.2, 0.4)) +            uSpline(degree = 3,                     knots = c(0.2, 0.4),                     intercept = FALSE)## Now separate the spline component from the non-spline componentremoveSplines(m0)

Function to implement rescaling procedure

Description

This function rescales the matrix of covariates used in the directregression to improve the conditioning number and the stability ofthe estimation procedure.

Usage

rescaleX(sset, dVec, drY, drN)

Arguments

sset

a list of lists constructed from the functiongenSSet. In the case of a direct regression, 'sset'contains only one inner list. This list contains the gammamoment at the individual level.

dVec

Vector of treatment statuses from the data.

drY

Vector of outcomes from the data.

drN

Scalar, number of observations in the data.

Value

List of rescaled covariates.


Auxiliary function that converts an expression of variable namesinto a vector of strings.

Description

Auxiliary function that converts an expression of variable namesinto a vector of strings.

Usage

restring(vector, substitute = TRUE, command = "c")

Arguments

vector

An expression of a list of variable names.

substitute

Boolean option of whether or not we wish to usethesubstitute command when implementing thisfunction. Note that this substitutes the argument of thefunction. Ifsubstitute = FALSE, then the function willinstead treat the arguments as variables, and substitute intheir values.

command

character, the name of the function defining thevector or list, e.g. "c", "list", "l". This let's the functiondetermine how many characters in front to remove.

Value

A vector of variable names (strings).

Examples

a <- 4b <- 5ivmte:::restring(c(a, b), substitute = TRUE)ivmte:::restring(c(a, b), substitute = FALSE)

Generate Halton sequence

Description

This function generates a one dimensional Halton sequence.

Usage

rhalton(n, base = 2)

Arguments

n

Number of draws.

base

Base used for the Halton sequence, set to 2 by default.

Value

A sequence of randomly drawn numbers.


Running cplexAPI solver

Description

This function solves the LP problem using the cplexAPI package. Theobject generated bylpSetup is not compatible withthecplexAPI functions. This function adapts the object tosolve the LP problem. SeerunGurobi for additionalerror code labels.

Usage

runCplexAPI(model, lpdir, solver.options)

Arguments

model

list of matrices and vectors defining the linearprogramming problem.

lpdir

input either CPX_MAX or CPX_MIN, which sets the LPproblem as a maximization or minimization problem.

solver.options

list, each item of the list shouldcorrespond to an option specific to the LP solver selected.

Value

a list of the output from CPLEX. This includes theobjective value, the solution vector, and the optimizationstatus (status of1 indicates successful optimization).


Running Gurobi solver

Description

This function solves the LP/QCQP problem using the Gurobi package. Theobject generated bylpSetup is compatible with thegurobi function. SeerunCplexAPI foradditional error code labels.

Usage

runGurobi(model, solver.options)

Arguments

model

list of matrices and vectors defining the linearprogramming problem.

solver.options

list, each item of the list shouldcorrespond to an option specific to the LP solver selected.

Value

a list of the output from Gurobi. This includes theobjective value, the solution vector, and the optimizationstatus (status of1 indicates successful optimization) .


Running lpSolveAPI

Description

This function solves the LP problem using thelpSolveAPIpackage. The object generated bylpSetup is notcompatible with thelpSolveAPI functions. This functionadapts the object to solve the LP problem. SeerunGurobi andrunCplexAPI foradditional error code labels.

Usage

runLpSolveAPI(model, modelsense, solver.options)

Arguments

model

list of matrices and vectors defining the linearprogramming problem.

modelsense

input either 'max' or 'min' which sets the LPproblem as a maximization or minimization problem.

solver.options

list, each item of the list shouldcorrespond to an option specific to the LP solver selected.

Value

a list of the output fromlpSolveAPI. This includesthe objective value, the solution vector, and the optimizationstatus (status of1 indicates successful optimization).


Running Rmosek

Description

This function solves the LP/QCQP problem using theRmosekpackage. The object generated bylpSetup is notcompatible with theRmosek functions. This functionadapts the object to solve the LP problem. SeerunGurobi andrunCplexAPI foradditional error code labels.

Usage

runMosek(model, modelsense, solver.options, debug = FALSE)

Arguments

model

list of matrices and vectors defining the linearprogramming problem.

modelsense

input either 'max' or 'min' which sets the LPproblem as a maximization or minimization problem.

solver.options

list, each item of the list shouldcorrespond to an option specific to the LP solver selected.

debug

boolean, indicates whether or not the function shouldprovide output when obtaining bounds. The output provided isthe same as what the Mosek would send to the console.

Value

a list of the output fromRmosek. This includesthe objective value, the solution vector, and the optimizationstatus (status of1 indicates successful optimization).


IV-like weighting function, OLS specification 1

Description

IV-like weighting function for OLS specification 1.

Usage

sOls1d(d, exx)

Arguments

d

0 or 1, indicating treatment or control.

exx

the matrix E[XX']

Value

scalar.


IV-like weighting function, OLS specification 2

Description

IV-like weighting function for OLS specification 2.

Usage

sOls2d(x, d, exx)

Arguments

x

vector, the value of the covariates other than theintercept and the treatment indicator.

d

0 or 1, indicating treatment or control.

exx

the matrix E[XX']

Value

scalar.


IV-like weighting function, OLS specification 3

Description

IV-like weighting function for OLS specification 3.

Usage

sOls3(x, d, j, exx)

Arguments

x

vector, the value of the covariates other than theintercept and the treatment indicator.

d

0 or 1, indicating treatment or control.

j

scalar, position of the component one is interested inconstructing the IV-like weight for.

exx

the matrix E[XX']

Value

scalar.


IV-like weighting function, OLS specifications

Description

IV-like weighting function for OLS specifications.

Usage

sOlsSplines(x = NULL, d, j, exx)

Arguments

x

vector, the value of the covariates other than theintercept and the treatment indicator.

d

0 or 1, indicating treatment or control.

j

scalar, position of the component one is interested inconstructing the IV-like weight for.

exx

matrix corresponding to E[XX'].

Value

scalar.


IV-like weighting function, TSLS specification

Description

IV-like weighting function for TSLS specification.

Usage

sTsls(z, j, exz, pi)

Arguments

z

vector, the value of the instrument.

j

scalar, position of the component one is interested inconstructing the IV-like weight for.

exz

the matrix E[XZ']

pi

the matrix E[XZ']E[ZZ']^-1

Value

scalar.


IV-like weighting function, TSLS specification

Description

IV-like weighting function for TSLS specification.

Usage

sTslsSplines(z, d, j, exz, pi)

Arguments

z

vector, the value of the instrument.

d

0 or 1, indicating treatment or control (redundant in thisfunction; included to exploit apply()).

j

scalar, position of the component one is interested inconstructing the IV-like weight for.

exz

matrix, corresponds to E[XZ'].

pi

matrix, corresponds to E[XZ']E[ZZ']^-1, the first stageregression.

Value

scalar.


IV-like weighting function, Wald specification

Description

IV-like weighting function for OLS specification 2.

Usage

sWald(z, p.to, p.from, e.to, e.from)

Arguments

z

vector, the value of the instrument.

p.to

P[Z = z'], where z' is value of the instrument theagent is switching to.

p.from

P[Z = z], where z is the value of the instrument theagent is switching from.

e.to

E[D | Z = z'], where z' is the value of the instrumentthe agent is switching to.

e.from

E[D | Z = z], where z is the value of the instrument theagent is switching from.

Value

scalar.


Select points from audit grid to add to the constraint grid

Description

This function selects which points from the audit grid should beincluded into the original grid. Both the constraint grid and auditgrid are represented as constraints in an LP/QCQP problem. Thisfunction selects which points in the audit grid (i.e. which rows inthe audit constraint matrix) should be added to the constraint grid(i.e. should be appended to the constraint matrix).

Usage

selectViolations(  diffVec,  audit.add,  lb0seq,  lb1seq,  lbteseq,  ub0seq,  ub1seq,  ubteseq,  mono0seq,  mono1seq,  monoteseq,  mbmap)

Arguments

diffVec

numeric vector, with a positive value indicating aviolation of a shape constraint.

audit.add

integer, the number of points from the audit gridto add to the initial for each constraint type. For instance, ifthere are 5 different kinds of constraints imposed, andaudit.add = 5, then up to 30 points may be added to theconstraint grid.

lb0seq

integer vector, indicates which rows in the auditconstraint matrix correspond to the lower bound for m0.

lb1seq

integer vector, indicates which rows in the auditconstraint matrix correspond to the lower bound for m1.

lbteseq

integer vector, indicates which rows in the auditconstriant matrix correspond to the lower bound for thetreatment effect.

ub0seq

integer vector, indicates which rows in the auditconstraint matrix correspond to the upper bound for m0.

ub1seq

integer vector, indicates which rows in the auditconstraint matrix correspond to the upper bound for m1.

ubteseq

integer vector, indicates which rows in the auditconstriant matrix correspond to the upper bound for thetreatment effect.

mono0seq

integer matrix, indicates which rows in the auditconstraint matrix correspond to the monotonicity conditions form0, and whether the constraint is increasing (+1) or decreasing(-1).

mono1seq

integer matrix, indicates which rows in the auditconstraint matrix correspond to the monotonicity conditions form1, and whether the constraint is increasing (+1) or decreasing(-1).

monoteseq

integer matrix, indicates which rows in the auditconstraint matrix correspond to the monotonicity conditions forthe treatment effect, and whether the constraint is increasing(+1) or decreasing (-1).

mbmap

integer vector, indexes the X-value associated witheach row in the audit constraint matrix.

Value

The audit grid is represented using a set of constraintmatrices. Each point in the audit grid corresponds to a set ofrows in the constraint matrices. The function simply returnsthe vector of row numbers for the points from the audit gridwhose corresponding constraints should be added to the originalLP/QCQP problem (i.e. the points to add to the original grid).


Integrating splines

Description

This function simply integrates the splines.

Usage

splineInt(ub, lb, knots, degree, intercept = FALSE)

Arguments

ub

scalar, upperbound of integral.

lb

scalar, lowerbound of integral.

knots

vector, knots of the spline.

degree

scalar, degre of spline.

intercept

boolean, set to TRUE if spline basis shouldinclude a component so that the basis sums to 1.

Value

vector, each component being the integral of a basis.


Constructing higher order splines

Description

This function recursively constructs the higher order splinesbasis. Note that the function does not take into consideration theorder of the final basis function. The dimensions of the inputsdicate this, and are updated in each iteration of therecursion. The recursion ends once the row number of argumentbmat reaches 1. This function was coded in accordance toCarl de Boor's set of notes on splines, "B(asic)-Spline Basics".

Usage

splineUpdate(x, bmat, knots, i, current.order)

Arguments

x

vector, the values at which to evaluate the basisfunction.

bmat

matrix. Each column ofbmat corresponds to anelement of argumentx. Each row corresponds to theevaluation of basis componenti,i + 1, .... Therecursive nature of splines requires that we initially evaluatethe basis functions for componentsi, ...,i +degree of spline. Each iteration of the recursion reduces therow ofbmat by 1. The recursion terminates oncebmat has only a single row.

knots

vector, the internal knots.

i

integer, the basis component of interest.

current.order

integer, the current order associated with theargumentbmat.

Value

vector, the evaluation of the spline at each value invectorx.


Evaluating splines basis functions

Description

This function evaluates the splines basis functions. Unlike thebSpline in thesplines2 package, this functionreturns the value of a single spline basis, rather than a vector ofvalues for all the spline basis functions.

Usage

splinesBasis(x, knots, degree, intercept = TRUE, i, boundary.knots = c(0, 1))

Arguments

x

vector, the values at which to evaluate the basisfunction.

knots

vector, the internal knots.

degree

integer, the degree of the splines.

intercept

boolean, default set toTRUE. This includesan additional component to the basis splines so that thesplines are a partition of unity (i.e. the sum of allcomponents equal to 1).

i

integer, the basis component to be evaluated.

boundary.knots

vector, default isc(0, 1).

Value

scalar.


Convert status code to string

Description

This function returns the status code specific to a solver.

Usage

statusString(status, solver)

Arguments

status

Status code.

solver

Name of solver, either 'gurobi', 'cplexapi', or'lpsolveapi'.

Value

Status specific to solver, e.g. 'OPTIMAL (2)'.


Auxiliary function: remove extraneous spaces

Description

Auxiliary function to remove extraneous spaces from strings.

Usage

subsetclean(string)

Arguments

string

the string object to be cleaned.

Value

a string


Summarize results

Description

This function uses the summary method on the ivmte return list.

Usage

## S3 method for class 'ivmte'summary(object, ...)

Arguments

object

an object returned from 'ivmte'.

...

additional arguments.

Value

summarized results.


Generate symmetric matrix

Description

Function takes in a vector of values, and constructs a symmetricmatrix from it. Diagonals must be included. The length of thevector must also be consistent with the number of "unique" entriesin the symmetric matrix. Note that entries are filled in along thecolumns (i.e. equivalent to byrow = FALSE).

Usage

symat(values)

Arguments

values

vector, the values that enter into the symmetricmatrix. Dimensions will be determined automatically.

Value

matrix.


TSLS weights, with controls

Description

Function generating the S-weights for TSLS estimand, with controls.

Usage

tsls(X, Z, Z0, Z1, components, treat, order = NULL)

Arguments

X

Matrix of covariates, including the treatment indicator.

Z

Matrix of instruments.

Z0

Matrix of instruments, fixing treatment to 0.

Z1

Matrix of instruments, fixing treatment to 1.

components

Vector of variable names of which user wants theS-weights for.

treat

Variable name for the treatment indicator.

order

integer, default set toNULL. This is simply anindex of which IV-like specification the estimate correspondsto.

Value

A list of two vectors: one is the weight for D = 0, theother is the weight for D = 1.


Spline basis function

Description

This function evaluates the splines that the user specifies whendeclaring the MTRs. This is to be used for auditing, namely whenchecking the boundedness and monotonicity conditions.

Usage

uSplineBasis(x, knots, degree = 0, intercept = TRUE)

Arguments

x

the points to evaluate the integral of the the splines.

knots

the knots of the spline.

degree

the degree of the spline; default is set to 0(constant splines).

intercept

boolean, set to TRUE if intercept term is to beincluded (i.e. an additional basis such that the sum of thesplines at every point inx is equal to 1).

Value

a matrix, the values of the integrated splines. Each rowcorresponds to a value ofx; each column corresponds toa basis defined by the degrees and knots.

Examples

## Since the splines are declared as part of the MTR, you will need## to have parsed out the spline command. Thus, this command will be## called via eval(parse(text = .)). In the examples below, the## commands are parsed from the object \code{splineslist} generated## by \code{\link[MST]{removeSplines}}. The names of the elements in## the list are the spline commands, and the elements themselves are## the terms that interact with the splines.## Declare MTR functionm0 = ~ x1 + x1 : uSpline(degree = 2,                          knots = c(0.2, 0.4)) +    x2 : uSpline(degree = 2,                  knots = c(0.2, 0.4)) +    x1 : x2 : uSpline(degree = 2,                       knots = c(0.2, 0.4)) +    uSpline(degree = 3,             knots = c(0.2, 0.4),             intercept = FALSE)## Extract spline functions from MTR functionsplineslist <- removeSplines(m0)$splineslist## Declare points at which we wish to evaluate the spline functionsx <- seq(0, 1, 0.2)## Evaluate the splineseval(parse(text = gsub("uSpline\\(",                       "ivmte:::uSplineBasis(x = x, ",                        names(splineslist)[1])))eval(parse(text = gsub("uSpline\\(",                       "ivmte:::uSplineBasis(x = x, ",                       names(splineslist)[2])))

Integrated splines

Description

This function integrates out splines that the user specifies whendeclaring the MTRs. This is to be used when generating the gammamoments.

Usage

uSplineInt(x, knots, degree = 0, intercept = TRUE)

Arguments

x

the points to evaluate the integral of the the splines.

knots

the knots of the spline.

degree

the degree of the spline; default is set to 0(constant splines).

intercept

boolean, set to TRUE if intercept term is to beincluded (i.e. an additional basis such that the sum of thesplines at every point inx is equal to 1).

Value

a matrix, the values of the integrated splines. Each rowcorresponds to a value ofx; each column corresponds toa basis defined by the degrees and knots.

Examples

## Since the splines are declared as part of the MTR, you will need## to have parsed out the spline command. Thus, this command will be## called via eval(parse(text = .)). In the examples below, the## commands are parsed from the object \code{splineslist} generated## by \code{\link[MST]{removeSplines}}. The names of the elements in## the list are the spline commands, and the elements themselves are## the terms that interact with the splines.## Declare MTR functionm0 = ~ x1 + x1 : uSpline(degree = 2,                          knots = c(0.2, 0.4)) +    x2 : uSpline(degree = 2,                  knots = c(0.2, 0.4)) +    x1 : x2 : uSpline(degree = 2,                       knots = c(0.2, 0.4)) +    uSpline(degree = 3,             knots = c(0.2, 0.4),             intercept = FALSE)## Separate the spline components from the MTR functionsplineslist <- removeSplines(m0)$splineslist## Delcare the points at which we wish to evaluate the integralsx <- seq(0, 1, 0.2)## Evaluate the splines integralseval(parse(text = gsub("uSpline\\(",                       "ivmte:::uSplineInt(x = x, ",                       names(splineslist)[1])))eval(parse(text = gsub("uSpline\\(",                       "ivmte:::uSplineInt(x = x, ",                       names(splineslist)[2])))

Auxiliary function that converts a vector of strings into anexpression containing variable names.

Description

Auxiliary function that converts a vector of strings into anexpression containing variable names.

Usage

unstring(vector)

Arguments

vector

Vector of variable names (strings).

Value

An expression for the list of variable names that are notstrings.

Examples

ivmte:::unstring(c("a", "b"))

Auxiliary function: extracting elements from strings

Description

This auxiliary function extracts the (string) element in theposition argument of thevector argument.

Usage

vecextract(vector, position, truncation = 0)

Arguments

vector

the vector from which we want to extract theelements.

position

the position invector to extract.

truncation

the number of characters from the front of theelement being extracted that should be dropped.

Value

A chracter/string.


Target weighting function, for ATT

Description

Target weighting function, for the ATT.

Usage

wAttSplines(z, d, ed)

Arguments

z

vector, the value of the instrument (redundant in thisfunction; included to exploit apply()).

d

0 or 1, indicating treatment or control (redundant in thisfunction; included to exploit apply()).

ed

scalar, unconditional probability of taking up treatment.

Value

scalar.


Target weight for ATE

Description

Function generates the target weight for the ATE.

Usage

wate1(data)

Arguments

data

data.frame on which the estimation is performed.

Value

The bounds of integration over unobservableu, aswell as the multiplier in the weight.


Target weight for ATT

Description

Function generates the target weight for the ATT.

Usage

watt1(data, expd1, propensity)

Arguments

data

data.frame on which the estimation is performed.

expd1

Scalar, the probability that treatment is received.

propensity

Vector of propensity to take up treatment.

Value

The bounds of integration over unobservableu, aswell as the multiplier in the weight.


Target weight for ATU

Description

Function generates the target weight for the ATT.

Usage

watu1(data, expd0, propensity)

Arguments

data

data.frame on which the estimation is performed.

expd0

Scalar, the probability that treatment is notrecieved.

propensity

Vector of propensity to take up treatment.

Value

The bounds of integration over unobservableu, aswell as the multiplier in the weight.


Generating splines weights

Description

This function generates the weights required to construct splinesof higher order. This function was coded in accordance to Carl deBoor's set of notes on splines, "B(asic)-Spline Basics".

Usage

weights(x, knots, i, order)

Arguments

x

vector, the values at which to evaluate the basisfunction.

knots

vector, the internal knots.

i

integer, the basis component to be evaluated.

order

integer, the order of the basis. Do not confuse thiswith the degree of the splines, i.e. order = degree + 1.

Value

scalar.


Target weight for generalized LATE

Description

Function generates the target weight for the generalized LATE,where the user can specify the interval of propensity scoresdefining the compliers.

Usage

wgenlate1(data, ulb, uub)

Arguments

data

data.frame on which the estimation is performed.

ulb

Numeric, lower bound of interval.

uub

Numeric, upper bound of interval.

Value

The bounds of integration over unobservableu, aswell as the multiplier in the weight.


Auxiliary function:which for lists

Description

Auxiliary function that makes it possible to usewhich witha list.

Usage

whichforlist(vector, obj)

Arguments

vector

the vector for which we want to check the entries of

obj

the value for which we want the vector to match on.

Value

a vector of positions where the elements invectorare equal toobj.


Target weight for LATE

Description

Function generates the target weight for the LATE, conditioned on aspecific value of the covariates.

Usage

wlate1(data, from, to, Z, model, X, eval.X)

Arguments

data

data.frame on which the estimation is performed.

from

Vector of baseline values for the instruments.

to

Vector of comparison values for the instruments.

Z

Character vector of names of instruments.

model

Alm orglm object, or adata.frame, which can be used to estimate the propensityto take up treatment for the specified values of theinstruments.

X

Character vector of variable names for the non-excludedvariables the user wishes to condition the LATE on.

eval.X

Vector of values the user wishes to condition theX variables on.

Value

The bounds of integration over unobservableu, aswell as the multiplier in the weight.


[8]ページ先頭

©2009-2025 Movatter.jp