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

optimal method with exact matching on some variables #60

Closed
jiweihe1223 opened this issue Feb 26, 2021 · 6 comments
Closed

optimal method with exact matching on some variables #60

jiweihe1223 opened this issue Feb 26, 2021 · 6 comments

Comments

@jiweihe1223
Copy link

jiweihe1223 commented Feb 26, 2021

I used the method = “exact” option to force exact matching on some variables and used other methods for the other variables.

The method = “nearest” approach worked as expected. However, when I tried switching the argument to method = “optimal”, it seems the matching id output by match.matrix do not show the expected matching for the variables specified in the exact option. Why is it so?

You can see in the output, subject 2 and subject 25 who are matched do not have the same age.

Code I used:
match= matchit(A ~ SEX + AGE + V1 + V2, method = "optimal",
exact = c("SEX", "AGE"), data = data_test)
match_id<-match$match.matrix
N<-9
match_id2<-c(1:N, match_id)

match_data<-match.data(match)
#reorder matched control in the same order as treated
match_data2<-match_data[match_id2, ]
match_data2$match_id<-rep(1:N, 2)

Output:

match_data2
SEX AGE V1 V2 A distance weights subclass match_id
1 F 8 5.4 6.0 1 0.19925382 1 1 1
2 F 9 5.7 2.6 1 0.52655669 1 2 2
3 M 10 5.6 1.6 1 0.25929894 1 3 3
4 F 8 5.1 3.7 1 0.19159122 1 4 4
5 M 8 4.6 2.9 1 0.03403255 1 5 5
6 M 7 5.7 4.9 1 0.30804933 1 6 6
7 F 7 5.2 5.2 1 0.21183573 1 7 7
8 F 6 5.3 5.6 1 0.30090303 1 8 8
9 F 6 4.4 4.2 1 0.06211456 1 9 9
30 M 8 5.4 4.1 0 0.15866640 1 1 1
25 F 8 5.4 2.7 0 0.41199904 1 2 2
13 F 6 5.0 3.7 0 0.26556803 1 3 3
28 M 8 5.4 3.9 0 0.16722246 1 4 4
53 F 6 4.3 5.6 0 0.03196558 1 5 5
24 M 7 5.7 4.9 0 0.30804933 1 6 6
51 M 8 5.5 3.4 0 0.23293292 1 7 7
36 F 8 5.2 2.8 0 0.28892715 1 8 8
47 F 6 4.3 3.5 0 0.05998461 1 9 9

@ngreifer
Copy link
Collaborator

I'm looking into this. Could you provide the full dataset so I can investigate? On the datasets I have It seems to be working correctly. When you run summary(match), is the Std. Pair Diff. value for AGE different from 0?

@jiweihe1223
Copy link
Author

jiweihe1223 commented Feb 26, 2021 via email

@ngreifer
Copy link
Collaborator

Sorry, I don't see the dataset anywhere.

@jiweihe1223
Copy link
Author

jiweihe1223 commented Feb 27, 2021

I attached it in the email reply. Let me try to attach here.
data_test.xlsx

@ngreifer
Copy link
Collaborator

Thank you for sending the dataset. It seems like you're using an old version of MatchIt. I was able to replicate your results using version 3.0.2, but not using version 4.0.0 or above. In recent versions, the units are correctly matched. Please update MatchIt and this should be fixed.

Please make sure you are always using the most updated version of a package. In the future, if you think you have found a bug or unexpected behavior, it may have already been fixed in an updated version, saving you and the maintainers time.

@jiweihe1223
Copy link
Author

jiweihe1223 commented Feb 27, 2021 via email

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