0

我想使用 R 中 {Matching} 的匹配函数来估计平均治疗效果对治疗(ATT)的影响,倾向得分作为距离,一对一匹配作为匹配方法。在同一个匹配模型中,我想使用确切的参数并将其应用于一个特定的变量。

在运行 logit 函数来估计倾向得分后,如下所示:

glm1 <- glm(treat~AREA_HA + SUMVIV_TOT + SUMPOB + COUNT + luz + potable + cocina_ele + altitudeme + river_mean + 
          paved_mean + unpaved_me + VDep_mean + VNacional_ + VVecinal_m + temp_mean + rain_mean + dccpp_mean + 
          distfloss_ + idh_mean + bmass_mean + slope_mean + distANP_me + ker10_mean + titled + for10 + for10_per + 
          floss_yr001 + floss_yr002 + floss_yr003 + floss_yr004 + floss_yr005 + floss_yr006 + floss_yr007 + floss_yr008 + 
          floss_yr009 + floss_yr010, family=binomial, data=comm.vars6)

在运行Match函数时,我尝试将确切的参数应用于第 26 个变量(“标题”) 。代码如下所示:

rr1 <- Match(Y=Y, Tr=Tr, X=glm1$fitted, exact = c(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0), M=1, replace = T)

尽管如此,我还是收到了以下警告消息:

Warning message:
In Match(Y = Y, Tr = Tr, X = glm1$fitted, exact = c(0, 0, 0, 0,  :
length of exact != ncol(X). Ignoring exact option

我相信这是一个与 X (=glm1$fitted) 的结构有关的问题。因为当我只使用以下矩阵时:

 Z<-with(comm.vars6,data.frame(AREA_HA , SUMVIV_TOT , SUMPOB , COUNT , luz , potable , cocina_ele , altitudeme , river_mean , 
                 paved_mean , unpaved_me , VDep_mean , VNacional_ , VVecinal_m , temp_mean , rain_mean , dccpp_mean , 
                 distfloss_ , idh_mean , bmass_mean , slope_mean , distANP_me , ker10_mean , titled , for10 , floss_yr001
                 , floss_yr002 , floss_yr003 , floss_yr004 , floss_yr005 , floss_yr006 , floss_yr007 , floss_yr008 , 
                 floss_yr009 , floss_yr010 , for10_per))

作为 X 并重新运行 Match 函数:

rr1 <- Match(Y=Y, Tr=Tr, X=Z, exact = c(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0), M=1, replace = T)

它工作正常!

为了能够同时使用倾向得分 (glm1$fitted) 和“标题”的确切参数 = 1,代码应该是什么样子?

4

1 回答 1

0

这是使用两个变量的函数应该是什么样子的粗略草图:PS(距离匹配)和标题(精确匹配):

# get X mat
myMatchMat <- data.frame("PS"=glm1$fitted, "trim"=comm.vars6$trim)
# match
rr1 <- Match(Y=Y, Tr=Tr, X=X, exact = c(0, 1), M=1, replace = T))

因为您没有提供数据集,所以我无法测试代码,因此您可能需要进行一些更改,但这就是Match函数的工作方式。

于 2016-04-27T23:10:48.773 回答