比率1:1使用Matchit软件包的精确匹配
library(MatchIt)
df <- data.frame(lalonde)
m.out1 <- matchit(treat ~ age + race + educ, data = lalonde,
method = "exact")
m.data1<-match.data(m.out1)
我想知道如何在与Matchit软件包进行确切的匹配后,如何获得控制和治疗样本的相同尺寸。理想情况下,如果将经过处理的单元与多个控件匹配,我想随机选择一个控件。 我的真正数据集不是拉隆德。它实际上是一个非常大的。因此,我可能有许多与经过处理的单元相关的控件,我想为每个处理的单元随机绘制一个对照。
library(MatchIt)
df <- data.frame(lalonde)
m.out1 <- matchit(treat ~ age + race + educ, data = lalonde,
method = "exact")
m.data1<-match.data(m.out1)
I would like to know how I can get the same size for both the control and treatment samples after running an exact matching with MatchIt package. Ideally, I would like to randomly pick a control if a treated unit has been matched to more than one control.
My real dataset is not lalonde. It is actually an extremely large one. So I might have many controls associated with a treated unit and I want to draw one randomly for each treated unit.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对于确切的匹配,您可以使用此代码。
如果您重新运行代码,您会发现IDS略有变化,如果数据集更大,它们可能会更清楚地做到这一点。
要修复控制单元的随机化,您可以使用
set.seed()
。为了确定性地使用ties = false
(请参阅?match
help page)。For exact matching you could use this code.
If you re-run the code, you will see that the IDs change slightly, which they would probably do more clearly if the dataset was larger.
To fix the randomization of the control units you may use
set.seed()
. For handling ties deterministically useties=FALSE
(see?Match
help page).最简单的方法是进行1:1最近的邻居匹配与精确匹配的约束:
如果您要进行精确匹配,则已经内置了一个选项,可以通过设置
k2k = true
:设置
cutpoints = 0
请求确切的匹配(无粗略)。The easiest way is to do 1:1 nearest neighbor matching with exact matching constraints:
If you are doing coarsened exact matching, there is an option already built in to request this which is by setting
k2k = TRUE
:Setting
cutpoints = 0
requests exact matching (no coarsening).