Practice: Chp. 6

Practice: Chp. 6#

source("iplot.R")
suppressPackageStartupMessages(library(rethinking))

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

Answer. Multicollinearity, Post-treatment bias, and Collider bias (the Chapter’s section titles).

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

Answer. From the beginning of Section 6.4 (Confronting confounding):

  • The Fork

  • The Pipe

  • The Collider

  • The Descendant

For practice understanding which variables are ‘connected’ (dependent, covariate) without the help of automatic tools, see the DAGitty tutorial d-Separation Without Tears.

The Fork and Pipe actually have one and the same conditional dependency:

\[ X \perp \!\!\! \perp Y | Z \]

The Collider has no conditional dependencies, but \(X \perp Y\) unconditionally.

The Descendant is similar to the Collider. It still has \(X \perp Y\) unconditionally, but has the additional conditional dependencies:

\[\begin{split} \begin{align} X \perp \!\!\! \perp D | Z \\ Y \perp \!\!\! \perp D | Z \end{align} \end{split}\]

Notice X -> Z -> D and Y -> Z -> D are Pipes in themselves.

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

Answer. In a biased sample you’re presumably unaware of the additional variable; it’s simply not in your tables and generally not on your radar (e.g. in your causal diagram).

When you condition on a collider you are aware of the variable but instead choose to sample from the part of your table that is biased toward a particular realization of the variable.

source("practice-deconfound-chp6-models.R")

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?

../../_images/385bb72a74c9f356592210c14c97837001516f9b39b0bdacd521234a9144a773.png
{ A }

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?

Answer. We still observe multicollinearity, most likely because it’s now impossible to distinguish the noise inherent in our measurement of Y from any noise added to Z relative to X. If the noise we add as part of generating Y is on the same scale as the noise added to Z, then we don’t observe this issue.

Removing predictors based on pairwise correlation is dangerous because we don’t know whether (in this case) either X or Z has a causal influence on Y. We really have no reason to prefer removing either X or Z from the analysis based on pairwise correlation, so we could easily remove the wrong one (X in this case) and infer that X has a direct (rather than total/indirect) causal influence on Y. If we were to then condition on Z, we’d be surprised with the results.

../../_images/b86032dd479035ccb586d8960f3f9681d18104260e5201274479a4057473031c.png
0.999773898191122
A precis: 4 × 4
meansd5.5%94.5%
<dbl><dbl><dbl><dbl>
a-0.005013250.01756539-0.033086140.02305964
bZ 0.451058800.86229540-0.927055791.82917339
bX 0.548297210.86204318-0.829414291.92600871
sigma 0.175287360.01237711 0.155506340.19506837
../../_images/788bfad9f1b44af3051fd691ae4bffdb2bf0c986f471d9db3957f4e50d4ae407.png ../../_images/ad4761b70fff751c91b4bef0213df62ff80deb523daae59db5e4f965b9454ae0.png

6M3. Learning to analyze DAGs requires practice. For each of the four DAGs below, state which variables, if any, you must adjust for (condition on) to estimate the total causal influence of X on Y.

Answer. Reading the DAGs from the left to right, top to bottom:

  1. Only Z, although A would not hurt (it is a competing exposure).

  2. Only A. Conditioning on Z would measure direct effect rather than total effect.

  3. None. Conditioning on Z would lead to collider bias.

  4. Only A, which is otherwise a ‘Fork’ confounder (an ancestor of both X and Y).

See also:

6H1. 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.

../../_images/8981b4f3facdb9546ea88108f4273276e46b073250287bd70be0dd200ac06af0.png

Adjustment Sets:

{ A, M }
{ S }
../../_images/0974e0875f5c0f4a9c6bb997f64c67a405d690e6fa2ac5f2e6a41f504d66b797.png

6H2. 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.

A _||_ W | S
D _||_ S | A, M, W
M _||_ W | S
../../_images/86e4547bc190f231ed9c1438cefcb8d3744c81acdc778852e2b8ebb38df20c84.png ../../_images/f30ab61ce80c7735cbd8de3a49584dd5a0797bd222649102f059a832977d0ae3.png

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:

source('load-fox-models.R')
iplot(function() plot(dag_foxes), scale=10)
display_markdown("Implied Conditional Dependencies:")
display(impliedConditionalIndependencies(dag_foxes))
../../_images/eb99ab5bae9dc73d4ee6d4d67302d9269c8156e3d62f34b93616d4fa62d139bb.png

Implied Conditional Dependencies:

area _||_ grps | avgf
area _||_ wght | avgf

6H3. 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.

Answer. We have nothing to condition on if we only care about the total causal effect of area on weight:

display(adjustmentSets(dag_foxes, exposure="area", effect="total"))
 {}

Answer. Assume the average area corresponds to the average weight in the priors (\(\beta_0\)):

prior <- extract.prior(mfox_Weight_Area)
mu <- link(mfox_Weight_Area, post=prior , data=list( Area=c(-2,2) ) )
iplot(function() {
    plot( NULL , ylab="Weight", xlab="Area", xlim=c(-2,2) , ylim=c(-2,2) )
    for ( i in 1:50 ) lines( c(-2,2) , mu[i,] , col=col.alpha("black",0.4) )
})
../../_images/0f25c5fe24a343f551e7f63b743ab1a5b126349b061575beff5332142ab377cd.png

Presumably because a larger area implies both more food (increasing weight) and a larger group (decreasing weight, more mouths to feed) the total causal effect of area on weight is nearly zero:

iplot(function() plot(coeftab(mfox_Weight_Area)), ar=3)
../../_images/44e9ed9b76a1dda063f2b1781309f33dc06e213b795009479bd823f5b8b78a0a.png

6H4. 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?”

Answer. We have nothing to condition on if we only care about the total causal effect of food on weight:

display(adjustmentSets(dag_foxes, exposure="avgfood", effect="total"))
 {}

Answer. Presumably because food also affects group size, and a larger group means more mouths to feed, there appars to be no noticeable impact of more food on weight:

iplot(function() plot(coeftab(mfox_Weight_Avgfood)), ar=3.5)
../../_images/d2c71e870f2a387b1e14402077f0e5e975427a06406eafa0cdf6e78bd313df95.png

It’s more interesting to look at the direct affect of food on weight. To see this we’ll need to adjust for groupsize:

display(adjustmentSets(dag_foxes, exposure="avgfood", effect="direct"))
{ groupsize }

As expected, food has a positive influence on weight (bAvgfood is positive):

iplot(function() plot(coeftab(mfox_Weight_AvgfoodGroupsize)), ar=3)
../../_images/348342370ec621bf218df49fc37f391e39985013bd6296bca0b38958b14e984a.png

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

Answer. We need to adjust for only avgfood assuming we are interested in the total causal effect of groupsize (otherwise avgfood would be a confounder):

display(adjustmentSets(dag_foxes, exposure="groupsize", effect="total"))
{ avgfood }

See the model mfox_Weight_AvgfoodGroupsize above for a model that already includes only groupsize and avgfood. As expected, groupsize has a negative influence on weight (bGroupsize is negative) presumably because a bigger group means more mouths to feed.