我正在使用 R 中出色的
sensemakr
包(Cinelli, C., & Ferwerda, J., & Hazlett, C. (2020)。“sensemakr:R 和 Stata 中 OLS 的灵敏度分析工具。”)来进行对一系列模型进行敏感性分析。我有两个模型,如下所示:
library(fixest)
library(sensemakr)
model1 <- lm(data = mtcars, mpg ~ vs + cyl + qsec + factor(hp))
model2 <- feols(data = mtcars, fml = mpg ~ vs + cyl + qsec | hp)
一个模型使用基本的
lm
回归,另一个模型使用 fixest
来有效计算多个固定效应。
sensemakr(model = model1,
treatment = "vs",
benchmark = "cyl",
kd = 0.5)
sensemakr(model = model2,
treatment = "vs",
benchmark = "cyl",
kd = 0.5)
第一个
sensemaker
函数工作正常,但第二个函数失败,并出现以下错误:
Error in UseMethod("sensemakr") :
no applicable method for 'sensemakr' applied to an object of class "fixest"
这个错误对我来说很清楚,所以如果
fixest
对象无法使用,我理解。但是,我发现包文档表明它可以与固定对象一起使用,例如here和here。
sensemakr
可以用于feols
型号吗?该功能是否已被废弃?或者是否必须以某种方式修改函数才能使 fixest
对象与其一起工作?我需要更改 sensemakr
函数的参数吗?
看起来 feols 模型是他们正在实施的一项“新”功能。我分叉了 github 存储库并做了一些小的更改(https://github.com/jpmam1/sensemakr);如果您安装此版本,该软件包似乎可以按预期处理 feols 模型:
# install.packages("fixest")
library(fixest)
devtools::install_github("jpmam1/sensemakr")
#> Downloading GitHub repo jpmam1/sensemakr@HEAD
#> ── R CMD build ─────────────────────────────────────────────────────────────────
#> * checking for file ‘/private/var/folders/gf/3p_ynkts411bs238rtw3y0b40000gn/T/RtmpsM5Zl2/remotes53d5525b31/jpmam1-sensemakr-47f9fe5/DESCRIPTION’ ... OK
#> * preparing ‘sensemakr’:
#> * checking DESCRIPTION meta-information ... OK
#> * checking for LF line-endings in source and make files and shell scripts
#> * checking for empty or unneeded directories
#> * building ‘sensemakr_0.1.5.tar.gz’
library(sensemakr)
#> See details in:
#> Carlos Cinelli and Chad Hazlett (2020). Making Sense of Sensitivity: Extending Omitted Variable Bias. Journal of the Royal Statistical Society, Series B (Statistical Methodology).
model1 <- lm(data = mtcars, mpg ~ vs + cyl + qsec + factor(hp))
model2 <- feols(data = mtcars, fml = mpg ~ vs + cyl + qsec | hp)
sensemakr(model = model1,
treatment = "vs",
benchmark = "cyl",
kd = 0.5)
#> Sensitivity Analysis to Unobserved Confounding
#>
#> Model Formula: mpg ~ vs + cyl + qsec + factor(hp)
#>
#> Null hypothesis: q = 1 and reduce = TRUE
#>
#> Unadjusted Estimates of ' vs ':
#> Coef. estimate: -1.86687
#> Standard Error: 4.7876
#> t-value: -0.38994
#>
#> Sensitivity Statistics:
#> Partial R2 of treatment with outcome: 0.02126
#> Robustness Value, q = 1 : 0.13692
#> Robustness Value, q = 1 alpha = 0.05 : 0
#>
#> For more information, check summary.
sensemakr(model = model2,
treatment = "vs",
benchmark = "cyl",
kd = 0.5)
#> Note for fixest: using 'iid' standard errors. Support for robust standard errors coming soon.
#> Sensitivity Analysis to Unobserved Confounding
#>
#> Model Formula: mpg ~ vs + cyl + qsec | hp
#>
#> Null hypothesis: q = 1 and reduce = TRUE
#>
#> Unadjusted Estimates of ' vs ':
#> Coef. estimate: -1.86687
#> Standard Error: 4.7876
#> t-value: -0.38994
#>
#> Sensitivity Statistics:
#> Partial R2 of treatment with outcome: 0.02126
#> Robustness Value, q = 1 : 0.13692
#> Robustness Value, q = 1 alpha = 0.05 : 0
#>
#> For more information, check summary.
创建于 2024-04-22,使用 reprex v2.1.0
这能解决你的问题吗?