1
$\begingroup$

I am doing the nearest neighbour matching from the package MatchIt. For example

data("lalonde")
m.out1 <- matchit(
    treat ~ age + educ, 
    data = lalonde,
    method = "nearest",
    distance = "glm",
    replace = FALSE
)

But this algorithm is sensitive to the order that the treated units are matched. As in The Effect: An Introduction to Research Design and Causality, a book by Nick Huntington-Klein enter image description here

I wish to see the effect of this randomness on my result. For example, without replacement, I can generate 100 different matching results and compare how different they are or derive the variation in matching results. How can I get this kind of different matching results by matchit? I tried set.seed() in R and it returns the same results.

Thank you a ton in advance.

$\endgroup$
3
  • 1
    $\begingroup$ Have you thought of reordering the original data? $\endgroup$
    – whuber
    Commented May 9, 2023 at 19:03
  • $\begingroup$ @whuber Yes I tried set.seed() and slice_sample(). The result is the same. $\endgroup$
    – xxx
    Commented May 10, 2023 at 10:11
  • 1
    $\begingroup$ I don't see how either of those reorder your data. This sounds like a programming issue... $\endgroup$
    – whuber
    Commented May 10, 2023 at 13:04

1 Answer 1

3
$\begingroup$

The matching order is controlled by the m.order argument, as explained in the documentation for matchit(). There are four options currently available:

  • "largest" - matches treated units with the highest propensity score first (in theory, these will be the hardest to match); this is the default for propensity score matching
  • "smallest" - matches the treated units with the lowest propensity score first (in theory, these will be the easiest to match)
  • "data" - matches treated units in the order they appear in the dataset; this is the default for Mahalanobis distance matching or when matching on a distance matrix
  • "random" - matches treated units in a random order

All of these are deterministic except "random", meaning you will get the same results each time you run them. With m.order = "random", changing the seed should yield different results each time and you must set a seed to be able to replicate the match. Only "data" is affected by the order of the data, so reordering your data will not change matches using the other options.

Another option is to use method = "optimal", which performs optimal matching. Optimal matching is also a deterministic algorithm that minimizes the overall within-pair distances in the full sample, not just in one pair at a time. In this way, it avoids the arbitrariness of greedy matching.

The literature has also described another method that can work well but isn't implemented in MatchIt, which is to match treated units with the closest control unit first. This algorithm is slower and often performs similarly to "smallest" anyway.

$\endgroup$
3
  • $\begingroup$ Thank you so much @Noah. One quick question, with m.order option, the matched matrix returned is still related to the 'data' right? $\endgroup$
    – xxx
    Commented May 10, 2023 at 15:55
  • $\begingroup$ Yes, so it will be in the same order every time unless you manually re-shuffle the dataset. It is organized by the rownames of the dataset. $\endgroup$
    – Noah
    Commented May 10, 2023 at 15:56
  • $\begingroup$ Great, thank you. $\endgroup$
    – xxx
    Commented May 10, 2023 at 16:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.