ngreifer / cobalt

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

4.5.2 cobalt::bal.tab and Missing Values #76

Open vnusinfo opened 11 months ago

vnusinfo commented 11 months ago

There may have been a bug introduced in version 4.5.2. When there is a missing value for a continuous variable (e.g., age in lalonde). Here is the error message:

> packageVersion("cobalt")
[1] ‘4.5.2’
> cobalt::bal.tab(subset(dfd, select = -c(treat, re78, nodegree, married))
+                ,treat=dfd$treat)$Balance
Note: `s.d.denom` not specified; assuming pooled.
Error in `.rowNamesDF<-`(x, value = value) : 
  duplicate 'row.names' are not allowed
In addition: Warning messages:
1: Missing values exist in the covariates. Displayed values omit these observations. 
2: non-unique value when setting 'row.names': ‘age’

Here is the minimum code to replicate:

> packageVersion("cobalt")
[1] ‘4.5.2’
> cobalt::bal.tab(subset(dfd, select = -c(treat, re78, nodegree, married))
+                ,treat=dfd$treat)$Balance
Note: `s.d.denom` not specified; assuming pooled.
Error in `.rowNamesDF<-`(x, value = value) : 
  duplicate 'row.names' are not allowed
In addition: Warning messages:
1: Missing values exist in the covariates. Displayed values omit these observations. 
2: non-unique value when setting 'row.names': ‘age’

Here is the same output when the version is reverted to 4.5.1:

> packageVersion("cobalt")
[1] ‘4.5.1’
> dfd <- cobalt::lalonde
> dfd$age[1] <- NA
> 
> packageVersion("cobalt")
[1] ‘4.5.1’
> cobalt::bal.tab(subset(dfd, select = -c(treat, re78, nodegree, married))
+                ,treat=dfd$treat)$Balance
Note: `s.d.denom` not specified; assuming pooled.
               Type      Diff.Un Diff.Adj
age         Contin. -0.248847159       NA
age:<NA>     Binary  0.005405405       NA
educ        Contin.  0.044755085       NA
race_black   Binary  0.640446040       NA
race_hispan  Binary -0.082731683       NA
race_white   Binary -0.557714358       NA
re74        Contin. -0.595751591       NA
re75        Contin. -0.287002109       NA
Warning message:
Missing values exist in the covariates. Displayed values omit these observations.`
ngreifer commented 11 months ago

Thank you for this report! I will take a look.

vnusinfo commented 11 months ago

Thanks so much! Please let me know if I can do anything to contribute.