forked from kosukeimai/MatchIt
-
Notifications
You must be signed in to change notification settings - Fork 2
/
README.Rmd
85 lines (61 loc) · 4.47 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, echo = FALSE}
knitr::opts_chunk$set(
collapse = FALSE,
warning = FALSE,
message = FALSE,
tidy = FALSE,
fig.align='center',
comment = "#>",
fig.path = "man/figures/README-",
R.options = list(width = 200)
)
```
# MatchIt: Nonparametric Preprocessing for Parametric Causal Inference <img src="man/figures/logo.png" align="right" width="150"/>
[![CRAN_Status_Badge](https://img.shields.io/cran/v/MatchIt?color=952100)](https://cran.r-project.org/package=MatchIt) [![CRAN_Downloads_Badge](https://cranlogs.r-pkg.org/badges/MatchIt?color=952100)](https://cran.r-project.org/package=MatchIt)
------
### Overview
`MatchIt` provides a simple and straightforward interface to various methods of matching for covariate balance in observational studies. Matching is one way to reduce confounding and model dependence when estimating treatment effects. Several matching methods are available, including nearest neighbor matching, optimal pair matching, optimal full matching, generalized full matching, genetic matching, exact matching, coarsened exact matching, cardinality matching, and subclassification, some of which rely on functions from other R packages. A variety of methods to estimate propensity scores for propensity score matching are included. Below is an example of the use of `MatchIt` to perform Mahalanobis distance matching with replacement and assess balance:
```{r}
library("MatchIt")
data("lalonde", package = "MatchIt")
# 1:1 nearest neighbor matching with replacement on
# the Mahalanobis distance
m.out <- matchit(treat ~ age + educ + race + married +
nodegree + re74 + re75,
data = lalonde, distance = "mahalanobis",
replace = TRUE)
```
Printing the `MatchIt` object provides details of the kind of matching performed.
```{r}
m.out
```
We can check covariate balance for the original and matched samples using `summary()`:
```{r}
#Checking balance before and after matching:
summary(m.out)
```
At the top is balance for the original sample. Below that is balance in the matched sample. Smaller values for the balance statistics indicate better balance. (In this case, fairly good balance was achieved, but other matching methods should be tried). We can plot the standardized mean differences in a Love plot for a clean, visual display of balance across the sample:
```{r, fig.alt ="Love plot of balance before and after matching."}
#Plot balance
plot(summary(m.out))
```
Although much has been written about matching theory, most of the theory relied upon in `MatchIt` is described well in [Ho, Imai, King, and Stuart (2007)](https//:doi.org/10.1093/pan/mpl013), [Stuart (2010)](https://doi.org/10.1214/09-STS313), and [Greifer and Stuart (2021)](https://doi.org/10.1093/epirev/mxab003). The *Journal of Statistical Software* article for `MatchIt` can be accessed [here](https://doi.org/10.18637/jss.v042.i08), though note that some options have changed, so the `MatchIt` reference pages and included vignettes should be used for understanding the functions and methods available. Further references for individual methods are present in their respective help pages. The `MatchIt` [website](https://kosukeimai.github.io/MatchIt/) provides access to vignettes and documentation files.
### Citing `MatchIt`
Please cite `MatchIt` when using it for analysis presented in publications, which you can do by citing the *Journal of Statistical Software* article below:
Ho, D. E., Imai, K., King, G., & Stuart, E. A. (2011). MatchIt: Nonparametric Preprocessing for Parametric Causal Inference. *Journal of Statistical Software*, 42(8). [doi:10.18637/jss.v042.i08](https://doi.org/10.18637/jss.v042.i08)
This citation can also be accessed using `citation("MatchIt")` in R. For reproducibility purposes, it is also important to include the version number for the version used.
### Installation
To download and install the latest stable version of `MatchIt` from CRAN, run the following:
```{r, eval=F}
install.packages("MatchIt")
```
To install a development version, which may have a bug fixed or a new feature, run the following:
```{r, eval=F}
install.packages("pak") #If not yet installed
pak::pkg_install("ngreifer/MatchIt")
```
This will require R to compile C++ code, which might require additional software to be installed on your computer. If you need the development version but can't compile the package, ask the maintainer for a binary version of the package.