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

Constant independent variables are not allowed #17

Closed victorn1 closed 5 years ago

victorn1 commented 6 years ago

If I take a constant independent variable, I get the error Error in relevel.factor(C[[i]], levels(C[[i]])[2]) : 'ref' must be an existing level

Code to reproduce the problem:

n=20
a=sample(2,n,replace=T)-1
b=runif(n)
c=rep(0,n)
l=glm(a~b+c)
matched=sample(2,n,replace=T)-1
b1=bal.tab(a~b+c,weights=matched,method="matching",s.d.denom="pooled")

Previous versions of Cobalt just silently removed constant variables from the analysis. The most convenient way may be that constant variables are removed with a warning, so that the script is not stopped.

ngreifer commented 5 years ago

Thank you for finding this! Fixed!