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

``````#Post-treatment bias
#Collider bias
#Multicollinearity``````

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

``````# Multicollinearity
# I was using a model to evaluate my pressure. The factors include work hours, age, income, expense, social hours, and sensitivity, etc.. If both work hours and social hours are both put into this model, this will cause a multicollinearty problem. Because, more work hours results in less social hours. ``````

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

``````# Fork: X<-Z->Y. X and Y are independent, conditional on Z.
# Pipe: X->Z->Y. X and Y are independent, conditional on Z.
# Collider: X->Z<-Y. no association between X and Y unless condition on Z. Conditioning on Z, information flows between X and Y.
# The Descendent: X->Z<-Y, Z->D Condition on a descendent of Z in the pipe. Variable D is driven by Z.X and Y are not independent when conditioned on Z or D``````

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

``# As we know, a biased sample means a sample overrepresenting or underrepresenting the population. One example is social impact vs popularity of news. When making decisions on which news which be on the headline, editors will weigh both social impact and popularity, then picking the ones that have a higher overall value score.In this case, conditioning on the overall value scores, there is a negative association between social impact and popularity (espeically in entertainment news). Eventually, the news selected by editors have to have either high social impact or high popularity.``

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. Draw the DAG. How many paths connect X to Y? Which must be closed? Which variables should you condition on now?

``````#There are two paths from X to Y
# 1) X<-U<-A->C<-V->Y: This path has a fork, a collider and a pipe. Because C<-V->Y is not having relation, we can close this path by conditioning on A.

# 2) X<-U->B<-C<-V->Y: This path has two coliiders. This path is closed if there is no condition on B or V``````

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?

``````#install.packages("rstan")
#install.packages("processx")
library(processx)
library(rstan)

#install.packages(c("coda","mvtnorm","devtools","loo","dagitty"))
library(coda)

library(mvtnorm)
library(devtools)

library(loo)

library(dagitty)
#devtools::install_github("rmcelreath/rethinking")
library(rethinking)

N = 1000

set.seed(100)
RT1 = 0.9
RT2 = 0.6
X = rnorm(N)
Z = rnorm(N,RT1*X)
Y = rnorm(N,RT2*Z)
Data_1 = data.frame(X, Y, Z)
cor(Data_1)``````
``````##           X         Y         Z
## X 1.0000000 0.4117249 0.6924074
## Y 0.4117249 1.0000000 0.5692564
## Z 0.6924074 0.5692564 1.0000000``````
``pairs(Data_1)``