参考匹配包,我们看一下使用的示例GenMatch.
我们读到,Weight Matrix创建的是一个矩阵,其对角线对应于X中每个变量的权重
但我们不确定生成的值代表什么 - 它们是否与标准偏差有关.
让我们举个例子 GenMatch
library(Matching)
data(lalonde)
attach(lalonde)
#The covariates we want to match on
X = cbind(age, educ, black, hisp, married, nodegr, u74, u75, re75, re74)
#The covariates we want to obtain balance on
BalanceMat <- cbind(age, educ, black, hisp, married, nodegr, u74, u75, re75, re74,
I(re74*re75))
#Let's call GenMatch() to find the optimal weight to give each
#covariate in 'X' so as we have achieved balance on the covariates in
#'BalanceMat'. This is only an example so we want GenMatch to be quick
#so the population size has been set to be only 16 via the 'pop.size'
#option. This is *WAY* too small for actual problems.
#For details see http://sekhon.berkeley.edu/papers/MatchingJSS.pdf.
#
genout <- GenMatch(Tr=treat, X=X, BalanceMatrix=BalanceMat, estimand="ATE", M=1,
pop.size=16, max.generations=10, wait.generations=1)
Run Code Online (Sandbox Code Playgroud)
然后我们可以输出Weight.matrix稍后用于配对数据的数据
genout$Weight.matrix
Run Code Online (Sandbox Code Playgroud)
特别是赋予的价值 age
genout$Weight.matrix[1,1]
Run Code Online (Sandbox Code Playgroud)
我们得到的值为~205.但是这个重量意味着什么呢?
此外,如果我们要随机化数据的顺序,则值会不断变化.
n <- 100
P1 <- rep(NA, n)
for (i in 1:n) {
lalonde <- lalonde[sample(1:nrow(lalonde)), ] # randomise order
X = cbind(lalonde$age, lalonde$educ, lalonde$black, lalonde$hisp,
lalonde$married, lalonde$nodegr, lalonde$u74, lalonde$u75,
lalonde$re75, lalonde$re74)
BalanceMat <- cbind(lalonde$age, lalonde$educ, lalonde$black,
lalonde$hisp, lalonde$married, lalonde$nodegr,
lalonde$u74, lalonde$u75, lalonde$re75, lalonde$re74,
I(lalonde$re74*lalonde$re75))
genout <- GenMatch(Tr=lalonde$treat, X=X, BalanceMatrix=BalanceMat, estimand="ATE", M=1,
pop.size=16, max.generations=10, wait.generations=1)
P1[i] <- genout$Weight.matrix[1,1]
}
Run Code Online (Sandbox Code Playgroud)
该文件的作者还建议附加信息可能有所帮助,但它并不能解释这些weight matrix值所代表的含义.任何人都可以解释它们或理解为什么当数据的顺序变化时它们的大小会发生变化
不幸的是,这不是一个可以很容易回答的问题(但要回答部分问题,不,权重矩阵的值与标准差无关)。
GenMatch是一种仿射不变匹配算法,使用距离度量d(),其中W的所有元素均为零(除了主对角线以下)。主对角线由必须选择的k 个参数组成。(请注意,如果这k个参数中的每一个都设置为等于 1,则d()与马氏距离相同)。与马氏距离一样,该距离度量可用于进行贪婪或最优完全匹配。(选择将W的非对角线元素设置为零只是出于计算能力的原因)
当数据顺序改变时,幅度会改变的原因是权重矩阵W具有无穷多个等价解。所产生的匹配对于距离测量的恒定比例变化是不变的。特别是,对于任何正标量c ,每个W = cW产生的匹配都是相同的,因此可以通过多种方式唯一地标识该矩阵。
为了充分理解权重矩阵的非零元素是如何计算的,我建议阅读公式背后的整篇文章GenMatch,其中对所使用的方法进行了一些深入和复杂的研究。
如果您只是对源代码感兴趣,可以在GitHub上查看。如果您对 R 特定代码有其他问题,我将很乐意尝试回答它们,但是,如果您对权重矩阵生成背后的算法有更多问题,您可能需要前往交叉验证。
| 归档时间: |
|
| 查看次数: |
286 次 |
| 最近记录: |