在R中进行最近邻匹配时,是否可以查看哪些case与哪些control匹配的identity? [英] When performing nearest neighbour matching in R, is it possible to view the identity of which cases matched with which controls?
问题描述
我首先在 R Studio 中尝试使用此处找到的小型练习数据集(584 个 obs,5 个变量)(https://scholarworks.umass.edu/cgi/viewcontent.cgi?article=1330&context=pare)
I'm first trying this out in R Studio with a small practice dataset found here (584 obs, 5 variables) (https://scholarworks.umass.edu/cgi/viewcontent.cgi?article=1330&context=pare)
使用此代码,我可以使用最近邻匹配来查找匹配案例和控件中的平均差异 (1:1),其中 stw 是我的分组变量,tot、min 和 dis 是匹配变量:
Using this code I can use nearest neighbor matching to find the mean difference in matched cases and controls (1:1) where stw is my grouping variable and tot, min, and dis are the matching variables:
m.out = matchit(stw ~ tot + min + dis,
data = mydata, method = "nearest",
ratio = 1)
我想知道的是如何查看哪些案例与哪些控件匹配(即向我显示确切身份)?
what I want to know is how can I view which cases have matched with which controls (i.e. shows me the exact identity)?
我还想在匹配 5 个最近的邻居(即比率 = 5)并查看这些确切身份的情况下执行此操作.是否需要额外的代码?
I would also like to do this where I match 5 nearest neighbors (i.e. ratio = 5) and also view those exact identities. is there additional code needed for this?
非常感谢
推荐答案
匹配中的单位标识存储在 matchit
输出的 match.matrix
组件中目的.这是一个矩阵,行数与处理单元数相同,列数与ratio
列数相同.每行对应一个处理单元,行中的值对应于与该处理单元匹配的控制单元的身份.下面是一个例子:
The identity of units within a match are stored in the match.matrix
component of the matchit
output object. This is a matrix with as many rows as there are treated units and with ratio
columns. Each row corresponds to a treated unit, and the values in the row correspond to the identity of the control unit matched to that treated unit. Below is an example:
> head(m$match.matrix)
1 2
NSW1 "PSID305" "PSID369"
NSW2 "PSID198" "PSID273"
NSW3 "PSID333" "PSID282"
NSW4 "PSID400" "PSID92"
NSW5 "PSID426" "PSID262"
NSW6 "PSID391" "PSID261"
处理单元NSW1
与控制单元<code>PSID305和PSID369
相匹配.如果原始数据集没有行名称,则值对应于数据集中出现相应单元的行.
Treated unit NSW1
is matched with control units PSID305
and PSID369
. If the original dataset did not have row names, the values correspond to the row of the dataset where the corresponding unit appears.
这篇关于在R中进行最近邻匹配时,是否可以查看哪些case与哪些control匹配的identity?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!