From 1a7690b902f15c54749551b8c351eecf5109298d Mon Sep 17 00:00:00 2001 From: "Jose R. Zubizarreta" Date: Mon, 18 Jun 2018 17:24:05 +0000 Subject: [PATCH] version 0.3.1 --- DESCRIPTION | 14 ++++---- MD5 | 26 +++++++------- R/cardmatch.r | 9 +++-- R/problemparameters_cardmatch.r | 60 ++++++++++++++++++++++----------- man/absstddif.Rd | 2 +- man/bmatch.Rd | 11 +++--- man/cardmatch.Rd | 11 +++--- man/designmatch-package.Rd | 4 +-- man/distmatch.Rd | 11 +++--- man/ecdfplot.Rd | 2 +- man/finetab.Rd | 2 +- man/loveplot.Rd | 2 +- man/nmatch.Rd | 2 +- man/pairsplot.Rd | 2 +- 14 files changed, 96 insertions(+), 62 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index b95d6a4..277746e 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,17 +1,17 @@ Package: designmatch Type: Package Title: Matched Samples that are Balanced and Representative by Design -Version: 0.3.0 -Date: 2017-05-17 -Author: Jose R. Zubizarreta , Cinar Kilcioglu , Juan P. Vielma -Maintainer: Jose R. Zubizarreta +Version: 0.3.1 +Date: 2018-06-18 +Author: Jose R. Zubizarreta , Cinar Kilcioglu , Juan P. Vielma +Maintainer: Jose R. Zubizarreta Depends: R (>= 3.2), lattice, MASS, slam, Rglpk -Suggests: gurobi, Rcplex, Rsymphony +Enhances: gurobi, Rcplex, Rmosek, Rsymphony SystemRequirements: GLPK library package (e.g., libglpk-dev on Debian/Ubuntu) License: GPL-2 | GPL-3 Description: Includes functions for the construction of matched samples that are balanced and representative by design. Among others, these functions can be used for matching in observational studies with treated and control units, with cases and controls, in related settings with instrumental variables, and in discontinuity designs. Also, they can be used for the design of randomized experiments, for example, for matching before randomization. By default, 'designmatch' uses the 'GLPK' optimization solver, but its performance is greatly enhanced by the 'Gurobi' optimization solver and its associated R interface. For their installation, please follow the instructions at and . We have also included directions in the gurobi_installation file in the inst folder. NeedsCompilation: no -Packaged: 2017-05-18 01:39:38 UTC; jrz +Packaged: 2018-06-18 14:12:15 UTC; jrz Repository: CRAN -Date/Publication: 2017-05-18 03:48:36 UTC +Date/Publication: 2018-06-18 18:24:05 UTC diff --git a/MD5 b/MD5 index c055239..adcef6d 100644 --- a/MD5 +++ b/MD5 @@ -1,9 +1,9 @@ -e6ccf902847f31ee3b7a20750bbc8815 *DESCRIPTION +bd3c4c85871ceff1cc5f2f0f9cdb44a5 *DESCRIPTION a84e461889448bab6f00dc036a173876 *NAMESPACE 4035589e4087aa8c0dfc97e90db340f8 *R/absstddif.r 7d1a85944bcd2594e3ab13ffdd80bd1e *R/addcalip.r 06d2cede573309b27980bbb8869ad01e *R/bmatch.r -932c4f0f192b4f4901220dcb169c4d50 *R/cardmatch.r +53910a26ffdd46067f0ff93d9694b58d *R/cardmatch.r 1ccbbc3d8e654fcd4366a8c93350178b *R/constraintmatrix.r ddd36bec26100d3064a1bf106c36740c *R/distmat.r 692b745a194a270376faf4842b958a02 *R/distmatch.r @@ -15,7 +15,7 @@ d3df5386a7329cd2c93dedac69a83db4 *R/meantab.r 4a4e30c24c6373c9118b32245b3f29fc *R/nmatch.r 98f291ae461a0b1c18ea5d8858b3eb22 *R/pairsplot.r 36d380e4bd2fb8bbd551af173cc12056 *R/problemparameters.r -3fc3b874e31fb6965591687cfc0481c9 *R/problemparameters_cardmatch.r +6c4827264e52d44760c865663f2e6c2d *R/problemparameters_cardmatch.r faaeb63e221a183bf338d8005151bb03 *R/relaxation_b.r 1ee8331d65f0dab43a41bd5a4740fcdf *R/relaxation_n.r 8a6974d5a5f551af3ca1e1be7d555be6 *R/smahal.r @@ -23,17 +23,17 @@ faaeb63e221a183bf338d8005151bb03 *R/relaxation_b.r 7c8f4dadefa6fd57a06a23067605dda0 *data/lalonde.rda fca1c5c2ab15ec2207f7f77919cca494 *inst/gurobi_installation.txt 8b5ab702a3ca62c67934d34220c09ab6 *inst/symphony_installation.txt -a3432aa9ad196973c884751e3a7e0fb4 *man/absstddif.Rd -e19dd3ffc9a2b389b9ad4c0a7a082600 *man/bmatch.Rd -2f242dd6c23bbb2cf7b56ab900a74572 *man/cardmatch.Rd -70d7c69f620facbd7955281a7d6bbf1b *man/designmatch-package.Rd +a8685672a86c1c9e7c630b430a193f5f *man/absstddif.Rd +6ec4ccf8e22c37bac38e74e20aedfa84 *man/bmatch.Rd +d26a6354e52f7b5a8d74a5fec2f4c4df *man/cardmatch.Rd +f57efa7f8b3a56947c842360a6be4c4b *man/designmatch-package.Rd 9d510e34095ba20a26ae6ed0e3b7807a *man/distmat.Rd -90779867557e9b66310864ca76f825f5 *man/distmatch.Rd -60560ddae0cc24fb6cedc7785379fd3d *man/ecdfplot.Rd -093455696515de415adc6c394e839715 *man/finetab.Rd +3562e9d06db45009486c574740e620a4 *man/distmatch.Rd +1d59c6df9d58dd6a7d6d7e94a0a535b8 *man/ecdfplot.Rd +e7f0f69f8b70ba4d92f21b1d93d60bec *man/finetab.Rd 3e98c15e211274459bbe5239f7342766 *man/germancities.Rd d956e94f68ff0196119800ab2e887d19 *man/lalonde.Rd -178925f2ba0ec6cb0cf7c88bd5f936c2 *man/loveplot.Rd +e6792c32417b2ef50459d550ed90b83f *man/loveplot.Rd 1616542174f147bf821c0ca73161fb10 *man/meantab.Rd -50a270039e2ddaa4d21bd7dcbc668c9a *man/nmatch.Rd -3a8a8aafd46dc6a04a0f186139fe43f9 *man/pairsplot.Rd +294e9c9f7e988b764df5ea51f1d36ddd *man/nmatch.Rd +54aa121631d4cc210c88409123f0cbec *man/pairsplot.Rd diff --git a/R/cardmatch.r b/R/cardmatch.r index e46d0e6..cabbfa1 100644 --- a/R/cardmatch.r +++ b/R/cardmatch.r @@ -8,8 +8,13 @@ cardmatch = function(t_ind, mom = NULL, fine = NULL, solver = NULL) { } else { mom_covs = mom$covs mom_tols = mom$tols - mom_targets = mom$targets - } + if (is.null(mom$targets)) { + mom_targets = NULL + } + if (!is.null(mom$targets)) { + mom_targets = mom$targets + } + } if (is.null(fine)) { fine_covs = NULL } else { diff --git a/R/problemparameters_cardmatch.r b/R/problemparameters_cardmatch.r index df6e41d..baabe2b 100644 --- a/R/problemparameters_cardmatch.r +++ b/R/problemparameters_cardmatch.r @@ -20,25 +20,39 @@ vals_mom = NULL n_mom_covs = ncol(mom_covs) k = 1 - for (i in 1:n_mom_covs) { - #! Treated - rows_mom_plus = rep(row_ind_cur+k, n_t) - rows_mom_minus = rep(row_ind_cur+k+1, n_t) - rows_mom = c(rows_mom, rows_mom_plus, rows_mom_minus) - cols_mom = c(cols_mom, rep(1:n_t, 2)) - vals_plus = c(mom_covs[t_ind==1, i]-mom_targets[i]-mom_tols[i]) - vals_minus = c(mom_covs[t_ind==1, i]-mom_targets[i]+mom_tols[i]) - vals_mom = c(vals_mom, c(vals_plus, vals_minus)) - #! Controls - rows_mom_plus = rep(row_ind_cur+k+2, n_c) - rows_mom_minus = rep(row_ind_cur+k+3, n_c) - rows_mom = c(rows_mom, rows_mom_plus, rows_mom_minus) - cols_mom = c(cols_mom, rep(n_t+(1:n_c), 2)) - vals_plus = c(mom_covs[t_ind==0, i]-mom_targets[i]-mom_tols[i]) - vals_minus = c(mom_covs[t_ind==0, i]-mom_targets[i]+mom_tols[i]) - vals_mom = c(vals_mom, c(vals_plus, vals_minus)) - k = k+4 + if (!is.null(mom_targets)) { + for (i in 1:n_mom_covs) { + #! Treated + rows_mom_plus = rep(row_ind_cur+k, n_t) + rows_mom_minus = rep(row_ind_cur+k+1, n_t) + rows_mom = c(rows_mom, rows_mom_plus, rows_mom_minus) + cols_mom = c(cols_mom, rep(1:n_t, 2)) + vals_plus = c(mom_covs[t_ind==1, i]-mom_targets[i]-mom_tols[i]) + vals_minus = c(mom_covs[t_ind==1, i]-mom_targets[i]+mom_tols[i]) + vals_mom = c(vals_mom, c(vals_plus, vals_minus)) + #! Controls + rows_mom_plus = rep(row_ind_cur+k+2, n_c) + rows_mom_minus = rep(row_ind_cur+k+3, n_c) + rows_mom = c(rows_mom, rows_mom_plus, rows_mom_minus) + cols_mom = c(cols_mom, rep(n_t+(1:n_c), 2)) + vals_plus = c(mom_covs[t_ind==0, i]-mom_targets[i]-mom_tols[i]) + vals_minus = c(mom_covs[t_ind==0, i]-mom_targets[i]+mom_tols[i]) + vals_mom = c(vals_mom, c(vals_plus, vals_minus)) + k = k+4 + } } + if (is.null(mom_targets)) { + for (i in 1:n_mom_covs) { + rows_mom_plus = rep(row_ind_cur+k, n_t+n_c) + rows_mom_minus = rep(row_ind_cur+k+1, n_t+n_c) + rows_mom = c(rows_mom, rows_mom_plus, rows_mom_minus) + cols_mom = c(cols_mom, rep(1:(n_t+n_c), 2)) + vals_plus = c(mom_covs[t_ind==1, i]-mom_tols[i], -mom_covs[t_ind==0, i]) + vals_minus = c(mom_covs[t_ind==1, i]+mom_tols[i], -mom_covs[t_ind==0, i]) + vals_mom = c(vals_mom, c(vals_plus, vals_minus)) + k = k+2 + } + } row_ind_cur = max(rows_mom) } #! Fine balance @@ -113,8 +127,14 @@ sense = NULL #! Mom balance if (!is.null(mom_covs)) { - sense_covs = rep(c("L", "G", "L", "G"), length(unique(rows_mom))/4) - sense = c(sense, sense_covs) + if (!is.null(mom_targets)) { + sense_covs = rep(c("L", "G", "L", "G"), length(unique(rows_mom))/4) + sense = c(sense, sense_covs) + } + if (is.null(mom_targets)) { + sense_covs = rep(c("L", "G"), length(unique(rows_mom))/2) + sense = c(sense, sense_covs) + } } #! Fine balance if (!is.null(fine_covs)) { diff --git a/man/absstddif.Rd b/man/absstddif.Rd index af4c733..bccc5e7 100644 --- a/man/absstddif.Rd +++ b/man/absstddif.Rd @@ -30,7 +30,7 @@ } \author{ - Jose R. Zubizarreta , Cinar Kilcioglu . + Jose R. Zubizarreta , Cinar Kilcioglu . } \examples{ diff --git a/man/bmatch.Rd b/man/bmatch.Rd index 6d6c30e..290208b 100644 --- a/man/bmatch.Rd +++ b/man/bmatch.Rd @@ -17,7 +17,7 @@ \arguments{ -\item{t_ind}{treatment indicator: a vector of zeros and ones indicating treatment (1 = treated; 0 = control).} +\item{t_ind}{treatment indicator: a vector of zeros and ones indicating treatment (1 = treated; 0 = control). Please note that the data needs to be sorted in decreasing order according to this treatment indicator.} \item{dist_mat}{distance matrix: a matrix of positive distances between treated units (rows) and controls (columns). If \code{dist_mat = NULL} and \code{subset_weight = 1}, then bmatch will solve the cardinality matching problem in Zubizarreta et al. (2014).} @@ -134,7 +134,7 @@ tional studies," \emph{Journal of Computational and Graphical Statistics}, 21, 5 } \author{ - Jose R. Zubizarreta , Cinar Kilcioglu . + Jose R. Zubizarreta , Cinar Kilcioglu . } \seealso{ @@ -143,8 +143,9 @@ tional studies," \emph{Journal of Computational and Graphical Statistics}, 21, 5 \examples{ -# Load and attach data +# Load, sort, and attach data data(lalonde) +lalonde = lalonde[order(lalonde$treatment, decreasing = TRUE), ] attach(lalonde) ################################# @@ -156,8 +157,10 @@ attach(lalonde) # exact matching for different covariates. The solver used is glpk with the # approximate option. -# Treatment indicator +# Treatment indicator; note that the data needs to be sorted in decreasing order +# according to this treatment indicator t_ind = treatment +t_ind # Distance matrix dist_mat = NULL diff --git a/man/cardmatch.Rd b/man/cardmatch.Rd index 51490b2..225c766 100644 --- a/man/cardmatch.Rd +++ b/man/cardmatch.Rd @@ -14,7 +14,7 @@ \arguments{ -\item{t_ind}{treatment indicator: a vector of zeros and ones indicating treatment (1 = treated; 0 = control).} +\item{t_ind}{treatment indicator: a vector of zeros and ones indicating treatment (1 = treated; 0 = control). Please note that the data needs to be sorted in decreasing order according to this treatment indicator.} \item{mom}{moment balance parameters: a list with three arguments, @@ -73,7 +73,7 @@ Optimization solver parameters: a list with four objects, } \author{ - Jose R. Zubizarreta , Cinar Kilcioglu , Juan P. Vielma . + Jose R. Zubizarreta , Cinar Kilcioglu , Juan P. Vielma . } \seealso{ @@ -82,8 +82,9 @@ Optimization solver parameters: a list with four objects, \examples{ -# Load and attach data +# Load, sort, and attach data data(lalonde) +lalonde = lalonde[order(lalonde$treatment, decreasing = TRUE), ] attach(lalonde) ################################# @@ -107,8 +108,10 @@ education_5 = quantiles(education, 5) re74_5 = quantiles(re74, 5) re75_5 = quantiles(re75, 5) -# Treatment indicator +# Treatment indicator; note that the data needs to be sorted in decreasing order +# according to this treatment indicator t_ind = treatment +t_ind # Fine balance fine_covs = cbind(black, hispanic, married, nodegree, age_5, education_5, re74_5, re75_5) diff --git a/man/designmatch-package.Rd b/man/designmatch-package.Rd index c82bc39..d24940b 100644 --- a/man/designmatch-package.Rd +++ b/man/designmatch-package.Rd @@ -18,9 +18,9 @@ License: \tab GPL-2 | GPL-3\cr } } \author{ - Jose R. Zubizarreta , Cinar Kilcioglu . + Jose R. Zubizarreta , Cinar Kilcioglu . -Maintainer: Jose R. Zubizarreta , Cinar Kilcioglu . +Maintainer: Jose R. Zubizarreta , Cinar Kilcioglu . } \references{ Greevy, R., Lu, B., Silber, J. H., and Rosenbaum, P. R. (2004), "Optimal Multivariate diff --git a/man/distmatch.Rd b/man/distmatch.Rd index d3a2421..4842ccc 100644 --- a/man/distmatch.Rd +++ b/man/distmatch.Rd @@ -14,7 +14,7 @@ \arguments{ -\item{t_ind}{treatment indicator: a vector of zeros and ones indicating treatment (1 = treated; 0 = control).} +\item{t_ind}{treatment indicator: a vector of zeros and ones indicating treatment (1 = treated; 0 = control). Please note that the data needs to be sorted in decreasing order according to this treatment indicator.} \item{dist_mat}{distance matrix: a matrix of positive distances between treated units (rows) and controls (columns). If \code{dist_mat = NULL} and \code{subset_weight = 1}, then bmatch will solve the cardinality matching problem in Zubizarreta et al. (2014).} @@ -58,7 +58,7 @@ Optimization solver parameters: a list with four objects, } \author{ - Jose R. Zubizarreta , Cinar Kilcioglu . + Jose R. Zubizarreta , Cinar Kilcioglu . } \seealso{ @@ -67,8 +67,9 @@ Optimization solver parameters: a list with four objects, \examples{ -# Load and attach data +# Load, sort, and attach data data(lalonde) +lalonde = lalonde[order(lalonde$treatment, decreasing = TRUE), ] attach(lalonde) ################################# @@ -92,8 +93,10 @@ education_5 = quantiles(education, 5) re74_5 = quantiles(re74, 5) re75_5 = quantiles(re75, 5) -# Treatment indicator +# Treatment indicator; note that the data needs to be sorted in decreasing order +# according to this treatment indicator t_ind = treatment +t_ind # Fine balance fine_covs = cbind(black, hispanic, married, nodegree, age_5, education_5, re74_5, re75_5) diff --git a/man/ecdfplot.Rd b/man/ecdfplot.Rd index 2c824d7..a5b3ac9 100644 --- a/man/ecdfplot.Rd +++ b/man/ecdfplot.Rd @@ -33,7 +33,7 @@ } \author{ - Jose R. Zubizarreta , Cinar Kilcioglu . + Jose R. Zubizarreta , Cinar Kilcioglu . } \examples{ diff --git a/man/finetab.Rd b/man/finetab.Rd index d790bd0..7db463a 100644 --- a/man/finetab.Rd +++ b/man/finetab.Rd @@ -30,7 +30,7 @@ } \author{ - Jose R. Zubizarreta , Cinar Kilcioglu . + Jose R. Zubizarreta , Cinar Kilcioglu . } \examples{ diff --git a/man/loveplot.Rd b/man/loveplot.Rd index 76dd9ac..ec84425 100644 --- a/man/loveplot.Rd +++ b/man/loveplot.Rd @@ -36,7 +36,7 @@ } \author{ - Jose R. Zubizarreta , Cinar Kilcioglu . + Jose R. Zubizarreta , Cinar Kilcioglu . } \examples{ diff --git a/man/nmatch.Rd b/man/nmatch.Rd index 17be727..290ef49 100644 --- a/man/nmatch.Rd +++ b/man/nmatch.Rd @@ -124,7 +124,7 @@ tional studies," \emph{Journal of Computational and Graphical Statistics}, 21, 5 } \author{ - Jose R. Zubizarreta , Cinar Kilcioglu . + Jose R. Zubizarreta , Cinar Kilcioglu . } %\seealso{ diff --git a/man/pairsplot.Rd b/man/pairsplot.Rd index 10e77b9..dea31f6 100644 --- a/man/pairsplot.Rd +++ b/man/pairsplot.Rd @@ -40,7 +40,7 @@ } \author{ - Jose R. Zubizarreta , Cinar Kilcioglu . + Jose R. Zubizarreta , Cinar Kilcioglu . } \examples{