0
$\begingroup$

I am analyzing observational data and want to perform propensity score matching. I would like to compare males and females matched for age,smoking status, bmi, etc. When I coded the male gender as 0 and female as 1 my covariates were very unbalanced after the matching. However, when I coded females as 0 and males as 1, my covariates were balanced after matching. How can this be? I am using the matchit function in R.

I swapped the coding of the control and treatment and received varying results.

$\endgroup$
2
  • 1
    $\begingroup$ Please make this question reproducible. This includes sample code you've attempted (including listing non-base R packages, and any errors/warnings received), sample unambiguous data (e.g., data.frame(x=...,y=...) or the output from dput(head(x)) into a code block), and intended output given that input. Refs: stackoverflow.com/q/5963269, [mcve], and stackoverflow.com/tags/r/info. $\endgroup$
    – r2evans
    Commented Apr 4 at 12:14
  • $\begingroup$ Does R understand that the input is a factor and not continuous? It would be helpful if you could "glimpse" or "str" the data so the inputs were known. It would also be helpful if we could see the actual analytical function, because you might be missing a flag, or something. $\endgroup$ Commented Apr 5 at 12:44

1 Answer 1

3
$\begingroup$

There are several ways matchit() can perform nearest neighbor matching depending on the arguments you give it. By default, it works as follows:

  1. The propensity score (probability of being treated, i.e., having a 1) is estimated for each unit.
  2. Treated units are sort in descending order by the propensity score, so units with the highest propensity score are earlier in the list.
  3. For each treated unit, the untreated unit with the closest propensity score is chosen as a match and then prevented from being used as a match for any other treated unit.
  4. The matching stops when all treated units receive a match or there are no more untreated units to be used as matches.

When you set being a male to having the value 1, then the propensity score is the probability of being a male, so males with the highest probability of being male are matched first. When you set being a female to having the value 1, then the propensity score is the probability of being a female, so females with the highest probability of being female are matched first. That means different units are being matched in a different order depending on which level is set as 1, which is why you observed such a difference.

This is not the only way to match and not necessarily even the best way. Setting m.order = "closest" instead finds the closest pairs and matches them regardless of where the units would fall if they were sorted by their propensity score. That means this method is symmetric across treatment values and you should get the same matched set whether male is 1 or female is 1. This is described in the documentation so please read it :)

$\endgroup$
1
  • $\begingroup$ Perfect, this has solved everything. Thank you very much! $\endgroup$ Commented Apr 9 at 8:12

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.