# NOT RUN {
library("twang")
# library("cobalt")
data("iptwExWide", package = "twang")
(W <- weightitMSM(list(tx1 ~ age + gender + use0,
tx2 ~ tx1 + use1 + age + gender + use0,
tx3 ~ tx2 + use2 + tx1 + use1 + age + gender + use0),
data = iptwExWide,
method = "ps"))
summary(W)
# bal.tab(W)
##Going from long to wide data
data("iptwExLong", package = "twang")
wide_data <- reshape(iptwExLong$covariates, #long data
timevar = "time", #time variable
v.names = c("use", "tx"), #time-varying
idvar = "ID", #time-stable
direction = "wide",
sep = "")
(W2 <- weightitMSM(list(tx1 ~ age + gender + use1,
tx2 ~ tx1 + use2 + age + gender + use1,
tx3 ~ tx2 + use3 + tx1 + use2 + age +
gender + use1),
data = wide_data,
method = "ps"))
summary(W2)
all.equal(W$weights, W2$weights)
# }
Run the code above in your browser using DataLab