rlinear-regressioncausalityfixest

Use sensemakr with fixest feols model (R)


I am using the brilliant sensemakr package in R (Cinelli, C., & Ferwerda, J., & Hazlett, C. (2020). “sensemakr: Sensitivity Analysis Tools for OLS in R and Stata.”) to conduct sensitivity analysis on a series of models. I have two models like the following:

library(fixest)
library(sensemakr)

model1 <- lm(data = mtcars, mpg ~ vs + cyl + qsec + factor(hp))

model2 <- feols(data = mtcars, fml = mpg ~ vs + cyl + qsec | hp)

One model uses a basic lm regression, the other uses fixest to efficiently compute multiple fixed effects.

sensemakr(model = model1,
          treatment = "vs",
          benchmark = "cyl",
          kd = 0.5)

sensemakr(model = model2,
          treatment = "vs",
          benchmark = "cyl",
          kd = 0.5)

The first sensemaker function works just fine, but the second fails, with the following error:

Error in UseMethod("sensemakr") : 
  no applicable method for 'sensemakr' applied to an object of class "fixest"

The error is clear to me, so if fixest objects cannot be used, I understand. However, I found package documentation that suggests it can be used with fixest objects, here and here, for example.

Can sensemakr be used for feols models? Was that capability depricated? Or do the functions have to be modified in some way in order to make the fixest object work with it? Do I need to change the arguments of the sensemakr function?


Solution

  • It seems that handling feols models is a new feature the authors are implementing (not in the CRAN 'v0.1.4' version). I tried installing the 'development version' but ran into an error when I ran your example, so I forked the github repo and made a minor change (you can see the changes at https://github.com/jpmam1/sensemakr). If you install this version the package appears to handle feols models as intended/expected:

    # 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.
    

    Created on 2024-04-22 with reprex v2.1.0

    The note "Support for robust standard errors coming soon." suggests that the authors are still working on this; presumably support for feols models will be included in the next CRAN release.