Chapter 17: Exercises

Exercises are graded by difficulty: - One star (*): Apply the technique from the chapter to a new dataset or scenario - Two stars (**): Extend the technique or combine it with a previous chapter's methods - Three stars (***): Derive a result, implement from scratch, or design a system component - Four stars (****): Research-level problems that connect to open questions in the field


DAG Construction and Junction Types

Exercise 17.1 (*)

For each of the following scenarios, draw the causal DAG and identify all forks, chains, and colliders.

(a) A study of the effect of exercise on blood pressure. Exercise increases cardiovascular fitness, which lowers blood pressure. Age is a common cause of both exercise (older people exercise less) and blood pressure (blood pressure increases with age). Body mass index (BMI) is affected by exercise and also affects blood pressure.

(b) A study of the effect of advertising spend on product sales. Brand awareness mediates the advertising-sales relationship. Seasonality affects both advertising budgets (companies spend more before holidays) and sales (consumers buy more before holidays). Customer reviews are caused by both product quality and sales volume.

(c) A study of the effect of college education on earnings. Parental income affects both college attendance (wealthier families send children to college) and earnings (through network effects). Test scores are caused by both innate ability and parental investment. College selectivity depends on both test scores and parental donations.


Exercise 17.2 (*)

Consider the DAG: $A \to B \to C \leftarrow D \to E$.

(a) List all paths between $A$ and $E$.

(b) For each path, identify whether it is a causal (directed) path or a non-causal path.

(c) Is $A$ d-separated from $E$ by $\emptyset$? Explain.

(d) Is $A$ d-separated from $E$ by $\{C\}$? Explain.

(e) Is $A$ d-separated from $E$ by $\{B\}$? Explain.

(f) Is $A$ d-separated from $E$ by $\{B, D\}$? Explain.


Exercise 17.3 (*)

Classify each variable in the following DAG as a confounder, mediator, collider, or none, with respect to the causal effect of $X$ on $Y$:

Z1 --> X --> M --> Y
Z1 --> Y
Z2 --> X
Z2 --> C <-- Y
Z3 --> Y

For each variable, state whether conditioning on it would bias, debias, or not affect the estimate of the causal effect of $X$ on $Y$.


Exercise 17.4 (*)

A hospital wants to estimate the effect of a surgical procedure (Treatment) on patient recovery time (Outcome). They have data on:

  • Patient age
  • Disease severity (measured by lab tests)
  • Surgeon experience
  • Post-operative complications
  • Hospital readmission within 30 days

Draw a plausible causal DAG. Identify which variables are good controls and which are bad controls for estimating the effect of the surgical procedure on recovery time. Justify each classification.


d-Separation

Exercise 17.5 (**)

Consider the following DAG:

A --> B --> C --> D
A --> E --> D
B --> F <-- E

Determine whether the following d-separation statements hold. For each, list all paths and explain which are blocked or active.

(a) $A \perp_{\mathcal{G}} D \mid \emptyset$

(b) $A \perp_{\mathcal{G}} D \mid \{B, E\}$

(c) $A \perp_{\mathcal{G}} D \mid \{C, E\}$

(d) $A \perp_{\mathcal{G}} D \mid \{F\}$

(e) $B \perp_{\mathcal{G}} E \mid \emptyset$

(f) $B \perp_{\mathcal{G}} E \mid \{A\}$

(g) $B \perp_{\mathcal{G}} E \mid \{A, F\}$


Exercise 17.6 (**)

Write a Python function is_d_separated(dag, x, y, z_set) that determines whether $X$ and $Y$ are d-separated given $\mathbf{Z}$ in a DAG. The function should:

  1. Accept a DAG as a dictionary of edges (e.g., {"A": ["B", "C"], "B": ["D"]}).
  2. Enumerate all paths between $X$ and $Y$.
  3. For each path, determine whether it is blocked by $\mathbf{Z}$ using the three junction rules.
  4. Return True if all paths are blocked, False otherwise.

Test your function on the DAG from Exercise 17.5.

Hint: Implement path enumeration using depth-first search on the undirected skeleton of the DAG.


Exercise 17.7 (**)

The Bayes-Ball algorithm (Shachter, 1998) provides an efficient algorithm for d-separation that avoids explicit path enumeration. Research the algorithm and implement it in Python. Compare its computational complexity to the path-enumeration approach from Exercise 17.6 on a DAG with 20 nodes and 40 edges.


Backdoor Criterion

Exercise 17.8 (**)

For the following DAG, find all minimal valid adjustment sets for the causal effect of $X$ on $Y$ (a minimal set is one where removing any variable would make it invalid):

Z1 --> X --> Y
Z1 --> Z2 --> Y
Z3 --> X
Z3 --> Z2

(a) List all backdoor paths from $X$ to $Y$.

(b) Find all minimal valid adjustment sets.

(c) Is $\{Z1, Z3\}$ a valid adjustment set? Is it minimal?

(d) Is $\{Z2\}$ a valid adjustment set? Why or why not?


Exercise 17.9 (**)

Consider the MediCore DAG from the chapter. A junior analyst proposes the following adjustment sets. For each, determine whether it is valid for estimating the total effect of Drug X on Hospitalization. If invalid, explain the specific graph-theoretic reason.

(a) $\{$Severity$\}$

(b) $\{$Severity, Biomarker$\}$

(c) $\{$Severity, Age, Insurance Status$\}$

(d) $\{$Age, Comorbidities$\}$

(e) $\{$Severity, Age, Comorbidities, Insurance Status$\}$


Exercise 17.10 (**)

Using the generate_medicore_linear_scm function from the chapter, empirically verify your answers to Exercise 17.9. For each proposed adjustment set:

  1. Run a regression of Hospitalization on Drug X and the adjustment covariates.
  2. Compare the Drug X coefficient to the true causal effect ($-1.0$).
  3. Report the bias for each adjustment set.

Do the empirical results match the theoretical predictions from the DAG?


Exercise 17.11 (***)

Prove that the backdoor adjustment formula:

$$P(Y \mid \text{do}(X = x)) = \sum_{\mathbf{z}} P(Y \mid X = x, \mathbf{Z} = \mathbf{z}) \, P(\mathbf{Z} = \mathbf{z})$$

follows from the truncated factorization formula:

$$P(v_1, \ldots, v_p \mid \text{do}(X = x)) = \prod_{i: V_i \neq X} P(V_i \mid \text{pa}(V_i)) \Big|_{X=x}$$

when $\mathbf{Z}$ satisfies the backdoor criterion.

Hint: Start from the truncated factorization, marginalize over all variables except $Y$ and $\mathbf{Z}$, then apply the Markov condition and the backdoor criterion conditions.


Front-Door Criterion

Exercise 17.12 (**)

Consider the following DAG where $U$ is unmeasured:

U --> X --> M --> Y
U --> Y

(a) Verify that $\{M\}$ satisfies the front-door criterion for the effect of $X$ on $Y$.

(b) Write out the front-door adjustment formula for this graph.

(c) Generate data from a linear SCM with $X = U + \varepsilon_X$, $M = 2X + \varepsilon_M$, $Y = 3M + 1.5U + \varepsilon_Y$ (all noise terms standard normal). Implement the two-step front-door estimator and verify that it recovers the true total effect of $X$ on $Y$ (which is $2 \times 3 = 6$).

(d) What happens to the front-door estimator if there is a direct path from $X$ to $Y$ that does not pass through $M$? Add an edge $X \to Y$ with coefficient 1.0 to the SCM and re-estimate. Is the front-door criterion still valid?


Exercise 17.13 (**)

The smoking-tar-cancer example is one of the most famous applications of the front-door criterion (Pearl, 2009). Consider:

  Genotype (U, unmeasured)
      /           \
     v             v
  Smoking --> Tar --> Cancer

Smoking causes tar deposits, which cause cancer. An unmeasured genetic factor confounds smoking and cancer. The front-door criterion identifies the causal effect of smoking on cancer through the mediator tar.

(a) Verify the three conditions of the front-door criterion.

(b) Explain why this example was historically important for the debate about whether smoking causes cancer.

(c) Identify a real-world scenario where the front-door criterion might apply. State the treatment, mediator, outcome, and unmeasured confounder. Critically evaluate whether the three conditions are plausible.


do-Calculus and Interventions

Exercise 17.14 (**)

For the DAG $Z \to X \to Y$ with $Z \to Y$:

(a) Write $P(Y \mid \text{do}(X = x))$ in terms of observational distributions using the backdoor adjustment formula.

(b) Verify that $P(Y \mid \text{do}(X = x)) \neq P(Y \mid X = x)$ by generating data from the linear SCM $Z = \varepsilon_Z$, $X = 2Z + \varepsilon_X$, $Y = X + 3Z + \varepsilon_Y$ and computing both quantities for $x = 1$.

(c) Compute $P(Y \mid \text{do}(X = x), Z = z)$. How does it differ from $P(Y \mid \text{do}(X = x))$?


Exercise 17.15 (**)

Consider the instrument-like DAG:

Z --> X --> Y
U --> X
U --> Y

where $U$ is unmeasured.

(a) Is the backdoor criterion satisfiable? Why or why not?

(b) Is the front-door criterion satisfiable? Why or why not?

(c) Under what additional assumption about $Z$ can the causal effect of $X$ on $Y$ be identified? (This foreshadows instrumental variables in Chapter 18.)


Exercise 17.16 (***)

Implement a Python function that takes a DAG and a treatment-outcome pair, and automatically finds all valid adjustment sets using the backdoor criterion:

def find_all_valid_adjustment_sets(
    dag: dict[str, list[str]],
    treatment: str,
    outcome: str,
) -> list[set[str]]:
    """Find all valid adjustment sets satisfying the backdoor criterion.

    Args:
        dag: Dictionary mapping each node to its children.
        treatment: Treatment variable name.
        outcome: Outcome variable name.

    Returns:
        List of sets, each a valid adjustment set.
    """
    pass  # Your implementation here

Test on the MediCore DAG. How many valid adjustment sets exist?


Good Controls vs. Bad Controls

Exercise 17.17 (**)

For each of the following scenarios, determine whether the proposed control variable is a good control, a bad control, or neutral. Draw the relevant portion of the DAG to justify your answer.

(a) Estimating the effect of a job training program on earnings. Proposed control: post-training job performance reviews.

(b) Estimating the effect of smoking on lung cancer. Proposed control: chest X-ray results (showing lung spots).

(c) Estimating the effect of a new drug on blood pressure. Proposed control: patient's zip code (which is associated with socioeconomic status, diet, and access to healthcare).

(d) Estimating the effect of a StreamRec recommendation on engagement. Proposed control: the user's "For You" page layout (which is determined by the recommendation algorithm).

(e) Estimating the effect of a college degree on lifetime earnings. Proposed control: the student's pre-college SAT score.


Exercise 17.18 (***)

Cinelli, Forney, and Pearl (2022) describe 18 graph structures that cover the major cases of good and bad controls. Reproduce their classification for the following six structures and verify each empirically using simulated data with $n = 10{,}000$:

  1. $Z \to X \to Y$ (Z causes treatment only)
  2. $X \to Y \leftarrow Z$ (Z causes outcome only)
  3. $Z \to X, Z \to Y$ (classic confounder)
  4. $X \to M \to Y$ (mediator)
  5. $X \to Z \leftarrow Y$ (collider)
  6. $X \to M \to Y, Z \to M, Z \to Y$ (M-bias)

For each structure: (a) state whether conditioning on $Z$ (or $M$) helps, hurts, or is neutral; (b) generate data, estimate the causal effect with and without the control, and report the bias.


DoWhy Implementation

Exercise 17.19 (**)

Using the DoWhy library, replicate the MediCore analysis from the chapter with the following extensions:

(a) Use the propensity score weighting estimator (backdoor.propensity_score_weighting) instead of linear regression. Compare the estimate.

(b) Run the "data subset refuter" that re-estimates on a random subset of the data. Does the estimate remain stable?

(c) Run the "add unobserved common cause" refuter with effect strengths of 0.5, 1.0, and 2.0. At what confounding strength does the estimate change sign?


Exercise 17.20 (**)

Define the StreamRec causal DAG in DoWhy. Specify user_preference as an unobserved confounder. Use DoWhy to:

(a) Identify the estimand. Does DoWhy flag unidentifiability due to the unobserved confounder?

(b) Estimate the effect using both the backdoor and front-door estimands (if a suitable mediator exists). Compare the results.

(c) Discuss the practical implications of having an unobserved confounder in the StreamRec setting. What additional data could StreamRec collect to move user preference from unobserved to observed?


Structural Causal Models

Exercise 17.21 (***)

Consider a nonlinear SCM:

$$Z = U_Z, \quad X = Z^2 + U_X, \quad Y = \sin(X) + 2Z + U_Y$$

where $U_Z, U_X, U_Y \sim \mathcal{N}(0, 1)$ independently.

(a) Draw the causal DAG. What is $Z$ with respect to $X$ and $Y$?

(b) Compute $\mathbb{E}[Y \mid \text{do}(X = 1)]$ analytically. (Hint: under the intervention, $X$ is fixed at 1, and $Z$ is independent of $X$.)

(c) Compute $\mathbb{E}[Y \mid X = 1]$ by simulation. Is it equal to $\mathbb{E}[Y \mid \text{do}(X = 1)]$?

(d) Estimate $\mathbb{E}[Y \mid \text{do}(X = 1)]$ from observational data using the backdoor adjustment formula with $Z$ as the adjustment variable. Compare with the analytical result.


Exercise 17.22 (***)

In the linear Gaussian case, the causal effect of $X$ on $Y$ (controlling for $\mathbf{Z}$ using the backdoor criterion) can be read directly from the regression coefficient. Show that in the nonlinear case, the regression coefficient is generally not equal to the average causal effect $\mathbb{E}[Y \mid \text{do}(X = x+1)] - \mathbb{E}[Y \mid \text{do}(X = x)]$. Provide a concrete numerical example using the SCM from Exercise 17.21.


Connections to Potential Outcomes

Exercise 17.23 (**)

Show that the backdoor criterion in the graphical framework corresponds to the conditional ignorability assumption in the potential outcomes framework. Specifically, prove that if $\mathbf{Z}$ satisfies the backdoor criterion for $(X, Y)$ in DAG $\mathcal{G}$, and the causal Markov condition and faithfulness hold, then:

$$\{Y(0), Y(1)\} \perp\!\!\!\perp X \mid \mathbf{Z}$$

This is the bridge between Pearl's and Rubin's frameworks.


Exercise 17.24 (***)

The potential outcomes framework defines the ATE as $\mathbb{E}[Y(1) - Y(0)]$. The graphical framework defines it as $\mathbb{E}[Y \mid \text{do}(X=1)] - \mathbb{E}[Y \mid \text{do}(X=0)]$.

(a) Show that these two definitions are equivalent under the consistency assumption ($Y = Y(X)$ when $X$ is observed) and SUTVA.

(b) In a DAG with $X \to M \to Y$ (complete mediation), what is $\mathbb{E}[Y \mid \text{do}(X = 1)] - \mathbb{E}[Y \mid \text{do}(X = 0)]$ in terms of the structural equation parameters?

(c) What is the natural direct effect (NDE) and natural indirect effect (NIE) in this graph? How do they relate to the total effect?


Advanced and Research-Level Problems

Exercise 17.25 (***)

Implement a Monte Carlo simulation to test the completeness of d-separation. Generate 1000 random DAGs with 8 nodes and 12 edges. For each DAG:

  1. Enumerate all conditional independence relations implied by d-separation.
  2. Generate data from a random linear Gaussian SCM consistent with the DAG.
  3. Test each implied independence using partial correlation tests.
  4. Report the fraction of implied independencies that hold in the data (at the $\alpha = 0.05$ level).

What fraction of implied independencies are confirmed by the data? Discuss cases where they are not, and relate to the faithfulness assumption.


Exercise 17.26 (****)

Causal Discovery. The chapter assumes the DAG is given. In practice, it must often be learned from data. Research the PC algorithm (Spirtes, Glymour, and Scheines, 1993) and implement it:

  1. Start with a complete undirected graph.
  2. Remove edges using conditional independence tests.
  3. Orient edges using v-structures (colliders) and propagation rules.

Apply your implementation to data generated from the MediCore SCM. Does the algorithm recover the true graph? Under what conditions does it fail?


Exercise 17.27 (****)

Transportability. Pearl and Bareinboim (2011) define the transportability problem: given a causal effect estimated in one population, under what conditions can it be transported to a new population? Consider a drug trial conducted in population $\Pi^*$ (European patients) and a target population $\Pi$ (Asian patients). The DAG is the same in both populations, but the distribution of covariates (e.g., genetic markers) differs.

(a) Formally define the transportability problem in terms of do-calculus.

(b) Under what graphical conditions is the causal effect transportable without any additional data from $\Pi$?

(c) Under what conditions is the causal effect transportable given observational data from $\Pi$ (but no experimental data from $\Pi$)?

(d) Discuss the relevance of transportability to MediCore's problem of generalizing from the RCT population (Chapter 16, Case Study 1) to the real-world population.


Exercise 17.28 (****)

Causal Bayesian Networks vs. Bayesian Networks. A Bayesian network is a DAG with a joint distribution that factorizes according to the Markov condition. A causal Bayesian network (CBN) adds the interpretation that each edge represents a direct causal effect. The same graph can be a valid Bayesian network for a given distribution under multiple edge orientations (Markov equivalence).

(a) Explain the Markov equivalence class. How many DAGs are in the same Markov equivalence class as the graph $A \to B \to C$?

(b) Show that the DAGs $A \to B \to C$, $A \leftarrow B \leftarrow C$, and $A \leftarrow B \to C$ encode the same set of conditional independencies (and are therefore Markov equivalent).

(c) Show that $A \to B \leftarrow C$ is not Markov equivalent to the three DAGs in (b). What distinguishes it?

(d) Explain why Markov equivalence is a fundamental limitation for causal discovery from purely observational data. What additional information (beyond conditional independence tests) is needed to distinguish between Markov-equivalent DAGs?