Using Zelig with the MatchIt Package for Matched Datasets¶

Zelig accepts the output object from the MatchIt package as the data argument.

First, using the MatchIt package, we attaching the lalonde example dataset, and run matching:

library("MatchIt")
## Loading required package: MASS
data(turnout)
m.out <- matchit(treat ~ educ + black + hispan, data=lalonde, method= "optimal")
## Loading required package: optmatch
## Loading required package: survival
## The optmatch package has an academic license. Enter relaxinfo() for more information.
## Warning in fullmatch(d, min.controls = ratio, max.controls = ratio, omit.fraction = (n0 - : Without 'data' argument the order of the match is not guaranteed
##     to be the same as your original data.
## Warning in fullmatch.matrix(d, min.controls = ratio, max.controls = ratio,
## : The problem is infeasible with the given constraints; some units were
## omitted to allow a match.

Then we can use the output object from the MatchIt package directly in the data argument for Zelig:

z.out <- zelig(educ ~ treat, model="ls", data=m.out)
## Warning in readLines(zeligmixedmodels): incomplete final line found on
## '/usr/lib64/R/library/ZeligMultilevel/JSON/zelig5mixedmodels.json'
## How to cite this model in Zelig:
##   R Core Team. 2007.
##   ls: Least Squares Regression for Continuous Dependent Variables
##   in Christine Choirat, James Honaker, Kosuke Imai, Gary King, and Olivia Lau,
##   "Zelig: Everyone's Statistical Software," http://zeligproject.org/

Zelig will automatically extract the dataset and the weights from the MatchIt object and use them in analysis. For more details on how weights are used in Zelig across models, see the weights section.

From the MatchIt object, it knows what matching method was used, and adds appropriate citations to the reference list accordingly, in addition to the other references it builds from models and utilities in Zelig:

print(z.out$references())
## Ho DE, Imai K, King G and Stuart EA (2011). "MatchIt:
## Nonparametric Preprocessing for Parametric Causal Inference."
## *Journal of Statistical Software*, **42** (8), pp. 1-28. <URL:
## http://www.jstatsoft.org/v42/i08/>.
##
## Hansen BB and Klopfer SO (2006). "Optimal full matching and
## related designs via network flows." *Journal of Computational and
## Graphical Statistics*, **15** (3), pp. 609-627.
##
## R Core Team (2016). *R: A Language and Environment for Statistical
## Computing*. R Foundation for Statistical Computing, Vienna,
## Austria. <URL: https://www.R-project.org/>.
## NULL