【问题标题】:R package matchit: exact matching specification and an error messageR包matchit:完全匹配规范和错误消息
【发布时间】:2019-12-05 07:29:06
【问题描述】:

我正在使用 R 包 matchit 进行倾向得分匹配分析。

m.out3<-matchit(data=b4psm5, treat~high_school_gpa+male+pell+black+hispanic+asian+other+race_miss,method="nearest", ratio=1,exact=c("cohortid"), m.order="random", caliper=0.25)

所有变量都在数据中,但我收到此错误消息,我认为这与完全匹配的命令有关。

Error in Ops.data.frame(exact[itert, k], exact[clabels, k]) : 
‘!=’ only defined for equally-sized data frames

你能建议吗?我没有可重现的数据集。

【问题讨论】:

  • 获取数据样本可能会有所帮助。您可以编辑您的问题并添加来自dput(head(b4msm5)) 的输出吗? (检查您是否收到该小样本的错误可能会很好。如果您没有收到错误,那么找到导致错误的行......您自己可能会看到问题。 )
  • 嗨,您需要为 Stack Overflow 提问reproducible,干杯。
  • 抱歉,需要一段时间才能回复。

标签: r


【解决方案1】:

这可能是因为您在语法中犯了错误。如果公式(带有~ 的部分)不是第一个参数,则需要用formula= 标记它。因此,尝试运行以下代码,看看是否出现错误:

m.out3 <- matchit(data = b4psm5, 
                  formula = treat ~ high_school_gpa + male + pell + 
                      black + hispanic + asian + other + race_miss,
                  method="nearest", ratio=1, exact=c("cohortid"), 
                  m.order="random", caliper=0.25)

通常公式被指定为第一个参数,因此不需要 formula= 标记,但您将其指定为第二个参数,因此 R 不知道您作为模型公式提供的内容进入formula 参数。

【讨论】:

  • 嗯,抱歉,没用。我得到了同样的信息。如果我找到解决方案,我会及时通知您。我试图制作可重现的数据,但代码没有产生错误。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-07-25
  • 2021-10-18
  • 2020-09-16
  • 2020-06-01
相关资源
最近更新 更多