The perfect doctor

Lab specs can be found here

Exercise 1

Question: Recreate table 1 shown below, inserting values appropriately for the three empty colums: (i) The column labeled \(\delta_i\): please enter each patient’s treatment effect (ii) The column labeled \(D\): the optimal treatment for this patient (iii) The column labeled \(Y\): the observed outcomes. Calculate the average treatment effect (ATE) and the average treatment effect for the treated (ATT) when comparing the outcome of the ventilators treatment with that of the bedrest treatment and comment as to which type of intervention is more effective on average. Finally, explain under which conditions might SUTVA be violated for treatments of covid-19 in the scenario described above.

# Write your code here

df<- 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) 
df%>% 
  gt()
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
#Observed values

df%>%
 summarize (mn.Y = mean (Y), .by = D)
#SDO
SDO <- mean(df$`Y`[df$D == 1]) -mean(df$`Y`[df$D == 0])


#ATT and ATU

df%>%
 summarize (mn.Y = mean (`Y(1)`-`Y(0)`), .by= D)
#ATE

df%>%
 summarize (mn.Y = mean (`Y(1)` -`Y(0)`))

Answer: ATE is -0.545: This implies that, on average, ventilators are associated with a worse outcome compared to bedrest. It’s the average of the effects on all the units in our analysis, it is a average difference of effect when the units in counterfactual states.

ATT is 4 additional years: This indicates that among the patients who received ventilators (the treated group), the average life gain was 4 years. similar to ATE, but it only consider people who reciveved treatment

ATU is -3.14 years: This indicates that among the patients who did not receive ventilators (the untreated group), the average decrease in outcomes was -3.14 years. The effect of ventilators on those who did not receive them, if they had received the treatment instead.

ATE suggested that bedrest is more effective, but ATT suggested ventilators are more effective, it could be posssible that people who received ventilator already had a worse health status, ventilator works well. However, for general population, ventilator seems to have a negative impact.

If the availability of ventilators for one patient impacts the availability for another, or if bedrest for one patient impacts the spread of the disease to others, then SUTVA could be voilated.

Exercise 2

Question: Calculate the simple difference in outcomes (SDO), showing the details of your calculation. Is the SDO a good estimation for the ATE? Finally, check whether the SDO is equal to the sum of the ATT and the selection bias, \(E[Y(0)|T=1] - E[Y(0)|T=0]\).

# Write your code here
#SDO
SDO <- mean(df$`Y`[df$D == 1]) -mean(df$`Y`[df$D == 0])

#ATT
ATT <- mean(df$`Y(1)`[df$D == 1]) -mean(df$`Y(0)`[df$D == 1])

#ATU
ATU <- mean(df$`Y(1)`[df$D == 0]) -mean(df$`Y(0)`[df$D == 0])

#selection bias
BIAS <- mean(df$`Y(0)`[df$D == 1]) -mean(df$`Y(0)`[df$D == 0])

Answer: SDO is 0.857, while ATE is -0.545. SDO would not be a good estimate for the ATE, they suggested different interventions. SDO is indeed equals to the sum of ATT and bias, which represents pre-treatment differences between the groups.

Exercise 3

Question: Compare the treatment effect for both groups: for those treated with a ventilator and for those treated with bedrest. What explains the difference in the average effect? Now compare all four measures of effects. What are the advantages and disadvantages of each? Is the ATE equal to the mean of the ATU and the ATT? Why or why not?

# Write your code here

SDO <- mean(df$`Y`[df$D == 1]) -mean(df$`Y`[df$D == 0])

#ATT and ATU

df%>%
 summarize (mn.Y = mean (`Y(1)`-`Y(0)`), .by= D)
#ATE

df%>%
 summarize (mn.Y = mean (`Y(1)` -`Y(0)`))

Answer: Ventilators are beneficial for treated patients (ATT) but harmful for untreated patients if they were treated (ATU). ATE, ATU, ATT includes counterfactual outcomes, it is impossible to observe, these are all potential outcomes. SDO contains the observed outcomes, it can be calculated and used as an estimator of ATE. ATE is not equals to the mean of ATT and ATU; it depends on the proportions of treated and untreated groups.

Using regression to estimate effects

The following exercises demonstrate that regression is a useful tool to estimate average outcomes and treatment effects in the different groups. Notice that in contrast to the role that regressions play in traditional statistics, here standard errors and significance are not of primary concern. Instead, we are interested in using regression to calculate average effects proper.

Exercise 4

Question: Calculate the outcome, conditional on getting the bedrest treatment \(\mathbb{E}[Y|D=0]\). Now estimate the following regression, comparing the coefficients \(\alpha\) and \(\delta\) to the statistics you’ve previously calculated. What did you find? How would you explain these finding?

# Write your code here


reg<-lm(Y ~ delta, data = subset(df, D == 0))

summary(reg)
## 
## Call:
## lm(formula = Y ~ delta, data = subset(df, D == 0))
## 
## Residuals:
##       1       2       3       4       5       6       7 
##  0.9561 -2.4211 -3.0965 -0.4474  0.5526  1.5526  2.9035 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)   
## (Intercept)   6.1228     1.3828   4.428  0.00684 **
## delta        -0.3246     0.3368  -0.964  0.37948   
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 2.354 on 5 degrees of freedom
## Multiple R-squared:  0.1566, Adjusted R-squared:  -0.01204 
## F-statistic: 0.9286 on 1 and 5 DF,  p-value: 0.3795

Answer: delta is similar with ATU, it is expected, because delta represents the difference in expected outcomes between the treated and untreated in the control group. That aligns with the concept of ATU, which measures the hypothetical effect of the treatment on the untreated group.

Alpha is the expected outcome for the untreated group, which is similar to the observed average outcome for the untreated group Y(0).

Exercise 5

Question: Now estimate the same regression, but this time, controlling for age, again comparing, the coefficient \(\delta\) to the statistics you’ve previously calculated. What did you find? How do you explain these results?

# Write your code here

regage<-lm(Y ~ delta + Age, data = subset(df, D == 0))

summary(regage)
## 
## Call:
## lm(formula = Y ~ delta + Age, data = subset(df, D == 0))
## 
## Residuals:
##       1       2       3       4       5       6       7 
##  0.6005 -2.3900 -2.4249 -0.3939  0.4423  0.5582  3.6079 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)
## (Intercept)  4.47915    3.24650    1.38    0.240
## delta       -0.44119    0.41604   -1.06    0.349
## Age          0.03275    0.05750    0.57    0.599
## 
## Residual standard error: 2.531 on 4 degrees of freedom
## Multiple R-squared:  0.2199, Adjusted R-squared:  -0.1702 
## F-statistic: 0.5638 on 2 and 4 DF,  p-value: 0.6086

Answer: After adjusting for age, both coefficient decreased, the reduction of delta indicates when controlling for aget, there is a larger difference of treatment outcome in control group. Even though age is not significant, its inclusion might refine the model slightly.

Exercise 6

Question: Estimate the following three regression models. The first model is the same as the one above. The second equation is the auxiliary regression of \(D\) onto \(X_{age}\). The third equation regresses \(Y\) onto \(\tilde{D}\) which is the residual from the second equation. Compare the coefficient on \(D\) from the first equation to the coefficient on \(\tilde{D}\) in the third equation. What does this tell you about how to interpret multivariate regressions?

# Write your code here


#EQ1

lm(Y ~ delta + Age, data = subset(df, D == 0))
## 
## Call:
## lm(formula = Y ~ delta + Age, data = subset(df, D == 0))
## 
## Coefficients:
## (Intercept)        delta          Age  
##     4.47915     -0.44119      0.03275
#EQ2
glm(D ~ Age, family = binomial(link = "logit"), data = df)
## 
## Call:  glm(formula = D ~ Age, family = binomial(link = "logit"), data = df)
## 
## Coefficients:
## (Intercept)          Age  
##     -8.5254       0.1261  
## 
## Degrees of Freedom: 10 Total (i.e. Null);  9 Residual
## Null Deviance:       14.42 
## Residual Deviance: 5.819     AIC: 9.819
#EQ3
reg_aux <- glm(D ~ Age, family = binomial(link = "logit"), data = df)
df$residuals_aux <- resid(reg_aux)
reg_residual <- lm(Y ~ residuals_aux, data = df)
summary(reg_residual)
## 
## Call:
## lm(formula = Y ~ residuals_aux, data = df)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -3.4615 -1.8843  0.3126  2.0553  2.6487 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept)     7.4524     0.7009  10.632 2.14e-06 ***
## residuals_aux  -0.1381     0.9637  -0.143    0.889    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 2.324 on 9 degrees of freedom
## Multiple R-squared:  0.002277,   Adjusted R-squared:  -0.1086 
## F-statistic: 0.02054 on 1 and 9 DF,  p-value: 0.8892

Answer: The logistic regression estimates the probability of being treated based on Age. The positive coefficient for Age suggests that as age increases, the likelihood of receiving the treatment increases. The third regression uses the residuals from the second regression (residuals_aux), which represent the part of the D that is not explained by Age, to predict Y. The third regression highlights that controlling for confounders (like Age) can change the estimated effect of the treatment variable. This demonstrates the importance of considering and adjusting for confounders to obtain an unbiased estimate of the treatment effect.