I have been generating inverse probability weights with ipw::ipwtm using multiple different datasets. I have faced difficulties in achieving balance of covariates in each time point in the weighted sample.
That is why I started testing the examples given in the ipw package introduction paper. However, I found the same trouble.
For instance, in the second example of the article, whatever timepoint (tstart or fuptime) one chooses, the balance is even worse in weighted sample than in unweighted one. I would understand such imbalance in later time points, because these weights are generated only up to the first switch in exposure, but there is clear imbalance already in the beginning of the follow-up that I cannot understand.
Have I understood something wrong, or is there some other problems?
library(ipw)
data("haartdat")
temp<-ipwtm( exposure=haartind, family="survival", numerator= ~ sex+age, denominator=~sex+age+cd4.sqrt, id="patient", tstart=tstart, timevar=fuptime, type="first", data=haartdat)
haartdat$ipw = temp$ipw.weights
library(cobalt)
bal.tab(haartind~ sex + age + cd4.sqrt, data=haartdat[haartdat$tstart==-100,],weights="ipw",un=T)
One can also note that this is not only the issue of family="survival". Same finding can be seen with family="binomial.
library(ipw)
data("haartdat")
temp<-ipwtm( exposure=haartind, family="binomial", link="logit",numerator= ~ sex+age, denominator=~sex+age+cd4.sqrt, id="patient", timevar=fuptime, type="first", data=haartdat)
haartdat$ipw = temp$ipw.weights
library(cobalt)
bal.tab(haartind~ sex + age + cd4.sqrt, data=haartdat[haartdat$tstart==-100,],weights="ipw",un=T)

