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
#ATE calculation
df%>%
 summarize(ATE = mean(`Y(1)`-`Y(0)`))
#ATT & ATU
df%>%
summarize(mean.delta=mean(delta), .by=D)

Answer:ATE = -0.545 ATT =4. SUTVA might be violated when the tratment assigned to one participant might affect the treatment of another participants. I can think of the limited availability of ventialtors, the limited supply of this equipment might affect te possibilities of other patients accessing such equipment [Replace this with your answer]

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 calculation
  
  df%>%
  summarize(mn.Y = mean(Y), .by =D)
#Selection bias
mean_D1 <- mean(df$`Y(0)`[df$D == 1])

# Calculate mean of 'variable' when D = 0
mean_D0 <- mean(df$`Y(0)`[df$D == 0])

# Calculate the difference
mean_diff <- mean_D1 - mean_D0

# Print results
cat("Mean of 'variable' when D = 1:", mean_D1, "\n")
## Mean of 'variable' when D = 1: 4
cat("Mean of 'variable' when D = 0:", mean_D0, "\n")
## Mean of 'variable' when D = 0: 7.142857
cat("Difference in means:", mean_diff, "\n")
## Difference in means: -3.142857

Answer:SDO= mean Y when D=1 (7.14)-mean Y when D=0 (8)=0.857142857 . SDO is not a good estimation of ATE. ATT=4 ,Selection bias= -3.142857143; SDO=4+(-3.142857143)=0.857142857. Yes, SDO is = to ATT + SELECTION BIAS

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
#ATT & ATU
df%>%
summarize(mean.delta=mean(delta), .by=D)

Answer:ATT= 4 ATU= -3.142857143. The patients treated with the ventilator show an improvement in the outcome, while the treated with bed rest show a negative effect. The ATE is not the same because ATT and ATU condition by the treatment the patients have received [Replace this with your answer]

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
lm(Y ~ delta, data = subset(df, D == 0))
## 
## Call:
## lm(formula = Y ~ delta, data = subset(df, D == 0))
## 
## Coefficients:
## (Intercept)        delta  
##      6.1228      -0.3246

Answer:Coefficients: alpha=6.1228 delta= -0.3246 The coefficient of delta is similat to the ATU since it is the difference in effect when the treatment is not given. alpha is similar to the mean baseline values of Y(0) when the population is not treated [Replace this with your answer]

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
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

Answer:Coefficients: alpha=4.47915 delta=-0.44119 Age=0.03275. Age has an effect on both delta and alpha, showing an reduction in the value of the baseline mean values of the population and a larger difference when adjusted by age in the non treated [Replace this with your answer]

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:Adjusting for the residual of D decreases the effect of delta [Replace this with your answer]