Only one of the two counterfactual outcomes is known: the one corresponding to the treatment level actually received
## # A tibble: 20 x 5## greek A Y_obs Y_a0 Y_a1## <chr> <dbl> <dbl> <dbl> <dbl>## 1 Rheia 0 0 0 NA## 2 Kronos 0 1 1 NA## 3 Demeter 0 0 0 NA## 4 Hades 0 0 0 NA## 5 Hestia 1 0 NA 0## 6 Poseidon 1 0 NA 0## 7 Hera 1 0 NA 0## 8 Zeus 1 1 NA 1## 9 Artemis 0 1 1 NA## 10 Apollo 0 1 1 NA## 11 Leto 0 0 0 NA## 12 Ares 1 1 NA 1## 13 Athena 1 1 NA 1## 14 Hephaestus 1 1 NA 1## 15 Aphrodite 1 1 NA 1## 16 Cyclope 1 1 NA 1## 17 Persephone 1 1 NA 1## 18 Hermes 1 0 NA 0## 19 Hebe 1 0 NA 0## 20 Dionysus 1 0 NA 0
The probability of the potential outcome Ya is the same under A=1 and A=0
Ya⊥⊥ A for all a
The probability of the potential outcome Ya is the same under A=1 and A=0
Ya⊥⊥ A for all a
For the binary treatment variable scenario:
The actual treatment level A does not predict PO Ya
Under exchangeability:
Under exchangeability:
## # A tibble: 20 x 4## greek A Y_a0 Y_a1## <chr> <dbl> <dbl> <dbl>## 1 Rheia 0 0 1## 2 Kronos 0 1 0## 3 Demeter 0 0 0## 4 Hades 0 0 0## 5 Hestia 1 0 0## 6 Poseidon 1 1 0## 7 Hera 1 0 0## 8 Zeus 1 0 1## 9 Artemis 0 1 1## 10 Apollo 0 1 0## 11 Leto 0 0 1## 12 Ares 1 1 1## 13 Athena 1 1 1## 14 Hephaestus 1 0 1## 15 Aphrodite 1 0 1## 16 Cyclope 1 0 1## 17 Persephone 1 1 1## 18 Hermes 1 1 0## 19 Hebe 1 1 0## 20 Dionysus 1 1 0
greek_gods_potential_outcomes %>% group_by(A) %>% count(Y_a0) %>% mutate( denominator = sum(n), pr_of_Y_a0 = round(n / denominator, 2) ) %>% filter(Y_a0 == 1)
## # A tibble: 2 x 5## # Groups: A [2]## A Y_a0 n denominator pr_of_Y_a0## <dbl> <dbl> <int> <int> <dbl>## 1 0 1 3 7 0.43## 2 1 1 7 13 0.54
greek_gods_potential_outcomes %>% group_by(A) %>% count(Y_a1) %>% mutate( denominator = sum(n), pr_of_Y_a1 = round(n / denominator, 2) ) %>% filter(Y_a1 == 1)
## # A tibble: 2 x 5## # Groups: A [2]## A Y_a1 n denominator pr_of_Y_a1## <dbl> <dbl> <int> <int> <dbl>## 1 0 1 3 7 0.43## 2 1 1 7 13 0.54
Marginal randomization (RCT): unconditional assignment of treatment probability
Introducing prognostic factor L
## # A tibble: 20 x 6## greek L A Y_obs Y_a0 Y_a1## <chr> <dbl> <dbl> <dbl> <dbl> <dbl>## 1 Rheia 0 0 0 0 NA## 2 Kronos 0 0 1 1 NA## 3 Demeter 0 0 0 0 NA## 4 Hades 0 0 0 0 NA## 5 Hestia 0 1 0 NA 0## 6 Poseidon 0 1 0 NA 0## 7 Hera 0 1 0 NA 0## 8 Zeus 0 1 1 NA 1## 9 Artemis 1 0 1 1 NA## 10 Apollo 1 0 1 1 NA## 11 Leto 1 0 0 0 NA## 12 Ares 1 1 1 NA 1## 13 Athena 1 1 1 NA 1## 14 Hephaestus 1 1 1 NA 1## 15 Aphrodite 1 1 1 NA 1## 16 Cyclope 1 1 1 NA 1## 17 Persephone 1 1 1 NA 1## 18 Hermes 1 1 0 NA 0## 19 Hebe 1 1 0 NA 0## 20 Dionysus 1 1 0 NA 0
# brokegreek_gods_condrand %>% group_by(A) %>% count(Y_obs) %>% mutate( denominator = sum(n), risk = round(n/sum(n), digits = 2) ) %>% filter(Y_obs == 1)
## # A tibble: 2 x 5## # Groups: A [2]## A Y_obs n denominator risk## <dbl> <dbl> <int> <int> <dbl>## 1 0 1 3 7 0.43## 2 1 1 7 13 0.54
0.54/0.43
## [1] 1.255814
# wokegreek_gods_condrand %>% glm(formula = Y_obs ~ A, family = binomial(link = "log")) %>% broom::tidy(exponentiate = T) %>% filter(term == "A") %>% select(term, estimate)
## # A tibble: 1 x 2## term estimate## <chr> <dbl>## 1 A 1.26
L-stratum specific causal risk ratios
Pr[Ya=1=1|L=1]Pr[Ya=0=1|L=1]
Pr[Ya=1=1|L=0]Pr[Ya=0=1|L=0]
L-stratum specific causal risk ratios
Pr[Ya=1=1|L=1]Pr[Ya=0=1|L=1]
Pr[Ya=1=1|L=0]Pr[Ya=0=1|L=0]
Average causal effect in the entire population:
Pr[Ya=1=1|L=1]Pr[Ya=0=1|L=1]
Same for the stratum L=0
Strata L=0
greek_gods_condrand %>% filter(L == 0) %>% group_by(A) %>% count(Y_obs) %>% mutate( denominator = sum(n), risk = round(n/sum(n), digits = 2) ) %>% filter(Y_obs == 1)
## # A tibble: 2 x 5## # Groups: A [2]## A Y_obs n denominator risk## <dbl> <dbl> <int> <int> <dbl>## 1 0 1 1 4 0.25## 2 1 1 1 4 0.25
Strata L=1
greek_gods_condrand %>% filter(L == 1) %>% group_by(A) %>% count(Y_obs) %>% mutate( denominator = sum(n), risk = round(n/sum(n), digits = 2) ) %>% filter(Y_obs == 1)
## # A tibble: 2 x 5## # Groups: A [2]## A Y_obs n denominator risk## <dbl> <dbl> <int> <int> <dbl>## 1 0 1 2 3 0.67## 2 1 1 6 9 0.67
Average causal effect for the whole population:
mean(greek_gods_condrand$L)
## [1] 0.6
Pr[Ya=1=1]Pr[Ya=0=1]
Standardization formula: Pr(Ya=1)=ΣlPr(Y=1|A=a,L=l)∗Pr(L=l)
pr_a <- glm(data = greek_gods_condrand, formula = A~1, family = binomial("logit"))pr_a_l <- glm(data = greek_gods_condrand, formula = A~L, family = binomial("logit"))greek_gods_condrand %<>% mutate( p_a = predict(object = pr_a, type = "response"), p_a_l = predict(object = pr_a_l, type = "response"), # average treatment effect iptw = if_else(A==1, 1/p_a_l, 1/(1-p_a_l)), # unstabilized weights sw_iptw = if_else(A==1, p_a/p_a_l, (1-p_a)/(1-p_a_l)) # stabilized weights)
greek_gods_condrand %>% select(iptw, sw_iptw) %>% skimr::skim()
Table: Data summary
Name | Piped data |
Number of rows | 20 |
Number of columns | 2 |
_ | |
Column type frequency: | |
numeric | 2 |
__ | |
Group variables | None |
Variable type: numeric
skim_variable | n_missing | complete_rate | mean | sd | p0 | p25 | p50 | p75 | p100 | hist |
---|---|---|---|---|---|---|---|---|---|---|
iptw | 0 | 1 | 2 | 0.92 | 1.33 | 1.33 | 2.00 | 2.0 | 4.0 | ▇▇▁▁▂ |
sw_iptw | 0 | 1 | 1 | 0.27 | 0.70 | 0.87 | 0.87 | 1.3 | 1.4 | ▃▇▁▁▆ |
Figure 2.3
greek_gods_condrand %>% distinct(A, Y_obs, L, iptw, sw_iptw)
## # A tibble: 8 x 5## L A Y_obs iptw sw_iptw## <dbl> <dbl> <dbl> <dbl> <dbl>## 1 0 0 0 2.00 0.7 ## 2 0 0 1 2.00 0.7 ## 3 0 1 0 2. 1.30 ## 4 0 1 1 2. 1.30 ## 5 1 0 1 4.00 1.40 ## 6 1 0 0 4.00 1.40 ## 7 1 1 1 1.33 0.867## 8 1 1 0 1.33 0.867
glm(data = greek_gods_condrand, formula = Y_obs~A, family = binomial("log"), weights = iptw) %>% broom::tidy(exponentiate = T) %>% filter(term == "A") %>% select(term, estimate)
## Warning in eval(family$initialize): non-integer #successes in a binomial glm!
## # A tibble: 1 x 2## term estimate## <chr> <dbl>## 1 A 1.00
glm(data = greek_gods_condrand, formula = Y_obs~A, family = binomial("log"), weights = sw_iptw) %>% broom::tidy(exponentiate = T) %>% filter(term == "A") %>% select(term, estimate)
## Warning in eval(family$initialize): non-integer #successes in a binomial glm!
## # A tibble: 1 x 2## term estimate## <chr> <dbl>## 1 A 1.00
# crude 2x2 tablegreek_gods_condrand %>% group_by(A) %>% count(Y_obs) %>% mutate( denominator = sum(n) ) %>% filter(Y_obs == 1)
## # A tibble: 2 x 4## # Groups: A [2]## A Y_obs n denominator## <dbl> <dbl> <int> <int>## 1 0 1 3 7## 2 1 1 7 13
# unstabilized weights doubled the size of the populationgreek_gods_condrand %>% group_by(A) %>% count(Y_obs, wt = iptw) %>% mutate( denominator = sum(n) ) %>% filter(Y_obs == 1)
## # A tibble: 2 x 4## # Groups: A [2]## A Y_obs n denominator## <dbl> <dbl> <dbl> <dbl>## 1 0 1 10.0 20.0## 2 1 1 10. 20.
# stabilized weights kept the original size of the populationgreek_gods_condrand %>% group_by(A) %>% count(Y_obs, wt = sw_iptw) %>% mutate( denominator = sum(n) ) %>% filter(Y_obs == 1)
## # A tibble: 2 x 4## # Groups: A [2]## A Y_obs n denominator## <dbl> <dbl> <dbl> <dbl>## 1 0 1 3.50 7.00## 2 1 1 6.5 13.
Only one of the two counterfactual outcomes is known: the one corresponding to the treatment level actually received
## # A tibble: 20 x 5## greek A Y_obs Y_a0 Y_a1## <chr> <dbl> <dbl> <dbl> <dbl>## 1 Rheia 0 0 0 NA## 2 Kronos 0 1 1 NA## 3 Demeter 0 0 0 NA## 4 Hades 0 0 0 NA## 5 Hestia 1 0 NA 0## 6 Poseidon 1 0 NA 0## 7 Hera 1 0 NA 0## 8 Zeus 1 1 NA 1## 9 Artemis 0 1 1 NA## 10 Apollo 0 1 1 NA## 11 Leto 0 0 0 NA## 12 Ares 1 1 NA 1## 13 Athena 1 1 NA 1## 14 Hephaestus 1 1 NA 1## 15 Aphrodite 1 1 NA 1## 16 Cyclope 1 1 NA 1## 17 Persephone 1 1 NA 1## 18 Hermes 1 0 NA 0## 19 Hebe 1 0 NA 0## 20 Dionysus 1 0 NA 0
Keyboard shortcuts
↑, ←, Pg Up, k | Go to previous slide |
↓, →, Pg Dn, Space, j | Go to next slide |
Home | Go to first slide |
End | Go to last slide |
Number + Return | Go to specific slide |
b / m / f | Toggle blackout / mirrored / fullscreen mode |
c | Clone slideshow |
p | Toggle presenter mode |
t | Restart the presentation timer |
?, h | Toggle this help |
Esc | Back to slideshow |