Chapter 6 - The Haunted DAG & The Causal Terror

Multiple regression is no oracle, but only a golem. It is logical, but the relationships it describes are conditional associations, not causal influences. Therefore additional information, from outside the model, is needed to make sense of it. This chapter presented introductory examples of some common frustrations: multicollinearity, post-treatment bias, and collider bias. Solutions to these frustrations can be organized under a coherent framework in which hypothetical causal relations among variables are analyzed to cope with confounding. In all cases, causal models exist outside the statistical model and can be difficult to test. However, it is possible to reach valid causal inferences in the absence of experiments. This is good news, because we often cannot perform experiments, both for practical and ethical reasons.

Place each answer inside the code chunk (grey box). The code chunks should contain a text response or a code that completes/answers the question or activity requested. Make sure to include plots if the question requests them.

Finally, upon completion, name your final output .html file as: YourName_ANLY505-Year-Semester.html and publish the assignment to your R Pubs account and submit the link to Canvas. Each question is worth 5 points.

Questions

6-1. Modify the DAG on page 186 to include the variable V, an unobserved cause of C and Y: C ← V → Y. Reanalyze the DAG. Draw the DAG. How many paths connect X to Y? Which must be closed? Which variables should you condition on now?

dag_6.1 <- dagitty("dag{
    U[unobserved]
    V[unobserved]
    X->Y
    X <- U <- A -> C -> Y
    U -> B <- C
    C <- V -> Y
    }")
adjustmentSets(dag_6.1,exposure="X",outcome="Y")
## { A }
## { A }

drawdag(dag_6.1)

# Four pathways
# X <- U <- A -> C -> Y
# X <- U -> B <- C -> Y
# X <- U <- A -> C <- V -> Y
# X <- U -> B <- C <- V -> Y
#The first path must be closed and the fourth path can be opened.
#The variables that should condition on are variable A for path one and variable B for path four

6-2. Sometimes, in order to avoid multicollinearity, people inspect pairwise correlations among predictors before including them in a model. This is a bad procedure, because what matters is the conditional association, not the association before the variables are included in the model. To highlight this, consider the DAG X → Z → Y. Simulate data from this DAG so that the correlation between X and Z is very large. Then include both in a model prediction Y. Do you observe any multicollinearity? Why or why not? What is different from the legs example in the chapter?

library(rethinking)
N = 100
x = rnorm(N, mean = 0, sd = 1)
z = rnorm(N, mean = x, sd = 0.5)
y = rnorm(N, mean = z, sd = 0.5)
cor(x,z)
## [1] 0.8973031
d <- data.frame(y,x,z)

m6.1 = quap(
  alist(
      y ~ dnorm(mu, sigma),
      mu <- a + bx*x + bz*z,
      a ~ dnorm(0,0.2),
      bx ~ dnorm(0,0.5),
      bz ~ dnorm(0,0.5),
     sigma ~ dexp(1)
  ), data = d
)

precis(m6.1)
##              mean         sd       5.5%      94.5%
## a     -0.03348935 0.04881887 -0.1115113 0.04453264
## bx     0.13117924 0.11198630 -0.0477965 0.31015498
## bz     0.84211940 0.10339695  0.6768711 1.00736770
## sigma  0.50074756 0.03530623  0.4443214 0.55717373
plot(precis(m6.1))

# There seem to be no multicollinearity because bx is closed to 0 and bz is closed to 1. In the leg example, both legs can be used to predict height. However, in this example, z can positively predict y, but x doesn’t predict y that well.

All three problems below are based on the same data. The data in data(foxes) are 116 foxes from 30 different urban groups in England. These foxes are like street gangs. Group size varies from 2 to 8 individuals. Each group maintains its own urban territory. Some territories are larger than others. The area variable encodes this information. Some territories also have more avgfood than others. We want to model the weight of each fox. For the problems below, assume the following DAG:

6-3. Use a model to infer the total causal influence of area on weight. Would increasing the area available to each fox make it heavier (healthier)? You might want to standardize the variables. Regardless, use prior predictive simulation to show that your model’s prior predictions stay within the possible outcome range.

library(dplyr)
library(tibble)
library(tidyr)
data("foxes")

fox <- foxes[,-1] %>%
           as_tibble() %>%
           mutate(across(everything(), standardize))

N<-100
a <- rnorm(N, 0, 0.5)
b <- rnorm(N, 0, 0.5)
plot(NULL, xlim=range(fox$area),ylim=c(-4,4))
xbar<-mean(fox$area)
for(i in 1:N) curve(a[i] + b[i]*(x- xbar),
                   from=min(fox$area), to = max(fox$area), add = TRUE,
                   col = col.alpha("red",0.3)
                   )

m6.3 = quap(
  alist(
      weight ~ dnorm(mu, sigma),
      mu <- a + ba*area,
      a ~ dnorm(0,3),
      ba ~ dnorm(0,5),
     sigma ~ dexp(1)
  ), data = fox
)

precis(m6.3)
##               mean         sd       5.5%     94.5%
## a     7.383735e-09 0.09199341 -0.1470232 0.1470233
## ba    1.947065e-02 0.09242020 -0.1282347 0.1671760
## sigma 9.912655e-01 0.06466639  0.8879162 1.0946149
plot(precis(m6.3))

# Since the coefficient for area is close to zero, we could conclude there's no causal impact for the area to the weight of foxes

6-4. Now infer the causal impact of adding food to a territory. Would this make foxes heavier? Which covariates do you need to adjust for to estimate the total causal influence of food?

m6.4 = quap(
  alist(
      weight ~ dnorm(mu, sigma),
      mu <- a + baf*avgfood,
      a ~ dnorm(0,3),
      baf ~ dnorm(0,5),
     sigma ~ dexp(1)
  ), data = fox
)

precis(m6.4)
##                mean         sd       5.5%     94.5%
## a     -1.242994e-06 0.09198691 -0.1470141 0.1470116
## baf   -2.503248e-02 0.09241366 -0.1727274 0.1226624
## sigma  9.911954e-01 0.06466695  0.8878452 1.0945457
plot(precis(m6.4))

#Average food doesn’t have a significant causal effect on weight. No adjustment is needed.

6-5. Now infer the causal impact of group size. Which covariates do you need to adjust for? Looking at the posterior distribution of the resulting model, what do you think explains these data? That is, can you explain the estimates for all three problems? How do they go together?

m6.5 = quap(
  alist(
      weight ~ dnorm(mu, sigma),
      mu <- a + baf*avgfood + bgs*groupsize,
      a ~ dnorm(0,3),
      baf ~ dnorm(0,5),
      bgs ~ dnorm(0,5),
     sigma ~ dexp(1)
  ), data = fox
)

precis(m6.5)
##                mean         sd       5.5%      94.5%
## a      3.955985e-06 0.08716616 -0.1393044  0.1393123
## baf    6.388380e-01 0.20205341  0.3159176  0.9617584
## bgs   -7.366218e-01 0.20205342 -1.0595422 -0.4137014
## sigma  9.392048e-01 0.06128487  0.8412598  1.0371499
plot(precis(m6.5))

#Group size has a negative effect on weight while average food has a positive effect on weight. However, when considering all the factor together, the positive effect brought by average food get canceled out by the negative effect from group size.