R:最近的邻居与比赛匹配

发布于 2025-01-29 07:42:29 字数 1291 浏览 2 评论 0 原文

我想将最近的邻居匹配与R中的Matchit匹配。 到目前为止,我已经使用了以下代码:

Matching<- matchit(Treatment ~ Size+ Age + Expenses, data=data, method = "nearest", distance="glm", replace=TRUE)

有两个问题:

问题1。

我 然后,一条线说,

A matchit object
 - method: 1:1 nearest neighbor matching with replacement

如果凝结,我想拥有相同的控制观察以多次匹配。 上面的代码是这样做的吗? 我很困惑,因为它说1:1最近的邻居与替代品匹配,我不知道它是否仅由于句子中的1:1部分而在对照组中不超过一次观察。但是,由于我在代码中使用替换= true ,所以我认为这是这样做的,以便可以将一个观察值匹配多次。

有人可以向我解释我的理解是否正确吗?

问题2。)

运行后,

Matching<- matchit(Treatment ~ Size+ Age + Expenses, data=data, method = "nearest", distance="glm", replace=TRUE)

我想估计平均治疗效果。 我使用以下文档作为如何估计它的参考: 但是,我想通过子类和ID使用聚类的标准错误。 因此,我需要首先编写代码:

matching_gm&lt; - get_matches(matching)

当我查看匹配_gm的权重时,它们总是1。但是,当我运行摘要时(匹配$匹配$) Weigths)有很多与1不同的权重。 当我使用 get_matches 时,为什么权重改变?据我所知,情况并非如此。

I would like to use nearest neighbour matching with MatchIt in R.
So far I have used the following code:

Matching<- matchit(Treatment ~ Size+ Age + Expenses, data=data, method = "nearest", distance="glm", replace=TRUE)

I have two questions:

Question 1.)

When I run this code and run Matching again then I get a summary.
One line then says

A matchit object
 - method: 1:1 nearest neighbor matching with replacement

I want to have the same control observation to be matched multiple times if neeeded.
Is the code above doing that?
I am confused since it says 1:1 nearest neighbor matching with replacement, I don't know if it now only uses an observation in the control group not more than once due to the 1:1 part in the sentence. However, since I use replace=true in the code I thought that this does exactly that so that one observation in the control group can be matched several times.

Could someone explain to me if my understanding is correct?

Question 2.)

After having run

Matching<- matchit(Treatment ~ Size+ Age + Expenses, data=data, method = "nearest", distance="glm", replace=TRUE)

I would like to estimate the average treatment effect.
I use the following document as a reference on how to estimate it:
https://cran.r-project.org/web/packages/MatchIt/vignettes/estimating-effects.html#after-pair-matching-with-replacement
However, I would like to use clustered standard errors by subclass and id.
Therefore, I need to first write the code:

Matching_gm <- get_matches(Matching)

When I look at the weights of Matching_gm they are always 1. However, when I run summary(Matching$weigths) there are many weights that are different from 1.
Why do the weights change when I use get_matches ? As far as I know, this should not be the case.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

淡淡的优雅 2025-02-05 07:42:29
  1. 它被称为1:1匹配,因为每个处理的单元都会获得一个匹配,但是控制单元可能会作为多个处理单元的匹配重复使用。如果将比率设置为1以外的其他功能,则您将进行k:1匹配,每个处理的单元都会获得K匹配项,该匹配项由其他处理的单元组成。

  2. get_matches()每次匹配时为每个单元生成一行。如果对控制单元的匹配两次(即,与两个不同处理的单位),则在 get_matches() output中,它的权重为1行,但重量为2在 matchit()输出中(尽管该权重可以缩放为与2不同)。如果使用 match.data()而不是 get_matches(),您会看到每个单元仅接收一行,每个控制单元的权重与在 matchit()输出。

  1. It is called 1:1 matching because each treated unit gets one match, but it is possible that control units are reused as matches for multiple treated units. If you set ratio to something other than 1, you would be doing k:1 matching, where each treated units gets k matches, composed of controls that may be resued for other treated units.

  2. get_matches() produces a row for each unit for each time it is matched. If a control unit is matched twice (i.e., to two different treated units), it will have two rows each with a weight of 1 in the get_matches() output, but it will have a weight of 2 in the matchit() output (though this weight may be scaled to be different from 2). If you use match.data() instead of get_matches(), you will see that each unit receives only one row and the weights for each control unit are the same as in the matchit() output.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文