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: multi-collinearity, 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.
6-1. Use the Waffle House data, data(WaffleDivorce), to find the total causal influence of number of Waffle Houses on divorce rate. Justify your model or models with a causal graph (draw a DAG).
data(WaffleDivorce)
data <- WaffleDivorce
DAG <- dagitty("dag {
A -> D
A -> M -> D
A <- S -> M
S -> W -> D
}")
coordinates(DAG) <- list(
x = c(A = 1, S = 1, M = 2, W = 3, D = 3),
y = c(A = 1, S = 3, M = 2, W = 3, D = 1)
)
drawdag(DAG)
adjustmentSets(DAG, exposure = "W", outcome = "D")
## { A, M }
## { S }
model <- quap(
alist(
Divorce ~ dnorm(mu, sigma),
mu <- a + bS * South + bW * WaffleHouses,
a ~ dnorm(0, 0.2),
c(bS, bW) ~ dnorm(0, 0.5),
sigma ~ dexp(1)
),
data = data
)
precis(model)
## mean sd 5.5% 94.5%
## a 0.24107433 0.20212236 -0.08195624 0.56410490
## bS 0.21518881 0.49545902 -0.57665040 1.00702801
## bW 0.06218672 0.01549949 0.03741555 0.08695789
## sigma 7.82233826 0.72280963 6.66714888 8.97752765
6-2. Build a series of models to test the implied conditional independencies of the causal graph you used in the previous problem. If any of the tests fail, how do you think the graph needs to be amended? Does the graph need more or fewer arrows? Feel free to nominate variables that arenโt in the data.
impliedConditionalIndependencies(DAG)
## A _||_ W | S
## D _||_ S | A, M, W
## M _||_ W | S
# Check A _||_ W | S
model1 <- quap(
alist(
MedianAgeMarriage ~ dnorm(mu, sigma),
mu <- a + bS * South + bW * WaffleHouses,
a ~ dnorm(0, 0.2),
c(bS, bW) ~ dnorm(0, 0.5),
sigma ~ dexp(1))
,
data = data
)
precis(model1)
## mean sd 5.5% 94.5%
## a 0.10712613 0.20030749 -0.21300392 0.4272562
## bS 0.08254169 0.49920381 -0.71528241 0.8803658
## bW 0.15553093 0.03841526 0.09413593 0.2169259
## sigma 19.75045318 1.57124236 17.23930442 22.2616019
# Check D _||_ S | A, M, W
model2 <- quap(
alist(
Divorce ~ dnorm(mu, sigma),
mu <- a + bA * MedianAgeMarriage + bS * South + bM * Marriage + bW * WaffleHouses,
a ~ dnorm(0, 0.2),
c(bA, bS, bM, bW) ~ dnorm(0, 0.5),
sigma ~ dexp(1)
),
data = data
)
precis(model2)
## mean sd 5.5% 94.5%
## a 0.019664997 0.19996091 -0.29991115 0.33924115
## bA 0.168845872 0.04072965 0.10375202 0.23393972
## bS 0.406129109 0.41291916 -0.25379546 1.06605368
## bM 0.246454650 0.05151472 0.16412418 0.32878512
## bW 0.005314709 0.00405780 -0.00117044 0.01179986
## sigma 1.639864521 0.16147716 1.38179284 1.89793620
# Check M _||_ W | S
model3 <- quap(
alist(
Marriage ~ dnorm(mu, sigma),
mu <- a + bS * South + bW * WaffleHouses,
a ~ dnorm(0, 0.2),
c(bS, bW) ~ dnorm(0, 0.5),
sigma ~ dexp(1)
),
data = data
)
precis(model3)
## mean sd 5.5% 94.5%
## a 0.1267937 0.20045205 -0.19356743 0.4471547
## bS 0.1059600 0.49881614 -0.69124453 0.9031645
## bW 0.1224513 0.03098106 0.07293764 0.1719651
## sigma 15.8854610 1.31519414 13.78352671 17.9873952
6-3. Consider your own research question. Draw a DAG to represent it. What are the testable implications of your DAG? Are there any variables you could condition on to close all backdoor paths? Are there unobserved variables that you have omitted? Would a reasonable colleague imagine additional threats to causal inference that you have ignored?
# Research question: How the higher demand for houses impact house prices.
# Implication: There is a direct relationship between the housing demand and house prices; higher housing demand increases house prices.
# In the long term, factors such as increase in the number of millennials who have high savings, increase in wealthy immigrants would continue to increase the demand for houses. Constructions company will catch up this trend and construct more houses Therefore, there is a backdoor channel that the increase in housing demand will also make construction companies expand their construction plans and sell more houses.The increasing supply of houses may impact house prices.
DAG2 <- dagitty("dag {
Demand -> Price
Demand -> Construction -> Price
}")
drawdag(DAG2)
adjustmentSets(DAG2, exposure = "Construction", outcome = "Price")
## { Demand }
6-4. For the DAG you made in the previous problem, can you write a data generating simulation for it? Can you design one or more statistical models to produce causal estimates? If so, try to calculate interesting counterfactuals. If not, use the simulation to estimate the size of the bias you might expect. Under what conditions would you, for example, infer the opposite of a true causal effect?
N <-50000
set.seed(123)
demand <-rnorm(N,10,3)
construction <-demand*rnorm(N,0,2)+rnorm(N,10,3)
price <-demand - construction + rnorm(N,0,2)
data2 <-data.frame(demand,construction,price)
model4 <- quap(
alist(
price ~ dnorm(mu, sigma),
mu <- a + bD * demand + bS * construction,
a ~ dnorm(0, 1),
c(bD, bS) ~ dnorm(0, 2),
sigma ~ dexp(1))
,
data = data2
)
precis(model4)
## mean sd 5.5% 94.5%
## a 0.001632909 0.031492266 -0.04869782 0.05196363
## bD 1.002050653 0.002989124 0.99727346 1.00682785
## bS -1.000808625 0.000425442 -1.00148856 -1.00012869
## sigma 2.006203306 0.006343963 1.99606443 2.01634218