Written and maintained by CASRAI Editorial Board
Published · Last updated
On this page
MatchIt is an R package (CRAN, GPL-2 or GPL-3) that preprocesses observational data by matching, weighting or subclassifying treated and control units so that the covariates are balanced before you estimate a treatment effect. This page is for analysts who need to install it, run a first match, choose among the matchit() options, and read the balance output well enough to decide whether to keep matching or stop. It was checked against CRAN and the package documentation on 2026-11-07.
What MatchIt is used for in research
MatchIt implements the approach of Ho, Imai, King and Stuart (2007), "Matching as Nonparametric Preprocessing for Reducing Model Dependence in Parametric Causal Inference": match first, then fit your usual outcome model on the matched data. The CRAN page lists the maintainer as Noah Greifer and version 4.8.2 (published 2026-11-01), which depends on R 4.1.0 or later. Typical uses are cohort comparisons without randomisation, such as program evaluations or exposure studies, where treated and untreated groups differ on measured covariates. For the method behind it, see propensity score matching explained; for a Stata equivalent, see propensity score matching in Stata.
MatchIt is distributed as an R package. If you search for "matchit r", this is the package meant; the other R packages that do related work are compared in the alternatives table below.
Install or access (official source only)
MatchIt is on CRAN. From an R session with R 4.1.0 or later:
install.packages("MatchIt")
library("MatchIt")
The general mechanics of installing packages are covered in how to install R packages. The package’s Suggests field lists optmatch, Matching, cobalt, marginaleffects and sandwich, which support optimal matching, genetic matching, extra balance plots and effect estimation. The optional gurobi solver is not on CRAN. The package website with the reference pages and vignettes is kosukeimai.github.io/MatchIt.
Step-by-step task: match, check balance, estimate an effect
The steps follow the "Getting Started" vignette, which uses the lalonde job-training data shipped with the package (treatment treat, outcome re78).
- Check the starting imbalance without matching. Setting
method = NULLestimates the propensity score but does not match:m.out0 <- matchit(treat ~ age + educ + race + married + nodegree + re74 + re75, data = lalonde, method = NULL, distance = "glm") summary(m.out0) - Run a match. Nearest-neighbor matching on a logistic propensity score is the default (
method = "nearest",distance = "glm",link = "logit"):m.out1 <- matchit(treat ~ age + educ + race + married + nodegree + re74 + re75, data = lalonde, method = "nearest", distance = "glm") - Read the balance.
summary(m.out1, un = FALSE)prints only the matched-sample table. Plot it withplot(summary(m.out1)), or draw distributions withplot(m.out1, type = "density", interactive = FALSE, which.xs = ~age + married + re75). For publication-style plots see Love plots and covariate balance. - Iterate if needed. The vignette’s next match uses
method = "full"withlink = "probit". Change one option at a time and compare the summaries. - Extract the matched data.
m.data <- match_data(m.out1)returns the matched sample with three added columns:distance,weightsandsubclass. - Estimate the effect. Fit the outcome model with the weights and use cluster-robust standard errors, for example with the marginaleffects package:
library("marginaleffects") fit <- lm(re78 ~ treat * (age + educ + race + married + nodegree + re74 + re75), data = m.data, weights = weights) avg_comparisons(fit, variables = "treat", vcov = ~subclass, newdata = subset(treat == 1))
The vignette states: "The outcome model coefficients and tests should not be interpreted or reported," and recommends cluster-robust standard errors for most analyses, with pair membership as the clustering variable. Report the estimated effect from the comparison step, not the raw regression coefficients.
Which matchit() option answers which question
The full signature in the reference is matchit(formula, data, method = "nearest", distance = "glm", link = "logit", distance.options, estimand = "ATT", exact, mahvars, antiexact, discard = "none", reestimate = FALSE, s.weights, replace = FALSE, m.order, caliper, std.caliper = TRUE, ratio = 1, verbose = FALSE, include.obj = FALSE, normalize = TRUE, ...). This table maps the options people search for to what each changes, as documented in the reference page.
| Option | Question it answers | What the reference says |
|---|---|---|
method |
Which matching algorithm? | nearest, optimal, full, quick, genetic, cem, exact, cardinality, subclass; NULL skips matching but still allows propensity score estimation and common-support checks. |
distance and link |
How is closeness measured? | Default is a propensity score from a generalized linear model ("glm") with a logit link; distance = "mahalanobis" matches on covariates directly (see Mahalanobis distance). |
replace |
Can one control serve several treated units? | Default FALSE; TRUE allows matching with replacement. |
mahvars |
Can I match on Mahalanobis distance within a propensity-score caliper? | Specifies variables for Mahalanobis matching, typically used together with a caliper on the propensity score; give a character vector or a one-sided formula such as ~ age + educ. |
caliper and std.caliper |
How far apart may a pair be? | An unnamed value applies to the distance measure; std.caliper = TRUE reads it in standard-deviation units. Named values set per-covariate calipers. |
exact |
Must pairs agree on a variable? | Used for exact matching on the variables you name, for example exact = ~ married + race in the reference examples. |
ratio |
How many controls per treated unit? | Default 1. |
estimand |
Which population does the effect describe? | ATT (default), ATC or ATE. The reference cautions that setting ATT does not by itself guarantee that the average treatment effect in the treated is what you end up estimating. |
discard |
Drop units outside common support? | Default "none". |
s.weights |
Do I have survey or sampling weights? | Pass the sampling weights here; the package has a vignette on matching with sampling weights. |
The reference page’s own examples combine these, for instance Mahalanobis distance with replacement and exact matching on married and race, or a probit propensity score with mahvars = ~ age + educ + re74 + re75, caliper = .1 and ratio = 2.
Output and how to read it
Printing the object shows the call and sample sizes. summary() gives a balance table with one row per covariate and these columns:
- Means Treated / Means Control: covariate means in each group.
- Std. Mean Diff.: the standardized mean difference; values near zero indicate good balance.
- Var. Ratio: the ratio of treated to control variances; values near one indicate good balance.
- eCDF Mean / eCDF Max: differences between the empirical distribution functions of the two groups.
- Std. Pair Dist.: the standardized distance within matched pairs.
A sample-size table reports All, Matched, Unmatched and Discarded counts; full matching adds an effective sample size (ESS) row. A practical way to use these columns: compare the matched rows with the unmatched rows (summary(m.out0)), confirm the standardized differences moved toward zero for the covariates that matter to the outcome, and check that the matched sample size is still adequate. If balance is poor, change the method, distance or calipers and rerun; if it is good, move to effect estimation. The returned object also carries match.matrix, weights, subclass, distance, discarded and estimand (subclassification returns no match.matrix). A related weighting approach is inverse probability weighting.
Troubleshooting
- Method needs another package. Optimal and full matching rely on optmatch and genetic matching on Matching; both are listed in Suggests on CRAN. Install them with
install.packages()if a method asks for one. - Install fails on an older R. The current CRAN release depends on R 4.1.0 or later; update R first.
- Balance still poor. Try a different
method, add acaliper, addexacton a key categorical covariate, or revise the propensity score model. - Too few matched units. Matching without replacement and tight calipers shrink the sample; check the sample-size table and consider
replace = TRUEor a looser caliper. - Standard errors look too small. Use cluster-robust errors with pair membership (
subclass) as the clustering variable, as in step 6.
Free alternatives and companions
These R packages are open-source on CRAN; versions are as listed on their CRAN pages on 2026-11-07.
| Package | What CRAN says it does | CRAN version, license |
|---|---|---|
| MatchIt | Nonparametric preprocessing for parametric causal inference via matching, weighting and subclassification. | 4.8.2, GPL-2 or GPL-3 |
| Matching | Multivariate and propensity score matching with balance optimization using a genetic search algorithm. | 4.10-15, GPL-3 |
| optmatch | Distance-based bipartite matching using minimum cost flow, for treatment and control groups in observational studies. | 0.10.8, MIT + file LICENSE |
| cobalt | Covariate balance tables and plots after matching, weighting or subclassification; integrates with MatchIt, WeightIt, Matching, optmatch and others. | 5.0.0, GPL-2 or GPL-3 |
| WeightIt | Balancing weights for causal effect estimation in observational studies with binary, multi-category or continuous treatments. | 2.1.0, GPL-2 or GPL-3 |
FAQ
What does MatchIt do?
It matches, weights or subclassifies treated and control units on observed covariates so that the groups are comparable before you estimate a treatment effect with an ordinary outcome model.
Is there a MatchIt example I can run?
Yes. The six steps above follow the package’s own Getting Started workflow on the bundled lalonde data, and the reference page ships further examples.
What is the MatchIt formula?
The first argument is a formula with the treatment indicator on the left and covariates on the right, for example treat ~ age + educ + race. It is used to estimate the propensity score (or, with Mahalanobis distance, to define the covariates matched on).
What does mahvars do?
It names variables for Mahalanobis-distance matching, typically inside a caliper on the propensity score, so pairs are close on the score and on those covariates.
How do I match with replacement?
Set replace = TRUE. The default is FALSE, where each control is used at most once.
Where is the MatchIt documentation and source?
The package website at kosukeimai.github.io/MatchIt hosts the reference pages and vignettes; the released package is on CRAN.
Sources (official documentation, read 2026-11-07)
- MatchIt on CRAN
- matchit() reference
- Getting Started with MatchIt (vignette)
- Ho, D. E., Imai, K., King, G., and Stuart, E. A. (2007). Matching as nonparametric preprocessing for reducing model dependence in parametric causal inference. Political Analysis, 15(3), 199-236. CRAN lists this work as the basis of the package.
- CRAN pages for cobalt, optmatch, Matching and WeightIt
Cite the software itself following how to cite software, code and R packages.







