ngreifer / cobalt

Covariate Balance Tables and Plots - An R package for assessing covariate balance
https://ngreifer.github.io/cobalt/
72 stars 11 forks source link

Difference sign reversal in love.plot() #19

Closed victorn1 closed 5 years ago

victorn1 commented 5 years ago

It seems that love.plot() with abs=FALSE changes the sign of the adjusted (or of the unadjusted) differences. When I have unadjusted and adjusted differences of different signs, they are displayed as they have one sign.

ngreifer commented 5 years ago

abs is definitely a strange argument that sometimes confuses me, but I think it's fairly clear in the documentation for love.plot:

If no aggregation (e.g., over clusters or imputations) is to take place, abs will be TRUE if it is TRUE in the call to bal.tab or in the call to love.plot. Otherwise, if balance is requested with multinomial or longitudinal treatments, abs is set to TRUE, and if balance is requested with clustered or multiply imputed data, abs will take on the value of abs set in the original call to bal.tab.

I know there's a lot going on, but see if your scenario matches one of the ones described. If you are using the standard binary treatment with no clustering, you should see absolute values in the plot if abs = TRUE in the call to bal.tab (which is not the default) or if abs = TRUE in the call to love.plot (which is the default). If you set abs = FALSE in the call to love.plot and don't change it in the call to bal.tab, you should see values of different signs.

With aggregated data, which includes clustered data, multiply imputed data, multinomial treatments, and longitudinal treatments, the rules are a little different, but they're described in that quote from the love.plot documentation.

Is the behavior of love.plot not in line with the documentation? Which data scenario are you in?

victorn1 commented 5 years ago

The problem is that when, for a covariate, the unadjusted difference is positive and adjusted is negative the differences are both displayed as positive. I use just one-to-one matching.

ngreifer commented 5 years ago

Oh, I see. Yeah I'll investigate that, thanks!

ngreifer commented 5 years ago

Hm, I am unable to reproduce that error. When I run:

library(cobalt)
library(MatchIt)

data("lalonde", package = "cobalt")
covs <- subset(lalonde, select = -c(re78, treat))
m1 <- matchit(f.build("treat", covs), data = lalonde, 
              replace = TRUE, ratio = 2)
(b <- bal.tab(m1, un = TRUE))
#> Call
#>  matchit(formula = f.build("treat", covs), data = lalonde, replace = TRUE, 
#>     ratio = 2)
#> 
#> Balance Measures
#>                 Type Diff.Un Diff.Adj
#> distance    Distance  1.7941   0.0043
#> age          Contin. -0.3094   0.1352
#> educ         Contin.  0.0550   0.0470
#> race_black    Binary  0.6404   0.0054
#> race_hispan   Binary -0.0827  -0.0081
#> race_white    Binary -0.5577   0.0027
#> married       Binary -0.3236   0.0514
#> nodegree      Binary  0.1114  -0.0216
#> re74         Contin. -0.7211  -0.0588
#> re75         Contin. -0.2903   0.0291
#> 
#> Sample sizes
#>           Control Treated
#> All           429     185
#> Matched       125     185
#> Unmatched     304       0
love.plot(b, abs = FALSE)

Created on 2018-10-17 by the reprex package (v0.2.1)

You can see that the mean differences for re75 are in opposite directions in bal.tab, and when I use love.plot with abs = FALSE, the points are where they belong. Are you able to produce a reproducible example?

victorn1 commented 5 years ago

Oh, I see. Everything works correct. I had a silly mistake in my code, that is why I got the issue. I checked it several times before, but found it just now. I am very sorry for taking you time. Thank you very much for your help!