【问题标题】:Matching. Data simulation and estimation with MatchIt and Matching. How to retrieve true model?匹配。使用 MatchIt 和 Matching 进行数据模拟和估计。如何检索真实模型?
【发布时间】:2019-03-10 21:26:50
【问题描述】:

我试图模拟 matching 与回归 (OLS) 的敏感性,但我在某处做错了,因为我无法使用 matching 检索真实模型。

我正在生成 3 个变量:x,一个背景特征,d 这是治疗变量(二进制)和y 结果。 dx 相关联。匹配的想法是,一旦以x 为条件,处理分配生成过程就像随机一样好。在回归世界中,x 只是一个控制变量。我想测试当数据中存在非共同支持区域(未处理高于或低于某些值)时回归的执行情况。

library(tidyverse)
library(Matching)
library(MatchIt)

N = 1000
# generate random variable normality dist #
x = rnorm(N, 0, 5)

这就是我在xd(二进制)之间生成关联的方式。

# generate Treatement associated with x, with different probailities after a certain threshold #
d = ifelse(x > 0.7, rbinom(0.7 * N, 1, 0.6) , rbinom( (1 - 0.7) * N, 1, 0.3) )
# beyond 0.7 the proba is 0.6 to receive treatment and below is 0.3 #

对我来说似乎是正确的,但如果您有更好的方法,请告诉我。

# adding a bit more randomness #
d[ sample(length(d), 100) ] <- rbinom(100, 1, 0.5)

# also adding a cut-off point for the treated #  
d[x < -10] <- 0
d[x > 10] <- 0

我正在使用ifelse 生成d 的效果,这对我来说似乎是正确的,但我可能是错的。

# generate outcome y, w/ polyn relationship with x and a Treatment effect of 15 # sd == 10 #
y = x*1 + x^2 + rnorm(N, ifelse(d == 1, 15, 0), 10)

#
df = cbind(x,d,y) %>% as.data.frame()
# check out the "common support"
df %>% ggplot(aes(x, y, colour = factor(d) )) + geom_point()
#

该图显示了我想要建模这 3 个关系的方式。注意处理过的 10 以上和以下的截止值。

现在,当我使用 OLS 估计 dy 的影响时,具有遗漏变量的模型和预期的错误指定模型给了我对 d 的错误估计。

# omitted x #
lm(y ~ d, df) %>% summary()
# misspecification #
lm(y ~ d + x, df) %>% summary()
# true model #

虽然正确的规范让我得到15d 的真实效果)。

lm(y ~ d + poly(x,2), df) %>% summary()
# we correctly retrieve 15 #

现在我的问题是了解为什么我无法使用匹配的包到达15(d 的真实效果)。

使用MatchIt 包。

我尝试使用mahalanobis 和这样的倾向得分:

m1 = matchit(d ~ x, df, distance = 'mahalanobis', method = 'genetic')
m2a = matchit(d ~ x, df, distance = 'logit', method = 'genetic')
m2b = matchit(d ~ x + I(x^2), df, distance = 'logit', method = 'genetic')

匹配数据

mat1 = match.data(m1)
mat2a = match.data(m2a)
mat2b = match.data(m2b)

# OLS #
lm(y ~ d, mat1) %>% summary()
lm(y ~ d, mat2a) %>% summary()
lm(y ~ d, mat2b) %>% summary()

所以这里我不检索15。为什么?我误解了结果吗? 我的印象是,在执行matching 时,您不必对多项式项或/和交互进行建模。这是不正确的吗?

lm(y ~ d + poly(x,2), mat1) %>% summary()
lm(y ~ d + poly(x,2), mat2a) %>% summary()
lm(y ~ d + poly(x,2), mat2b) %>% summary()

因为如果我在此处包含 poly(x,2) 术语,我会检索到 15。

使用Matching包,我也得到了完全不同的估计

x1 = df$x
gl = glm(d ~ x + I(x^2), df, family = binomial)
x1 = gl$fitted.values

# I thought that it could be because OLS only gives ATE #
m0 = Match(Y = y, Tr = d, X = x1, estimand = 'ATE')
# but no 
m0$est

有什么线索吗?

【问题讨论】:

    标签: r regression linear-regression matching economics


    【解决方案1】:

    匹配过程的一个重要输出是控制观察的权重。计算权重以使倾向得分的分布在治疗组和对照组中相似(一旦应用权重)。

    在你的情况下,这意味着(从你的 dgp 和你的符号开始):

    lm(y ~ d, mat1, weights = weights) %>% summary()
    lm(y ~ d, mat2a, weights = weights) %>% summary()
    lm(y ~ d, mat2b, weights = weights) %>% summary()
    

    我们在这里:15 回来了(或者实际上是 14.9)!

    【讨论】:

    • 非常酷,谢谢。说得通! 'mahalanobis' 呢?
    • 我这边的 mahalanobis 的工作方式相同。你的意思是Matching::Match() 可能与你的最后一点有关?
    猜你喜欢
    • 2018-03-11
    • 1970-01-01
    • 2015-12-09
    • 2018-07-09
    • 1970-01-01
    • 2021-10-01
    • 2021-06-10
    • 2014-09-22
    • 1970-01-01
    相关资源
    最近更新 更多