Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error in matchit if option ratio > 1 is included - MatchIt package #208

Open
Monique84 opened this issue Dec 18, 2024 · 2 comments
Open

Comments

@Monique84
Copy link

Monique84 commented Dec 18, 2024

I need to do a matching on data to have it balanced for the two groups defined by a variable according to certain variables. I want to do a 1:2 matching.
I used this code a few months ago and it returned what I needed.
Today I tried to run it again but the outcome was not the same and I think there is a bug.
When I display the dataset post matching I have the subclass variable which should tell me each case which 2 controls it has been matched to. But this doesn't work well today: I see 2 records for each subclass value (1 case and 1 control) until the last subclass for which I see 1 case and lots of controls. The total records are 3 times the number of cases to be matched but the subclasses are not correct and I cannot verify each case to which 2 controls it has been matched.

Actual versions:
R version 4.4.2 (2024-10-31 ucrt)
MatchIt version: 4.6.0

This is the code:

library(MatchIt)
library(writexl)

data("lalonde")
m.out2<-matchit(treat ~ age+educ+married+race,data = lalonde, method = "nearest",
distance = "mahalanobis", exact = c("race"), caliper = c(age = 5), std.caliper = FALSE,ratio = 2, random = TRUE)

m.data2 <- match.data(m.out2)

write_xlsx(m.data2, "m.data2.xlsx")

Screenshot 2024-12-18 080650

@ngreifer
Copy link
Collaborator

Sorry about this. It is a known issue, and I fixed it in the development version, which you can install using remotes::install_github("ngreifer/MatchIt"). I'm working on getting it onto CRAN soon.

@Monique84
Copy link
Author

Thank you very much. I was able to do the matching the right way with this development version of the package!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants