Background
Looking into the MatchIt articles made me realize that using Bootstrap with BCa is a better practice for assessing uncertainty estimation (since: "For nonlinear models (e.g., logistic regression), the delta method is only an approximation subject to error"). Using Estimating Effects After Matching article for clustered bootstrap, I got satisfactory results. Still, I would like to utilize the full functionality of the marginaleffects package, for instance - using the "by =" to get stratified results, etc.
The marginaleffects documentation shows how can marginaleffects::avg_comparisons can be used in combination with the boot package using marginaleffect::inferences.
The problem
When I try to use bootstrap after running marginaleffects::avg_comparisons with clusters G-comp according to MatchIt article, I get this error:
avg_comparisons(fit, variables = "A", vcov = ~subclass, newdata = subset(md, A == "1"), wts = "weights", comparison = "lnratioavg", transform = exp ) %>% inferences(method = "boot", R = 999, conf_type = "bca") # Error: Assertion failed. One of the following must apply: # * checkmate::check_choice(x): Must be element of set {'exp','ln'}, but is not atomic scalar # * checkmate::check_function(x): Must be a function, not 'list' Also, running the code after removing the transform = exp or/and comparison = "lnratioavg" arguments shows results that are very different than the estimate and CI computed using delta method or bootstrapping after manually computing G-comp. as shown in the article above (which are very similar in my instance).
To avoid from posting very long code, I'm attaching a reproduced example with downloadable code
My questions:
- Is using
marginaleffectswithbootconsidered good practice in a matched cohort, and is it an appropriate and equal substation for the manual g-computation in the MatchIt articles? - What is the proper code for doing it?
- How to run bootstrap with
by =argument, and is this a good practice?
================