library(tidyverse)ββ Attaching core tidyverse packages ββββββββββββββββββββββββ tidyverse 2.0.0 ββ
β dplyr 1.1.3 β readr 2.1.4
β forcats 1.0.0 β stringr 1.5.0
β ggplot2 3.4.3 β tibble 3.2.1
β lubridate 1.9.2 β tidyr 1.3.0
β purrr 1.0.2
ββ Conflicts ββββββββββββββββββββββββββββββββββββββββββ tidyverse_conflicts() ββ
β dplyr::filter() masks stats::filter()
β dplyr::lag() masks stats::lag()
βΉ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
data <- tribble(
~patient, ~`Y(0)`, ~`Y(1)`, ~Age, ~`delta`, ~`D`, ~`Y`,
1, 10, 1, 29, -9, 0, 10,
2, 5, 1, 35, -4, 0, 5,
3, 4, 1, 19, -3, 0, 4,
4, 6, 5, 45, -1, 0, 6,
5, 1, 5, 65, 4, 1, 5,
6, 7, 6, 50, -1, 0, 7,
7, 8, 7, 77, -1, 0, 8,
8, 10, 7, 18, -3, 0, 10,
9, 2, 8, 85, 6, 1, 8,
10, 6, 9, 96, 3, 1, 9,
11, 7, 10, 77, 3, 1, 10)
print(data)# A tibble: 11 Γ 7
patient `Y(0)` `Y(1)` Age delta D Y
<dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
1 1 10 1 29 -9 0 10
2 2 5 1 35 -4 0 5
3 3 4 1 19 -3 0 4
4 4 6 5 45 -1 0 6
5 5 1 5 65 4 1 5
6 6 7 6 50 -1 0 7
7 7 8 7 77 -1 0 8
8 8 10 7 18 -3 0 10
9 9 2 8 85 6 1 8
10 10 6 9 96 3 1 9
11 11 7 10 77 3 1 10
data %>%
summarise(ATE = mean(delta))# A tibble: 1 Γ 1
ATE
<dbl>
1 -0.545
data %>%
filter(D == 1) %>%
summarise(ATT = mean(delta))# A tibble: 1 Γ 1
ATT
<dbl>
1 4