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. Problems are labeled Easy (E), Medium (M), and Hard(H).

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

6E1. List three mechanisms by which multiple regression can produce false inferences about causal effects.

#The three mechanisms by which multiple regression can produce false inferences about causal effects are Collider Bias, Post-Treatment Bias and Multicollinearity

6E2. For one of the mechanisms in the previous problem, provide an example of your choice, perhaps from your own research.

#Considering Multicollinearity as a sample mechanism, lets assume we are predicting weather in a certain region, considering both humidity and temperature as predictor variables may result in multicollinearity because generally humid places usually have high temperatures, so prediction of weather can be erroneous.

6E3. List the four elemental confounds. Can you explain the conditional dependencies of each?

#Four elemental confounds:
#The Descendant- Variable X causes Z and variable Z causes A and Y. Condition on Z is equivalent to condition on A
#The Fork- Variable Z is a common cause of variables X and Y. X and Y are independent and condition on Z
#The Pipe- Variable X causes Z and Z further causes variable Y. X and Y are independent and condition on Z
#The Collider- Both variables X and Y cause variable Z. X and Y are dependent when condition on Z

6E4. How is a biased sample like conditioning on a collider? Think of the example at the open of the chapter.

#For a biased sample like conditioning on a collider, taking newsworthiness vs trustworthiness in publishing scientific papers example from the chapter, newsworthy examples are not very trustworthy, so conditioning on this would result in collider confound.

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

#1. X <- U <- A -> C -> Y
#2. X <- U -> B <- C -> Y
#3. X <- U <- A -> C -> V -> Y
#4. X <- U -> B <- C -> V -> Y
#From above, there seems to be four paths which connect X to 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

6M2. 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?

#DAG- X → Z → Y
#Loading library
library(rethinking)
## Loading required package: rstan
## Loading required package: StanHeaders
## Loading required package: ggplot2
## rstan (Version 2.21.2, GitRev: 2e1f913d3ca3)
## For execution on a local, multicore CPU with excess RAM we recommend calling
## options(mc.cores = parallel::detectCores()).
## To avoid recompilation of unchanged Stan programs, we recommend calling
## rstan_options(auto_write = TRUE)
## Do not specify '-march=native' in 'LOCAL_CPPFLAGS' or a Makevars file
## Loading required package: parallel
## rethinking (Version 2.13)
## 
## Attaching package: 'rethinking'
## The following object is masked from 'package:stats':
## 
##     rstudent
#Samples
N <- 100
#Variables
a <- 0.9
b <- 0.7
set.seed(10)
x <- rnorm(N)
y <- rnorm(N, x*a)
z <- rnorm(N, y*b)
#Data frame
df <- data.frame(x, y, z)
cor(df)
##           x         y         z
## x 1.0000000 0.6327509 0.4516289
## y 0.6327509 1.0000000 0.6264275
## z 0.4516289 0.6264275 1.0000000
#Quap
m1 <-quap(
  alist(
    z ~ dnorm(mu, sigma),
    mu<- d + e * x + f * y,
    d ~ dnorm(1, 10),
    e ~ dnorm(2,20),
    f ~ dnorm(3, 30),
    sigma ~ dexp(1)
  ), data=df)

precis(m1)
##             mean         sd        5.5%     94.5%
## d     0.01593501 0.09700491 -0.13909758 0.1709676
## e     0.12165392 0.13162992 -0.08871611 0.3320240
## f     0.56450270 0.09912791  0.40607715 0.7229282
## sigma 0.95459998 0.06702199  0.84748590 1.0617141