# NOT RUN {
library("cobalt")
data("lalonde", package = "cobalt")
(W <- weightit(treat ~ age + educ + married +
nodegree + re74, data = lalonde,
method = "ps", estimand = "ATT"))
summary(W)
#Trimming the top and bottom 5 weights
trim(W, at = 5, lower = TRUE)
#Trimming at 90th percentile
(W.trim <- trim(W, at = .9))
summary(W.trim)
#Note that only the control weights were trimmed
#Trimming a numeric vector of weights
weights <- cobalt::get.w(W)
all.equal(trim(weights, at = .9, treat = lalonde$treat),
W.trim$weights)
#Using made up data and as.weightit()
treat <- rbinom(500, 1, .3)
weights <- rchisq(500, df = 2)
W <- as.weightit(weights= weights, treat = treat,
estimand = "ATE")
summary(W)
summary(trim(W, at = .95))
# }
Run the code above in your browser using DataLab