ngreifer / WeightIt

WeightIt: an R package for propensity score weighting
https://ngreifer.github.io/WeightIt/
102 stars 13 forks source link

`method_cbps`: `quantile` argument is missing #69

Closed BERENZ closed 2 months ago

BERENZ commented 2 months ago

In the documentation is it not stated that quantile argument can be used with the method_cbps. However, if you provide this argument method_cbps returns weights that balance on user specified quantiles.

See the code that shows this issue for the ATT estimand (results are exactly the same as noted by Słoczyński et al (2024))

data("lalonde", package = "cobalt")

#Balancing covariates between treatment groups (binary)
## no balance on quantiles
res1 <- weightit(treat ~ age + educ + married +
                    nodegree + re74, data = lalonde,
                  method = "cbps", estimand = "ATT")

## balance on quantiles
res1a <- weightit(treat ~ age + educ + married +
                  nodegree + re74, data = lalonde,
                method = "cbps", estimand = "ATT",
                quantile = list(age=0.5, educ = 0.5))

## standard EBAL
res2 <- weightit(treat ~ age + educ + married +
                  nodegree + re74, data = lalonde,
                method = "ebal", estimand = "ATT")

## balance on quantiles
res2a <- weightit(treat ~ age + educ + married +
                   nodegree + re74, data = lalonde,
                 method = "ebal", estimand = "ATT",
                 quantile = list(age=0.5, educ = 0.5))

plot(res1$weights, res2$weights, xlab = "CBPS", ylab = "EB")  ## results are the same 

plot(res1$weights, res1a$weights, xlab = "CBPS", ylab="CBPS + quantiles") ## different results

plot(res1a$weights, res2a$weights, xlab = "CBPS + quantiles", ylab="EB + quantiles") ## the same

For the d.moments argument the results are exactly the same as without this argument. No problem here.

I'm actually quite pleased that the quantile argument works for the CBPS method. So, I opt for leaving the quantile argument for the CBPS. :)

ngreifer commented 2 months ago

Thanks for letting me know about this! quantile can indeed be used with CBPS but I did forget to document it. It is now correctly documented.

BERENZ commented 2 months ago

Thanks! Do you think that it will be possible to balance only to quantiles not moments of a given variable? Say I would like to balance only to medians but not means.

ngreifer commented 2 months ago

That's a good question. I hadn't considered that as a possibility but it's definitely something I could add. I'll look into that and get back to you.

ngreifer commented 2 months ago

I made this change and it should work now! You can set moments = 0 and supply an argument to quantile to request balance on the quantiles but not the means. This will fail to balance any categorical variables, though, since those are ignored by quantile. I would recommend balancing both means and quantiles if possible; usually the cost to balancing the means is not much higher than the quantiles.

BERENZ commented 2 months ago

Great! I will test it after the weekend. The basic idea behind this is that in a simple case say y= a+a_1x and x is continuous then calibrating weight to $\alpha$-quantile of x gives you exactly the $\alpha$-quantile of y. So you can estimate quantile treatment effect using linear regression (now I work on the multivariate case to show how it works in such setting). Does this change affect other methods such as ebal or ipt?

ngreifer commented 2 months ago

Yes, all methods that accept quantile can be used to balance only the quantiles and not the means. This includes cbps, nbcbps, ebal, optweight, ipt, and energy.