data(lalonde)
print(nrow(lalonde))
ps.lalonde <- ps(treat ~ age + educ + black + hispan + nodegree +
married + re74 + re75,
data = lalonde,
title="Lalonde example",
stop.method=stop.methods$ks.stat.max,
# generate plots?
plots=TRUE,
# gbm options
n.trees=2000,
interaction.depth=3,
shrinkage=0.005,
perm.test.iters=50,
verbose=TRUE)
# get the balance tables
bal.table(ps.lalonde)
# diagnose the weights using a ps object
a <- dx.wts(ps.lalonde,data=lalonde,treat.var="treat")
print(a)
bal.table(a)
# diagnose the weights as propensity score weights
# will be the same as before, except for MC variation in the KS p-values
w <- with(ps.lalonde, ps/(1-ps))
w[lalonde$treat==1,] <- 1
dx.wts(w,data=lalonde,treat.var="treat",
perm.test.iters=100)
# diagnose the weights as propensity scores
p <- ps.lalonde$ps
p[lalonde$treat==1,] <- 1
dx.wts(p,data=lalonde,treat.var="treat",x.as.weights=FALSE)
# look at propensity scores
names(ps.lalonde$ps)
hist(ps.lalonde$ps$ks.stat.max)
boxplot(split(ps.lalonde$ps$ks.stat.max,ps.lalonde$treat),
ylab="estimated propensity scores",
names=c("control","treatment"))
# check out the balance
names(ps.lalonde$desc)
# unweighted
ps.lalonde$desc$unw
# optimized for ks.stat.max
ps.lalonde$desc$ks.stat.max
# check out the gbm object, indicates which variables are most influential in
# estimating the propensity score
summary(ps.lalonde$gbm.obj, n.trees=ps.lalonde$desc$ks.stat.max$n.trees)
# bal.stat() can use an arbitrary set of weights
bal.stat(data=lalonde,
w.all=w[,1],
vars=names(lalonde),
treat.var="treat",
get.means=TRUE,
get.ks=TRUE,
na.action="level")
Run the code above in your browser using DataLab