require(twangContinuous)
set.seed(1235)
data(dat)
summary(dat$tss_0) # treatment
#> Min. 1st Qu. Median Mean 3rd Qu. Max.
#> 0.000 0.000 0.000 2.101 4.000 13.000
5 Continuous exposure
5.1 Step 1: Estimation of Propensity scores via GBM
<- ps.cont(tss_0 ~ sfs8p_0 + sati_0 + sp_sm_0
test.mod + recov_0 + subsgrps_n + treat,
data=dat,
n.trees = 500,
shrinkage = 0.01,
interaction.depth = 3,
verbose = FALSE)
::bal.table(test.mod, digits = 3) twangContinuous
5.2 Step 2: IPW calculation for ATT
$wts <- twangContinuous::get.weights(test.mod)
datsummary(dat$wts)
#> Min. 1st Qu. Median Mean 3rd Qu. Max.
#> 0.04231 0.85715 0.90552 0.99339 1.05425 6.31356
# by(dat$wts, dat$tss_0, summary)
5.3 Step 3: Balance assessment in weighted data
bal.table(test.mod, digits = 3)
plot(test.mod, plots="es")
5.4 Step 4: Effect estimates from weighted outcome model
<- svydesign(ids=~1, weights=~wts, data=dat)
design.ps <- svyglm(sfs8p_3 ~ tss_0, design = design.ps,
outcome.model family = gaussian())
publish(outcome.model, intercept = FALSE, digits = 4)
#> Variable Units Coefficient CI.95 p-value
#> tss_0 0.0026 [-0.1197;0.1249] 0.9666