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.

# Three mechanisms by which multiple regression can produce false inferences about causal effects:
# 1. Multicollinearity
# 2. Post-treatment bias 
# 3. collider bias 

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

# Example of Multicollinearity
# what is the relationship between test score to IQ and GPA. Since IQ and GPA is highly correlated. Then, we have a 
# Multicollinearity problem.

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

# Four elemental confounds:
# The Confounding Fork: Z is a common cause of X and Y
# The Perplexing Pipe: X causes Z causes Y
# The Explosive Collider: X and Y jointly cause Z
# The Descendant: conditioning on A is like conditioning on Z

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

# The example of newsworthiness and trustworthiness scores. The editors usually want to choose both high newsworthiness and trustworthiness scores proposal to fund. But since the relation between newsworthiness and trustworthiness scores is negative. When the editors choose one proposal with high trustworthiness scores, it will end up with low trustworthiness scores. 

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?

# There are four paths in total:
# 1. X ← U ← A → C → Y
# 2.  X ← U ← A → C → V → Y
# 3. X ← U → B ← C → Y
# 4. X ← U → B ← C → V → Y
# 
# 
# Path 1: condition on A to close 
# Path 4: condition on B to open  

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?

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)
## Loading required package: parallel
## rethinking (Version 2.12)
## 
## Attaching package: 'rethinking'
## The following object is masked from 'package:stats':
## 
##     rstudent
n<- 1000
b_xz<- 0.9
b_zy<- 0.7

set.seed(100)
x<- rnorm(n)
z<- rnorm(n,x*b_xz)
y<- rnorm(n,z*b_zy)

results <- data.frame(x,y,z)
cor(results)
##           x         y         z
## x 1.0000000 0.4562717 0.6924074
## y 0.4562717 1.0000000 0.6351279
## z 0.6924074 0.6351279 1.0000000
model <- quap( alist(
y ~ dnorm( mu , sigma ) ,
sigma ~ dexp( 1 ),
a ~ dnorm( 1, 30 ) ,
b ~ dnorm( 2 , 10 ) ,
c ~ dnorm( 2 , 10 ) ,
mu <- a + b*x + c*z 
), data=results) 
## Caution, model may not have converged.
## Code 1: Maximum iterations reached.
precis(model)
## Warning in sqrt(diag(vcov(model))): NaNs produced

## Warning in sqrt(diag(vcov(model))): NaNs produced

## Warning in sqrt(diag(vcov(model))): NaNs produced
##             mean        sd      5.5%    94.5%
## sigma 661.101846       NaN       NaN      NaN
## a      -5.659925 17.151843 -33.07188 21.75203
## b       1.371683  9.097619 -13.16807 15.91144
## c       2.084740  8.503467 -11.50544 15.67492
# Since X and Z are highly correlated, there is a multicollinearity problem, but Z will provide more info of Y. However for the legs example, the length of two legs will provide same info. They will not provide any more info.