library(WeightIt)
library(tidyverse)
data("lalonde", package = "cobalt")
W_ipt <- weightit(treat ~ age + educ + married +
nodegree + re74, data = lalonde,
method = "ipt", estimand = "ATT")
W_ebal <- weightit(treat ~ age + educ + married +
nodegree + re74, data = lalonde,
method = "ebal", estimand = "ATT")
summary(W_ipt)
Summary of weights
- Weight ranges:
Min Max
treated 1. || 1.
control 0.017 |---------------------------| 2.263
- Units with the 5 most extreme weights by group:
1 2 3 4 5
treated 1 1 1 1 1
410 404 224 111 84
control 1.464 1.485 1.576 1.743 2.263
- Weight statistics:
Coef of Var MAD Entropy # Zeros
treated 0.000 0.000 0.000 0
control 0.839 0.707 0.341 0
- Effective Sample Sizes:
Control Treated
Unweighted 429. 185
Weighted 252.12 185
summary(W_ebal)
Summary of weights
- Weight ranges:
Min Max
treated 1. || 1.
control 0.04 |---------------------------| 5.247
- Units with the 5 most extreme weights by group:
1 2 3 4 5
treated 1 1 1 1 1
410 404 224 111 84
control 3.396 3.443 3.655 4.043 5.247
- Weight statistics:
Coef of Var MAD Entropy # Zeros
treated 0.000 0.000 0.000 0
control 0.839 0.707 0.341 0
- Effective Sample Sizes:
Control Treated
Unweighted 429. 185
Weighted 252.12 185
cobalt::bal.tab(W_ipt)
Balance Measures
Type Diff.Adj
prop.score Distance 0.0164
age Contin. -0.0000
educ Contin. 0.0000
married Binary -0.0000
nodegree Binary -0.0000
re74 Contin. -0.0000
Effective sample sizes
Control Treated
Unadjusted 429. 185
Adjusted 252.12 185
cobalt::bal.tab(W_ebal)
Balance Measures
Type Diff.Adj
age Contin. 0
educ Contin. 0
married Binary -0
nodegree Binary -0
re74 Contin. -0
Effective sample sizes
Control Treated
Unadjusted 429. 185
Adjusted 252.12 185
weight_comp <- tibble(
ipt = W_ipt$weights,
entropy = W_ebal$weights,
treat = lalonde$treat
)
weight_comp |>
filter(treat == 0) |>
ggplot() +
aes(x = entropy, y = ipt) |>
geom_point() +
labs(x = "Entropy balancing",
y = "Inverse probability tilting (logit link)",
title = "Comparison group ATT weights")
The weights are perfectly correlated:
weight_comp |>
filter(treat == 0) |>
cor.test(~ ipt + entropy, data = _)
Pearson's product-moment correlation
data: ipt and entropy
t = 980570508, df = 427, p-value < 2.2e-16
alternative hypothesis: true correlation is not equal to 0
95 percent confidence interval:
1 1
sample estimates:
cor
1
Sample sizes:
lalonde |>
group_by(treat) |>
tally()
weight_comp |>
filter(treat == 0) |>
pivot_longer(
cols = c(entropy, ipt),
values_to = "weight",
names_to = "method"
) |>
group_by(method) |>
summarise(
mean = mean(weight),
sum = sum(weight),
sd = sd(weight),
ESS = ESS(weight)
)
So the entropy balancing weights sum to the comparison group sample size and the IPT weights sum to the intervention group sample size.