overwhelmed
overwhelmed

Reputation: 225

How to extract "distance" of the unmatched cases in matchit package?

After successfully running matchit function in r, I want to extract the distances (propensity score) of unmached subjects. I know how to extract the matched cases, but cannot figure out how to exclude the matched cases in extracting distances of unmatched cases. Sample code:

library(MatchIt)
m.out <- matchit(treat ~ age + educ + black + hispan + nodegree + married + 
                         re74 + re75, 
                 data = lalonde, method = "nearest", distance = "logit")
m.dat <- match.data(m.out)

Upvotes: 1

Views: 558

Answers (1)

d.b
d.b

Reputation: 32558

Just get the rows that are in lalonde but not in m.dat. distance which is inside the list m.out is a named vector so you can just get the distances using row names.

> m_nm_dat = lalonde[!row.names(lalonde) %in% row.names(m.dat),]
> m_nm_dat$distance = m.out$distance[row.names(m_nm_dat)]
> head(m_nm_dat)
      treat age educ black hispan married nodegree     re74     re75     re78   distance
PSID1     0  30   12     0      0       1        0 20166.73 18347.23 25564.67 0.02611776
PSID2     0  26   12     0      0       1        0 25862.32 17806.55 25564.67 0.01599286
PSID3     0  25   16     0      0       1        0 25862.32 15316.21 25564.67 0.02600442
PSID4     0  42   11     0      0       1        1 21787.05 14265.29 15491.01 0.03850037
PSID7     0  32   12     0      0       1        0 19067.58 12625.35 14146.28 0.02158276
PSID9     0  38    9     0      1       1        1 16826.18 12029.18     0.00 0.08445103

Upvotes: 2

Related Questions