【问题标题】:R - Matchit - Propensity Score Matching - Discard function not workingR - Matchit - 倾向得分匹配 - 丢弃功能不起作用
【发布时间】:2017-10-28 10:01:22
【问题描述】:

我在 LaLonde 数据集上使用 MatchIt 包,并且丢弃参数会产生两种类型的错误。 (如果我不使用丢弃参数,则代码有效)。在这两种情况下,都不清楚如何解决问题......

第一个问题是当我尝试discard = "hull.control"

m.opt1 <- matchit(treat ~ inc.re74 + inc.re75 + education + nonwhite + 
  age + nodegree, data = cps_controls, method = "optimal", ratio=1, 
  discard="hull.control")

产生此错误消息....

Loading required namespace: WhatIf
Preprocessing data ...
Performing convex hull test ...
Error in mclapply(1:m, in_ch, mc.cores = mc.cores) : 
'mc.cores' > 1 is not supported on Windows

第二个问题是当我尝试discard = "control"

Error in d[i, ] <- abs(d1[i] - d0) : 
number of items to replace is not a multiple of replacement length

有没有办法解决这些问题?谢谢!!

【问题讨论】:

  • 您使用的是“lalonde”数据还是“cps_controls”数据?对于后者,请添加我们可以重现您的问题的数据示例。
  • 您好,我使用的是 cps_controls,但刚刚使用 MatchIt 包中可用的 lalonde 数据集再次尝试 -
  • 我收到了上面第一个问题的相同错误和提到的第二个问题的新错误-这是我使用的代码-如果我不使用丢弃参数,它再次起作用:m。 opt
  • 这是新的错误信息。谢谢! fullmatch.matrix 中的错误(d,min.controls = ratio,max.controls = ratio,:负 'omit.fraction' 不允许 'min.controls' >= 2 另外:警告消息:1:在 optmatch 中:: fullmatch(d, min.controls = ratio, max.controls = ratio, : 如果没有 'data' 参数,则不保证匹配的顺序与您的原始数据相同。2:在 fullmatch.matrix(d, min. controls = ratio, max.controls = ratio, : 找到负的 omit.fraction 值,目前不支持

标签: r matching


【解决方案1】:

如 SO herehere 中所述,您的问题似乎是 MatchIt 包中的一个错误。我已经提交了ticket on GitHub

【讨论】:

    【解决方案2】:

    关于discard = "hull.control"问题:

    here下载MatchIt的源代码并编辑discard.R。在WhatIf::whatif 的调用中添加参数mc.cores = 1。这应该将使用的核心数硬编码为 1,从而消除问题。

    卸载 MatchIt 包并通过打开命令行并键入 R CMD build C:\path\to\MatchIt-master 来构建新的包。这应该创建一个 .tar.gz 文件。在 R Studio 中,点击 Tools -> Install packages... 并选择本地包。

    如果之前加载了库,您可能需要重新启动 R Studio。

    享受吧。

    【讨论】:

      猜你喜欢
      • 2021-02-20
      • 1970-01-01
      • 1970-01-01
      • 2015-09-25
      • 2020-04-26
      • 1970-01-01
      • 1970-01-01
      • 2021-10-18
      • 2016-10-15
      相关资源
      最近更新 更多