SCM.Examples

Worked structural-causal-model examples (instrumental variables and related DAGs) exercising the SCM and identification layers.

Back­Door 8 core · 4 supporting This file constructs the canonical directed acyclic graph for backdoor adjustment, with a treatment, an outcome, an observed confounder, and latent root noise variables. ★ bdTopo_lt

Backdoor Adjustment Example

This file constructs the canonical directed acyclic graph for backdoor adjustment, with a treatment, an outcome, an observed confounder, and latent root noise variables. The declarations BDNode, bdEdge, bdDAG, and bdSWIG define the graph and its standard SWIG representation. The examples check parents, roots, c-components, ID reachability, and the split-graph d-separation condition behind the graphical backdoor criterion; the final backdoor-criterion example verifies that the observed confounder is a valid adjustment set for the treatment-outcome effect.

inductive BDNode reviewed
Causalean.SCM.Examples.BackDoor

The backdoor-example node type consists of the treatment vertex, the outcome vertex, the observed-confounder vertex, the latent root for the confounder, the latent root for treatment, and the latent root for the outcome.

Definition (Lean source)
BDNode :
Type
bdD :
bdY :
bdZ :
bdU1 :
bdU2 :
bdU3 :
deriving DecidableEq
Causalean.SCM.Examples.BackDoor.BDNode · Causalean/SCM/Examples/BackDoor.lean:70
def repr reviewed
Causalean.SCM.Examples.BackDoor.instReprBDNode

For each vertex of the backdoor-adjustment DAG and each natural-number precedence level, this method returns a formatted textual rendering of that vertex. There are no additional hypotheses or side conditions.

Definition (Lean source)
repr :
BDNodeNatFormat
clause 1
| bdD, _ => "Causalean.SCM.Examples.BackDoor.BDNode.bdD"
clause 2
| bdY, _ => "Causalean.SCM.Examples.BackDoor.BDNode.bdY"
clause 3
| bdZ, _ => "Causalean.SCM.Examples.BackDoor.BDNode.bdZ"
clause 4
| bdU1, _ => "Causalean.SCM.Examples.BackDoor.BDNode.bdU1"
clause 5
| bdU2, _ => "Causalean.SCM.Examples.BackDoor.BDNode.bdU2"
clause 6
| bdU3, _ => "Causalean.SCM.Examples.BackDoor.BDNode.bdU3"
Causalean.SCM.Examples.BackDoor.instReprBDNode.repr · Causalean/SCM/Examples/BackDoor.lean:84 · uses BDNode
def bdEdge reviewed
Causalean.SCM.Examples.BackDoor

The backdoor-edge relation contains exactly the arrow from the observed confounder to treatment, the arrow from the observed confounder to outcome, the arrow from treatment to outcome, the arrow from the first latent root to the confounder, the arrow from the second latent root to treatment, and the arrow from the third latent root to outcome; all other ordered pairs have no edge.

Definition (Lean source)
bdEdge :
BDNodeBDNode → Prop
clause 1
| bdZ, bdD => True
clause 2
| bdZ, bdY => True
clause 3
| bdD, bdY => True
clause 4
| bdU1, bdZ => True
clause 5
| bdU2, bdD => True
clause 6
| bdU3, bdY => True
clause 7
| _, _ => False
Causalean.SCM.Examples.BackDoor.bdEdge · Causalean/SCM/Examples/BackDoor.lean:114 · uses BDNode
def bdTopo reviewed
Causalean.SCM.Examples.BackDoor

The topological-order label for the backdoor graph assigns label 0 to the first latent root, label 1 to the second latent root, label 2 to the third latent root, label 3 to the observed confounder, label 4 to treatment, and label 5 to outcome.

Definition (Lean source)
bdTopo :
BDNode → ℕ
clause 1
| bdU1 => 0
clause 2
| bdU2 => 1
clause 3
| bdU3 => 2
clause 4
| bdZ => 3
clause 5
| bdD => 4
clause 6
| bdY => 5
Causalean.SCM.Examples.BackDoor.bdTopo · Causalean/SCM/Examples/BackDoor.lean:132 · uses BDNode
theorem bdTopo_lt reviewed
Causalean.SCM.Examples.BackDoor

Every edge of the backdoor-example graph connects a node with a strictly smaller assigned order label to one with a strictly larger label — the chosen ordering is a valid topological order for the graph.

Formal statement
u :
shared
v :
shared
u v :
bdEdge u v
Proof (Lean source)
theorem bdTopo_lt : ∀ u v, bdEdge u v → bdTopo u < bdTopo v := by intro u v h; cases u <;> cases v <;> simp_all [bdEdge, bdTopo]
Causalean.SCM.Examples.BackDoor.bdTopo_lt · Causalean/SCM/Examples/BackDoor.lean:141 · uses BDNode , bdEdge , bdTopo
def bdDAG reviewed
Causalean.SCM.Examples.BackDoor

The backdoor-adjustment directed acyclic graph has the specified backdoor edge relation and the displayed topological ordering, and is therefore acyclic.

Definition (Lean source)
bdDAG :
clause 1
clause 2
decEdge := inferInstance
clause 3
acyclic := DAG.acyclic_of_topoOrder bdTopo_lt
def bdSWIG reviewed
Causalean.SCM.Examples.BackDoor

The pre-intervention SWIG graph for the backdoor example has the backdoor directed acyclic graph, no fixed nodes, treatment, outcome, and confounder as observed random nodes, and the three latent roots as unobserved random nodes.

Definition (Lean source)
bdSWIG :
clause 1
clause 2
fixed := ∅
clause 3
observed := {SWIGNode.random bdD, SWIGNode.random bdY, SWIGNode.random bdZ}
clause 4
unobserved := {SWIGNode.random bdU1, SWIGNode.random bdU2, SWIGNode.random bdU3}
clause 5
fixed_is_fixed := by intro s hs; simp at hs
clause 6
observed_is_random := by intro v hv; simp at hv rcases hv with rfl | rfl | rfl <;> exact ⟨_, rfl⟩
clause 7
unobserved_is_random := by intro u hu; simp at hu rcases hu with rfl | rfl | rfl <;> exact ⟨_, rfl⟩
clause 8
obs_unobs_disjoint := by decide
clause 9
dag_edges_classified := by decide
clause 10
fixed_image_in_observed := by intro s hs; simp at hs
clause 11
fixed_are_roots := by intro s hs; simp at hs
clause 12
unobs_are_roots := by intro u hu; simp at hu rcases hu with rfl | rfl | rfl · simpa [initialSWIG] using swig_random_root_of_root bdDAG ∅ bdU1 (by decide : bdDAG.parents bdU1 = ∅) · simpa [initialSWIG] using swig_random_root_of_root bdDAG ∅ bdU2 (by decide : bdDAG.parents bdU2 = ∅) · simpa [initialSWIG] using swig_random_root_of_root bdDAG ∅ bdU3 (by decide : bdDAG.parents bdU3 = ∅)
clause 13
fixed_outside_fixed_isolated := by intro n _ cases n <;> exact ⟨by decide, by decide⟩
clause 14
all_children_in_observed := by decide
def bdEdgeTypes reviewed
Causalean.SCM.Examples.BackDoor

The edge-type assignment for the backdoor graph classifies every graph edge as nonparametric.

Definition (Lean source)
bdEdgeTypes :
EdgeTypeAssignment.allNonparametric bdDAG
4 supporting declarations (lemmas, instances)
  • instDecidableEqBDNode instance
    deriving DecidableEq
    Causalean.SCM.Examples.BackDoor.instDecidableEqBDNode · Causalean/SCM/Examples/BackDoor.lean:78
  • instReprBDNode instance — A textual representation structure for backdoor-example vertices is provided by rendering each vertex through its fully qualified constructor name.
    instReprBDNode :
    reprPrec := instReprBDNode.repr
    Causalean.SCM.Examples.BackDoor.instReprBDNode · Causalean/SCM/Examples/BackDoor.lean:101
  • instFintypeBDNode instance — A finite enumeration of the backdoor-example node type is provided by the collection of its six named vertices together with the assertion that every backdoor-example vertex belongs to that collection.
    instFintypeBDNode :
    clause 1
    elems := {bdD, bdY, bdZ, bdU1, bdU2, bdU3}
    clause 2
    complete := by intro x; cases x <;> simp
    Causalean.SCM.Examples.BackDoor.instFintypeBDNode · Causalean/SCM/Examples/BackDoor.lean:105
  • instDecidableRelBDNodeBdEdge instance — For every ordered pair of backdoor-example vertices, a decision procedure for whether the pair is a directed edge is provided.
    instDecidableRelBDNodeBdEdge :
    by intro a b; cases a <;> cases b <;> simp [bdEdge] <;> infer_instance
    Causalean.SCM.Examples.BackDoor.instDecidableRelBDNodeBdEdge · Causalean/SCM/Examples/BackDoor.lean:124
Continuous­Backdoor 13 core · 10 supporting This file gives a real-valued backdoor example in which the confounder, treatment, and outcome all take values in ℝ. ★ cb_backdoor_criterion★ cb_backdoor_identified

Real-Valued Backdoor Example

This file gives a real-valued backdoor example in which the confounder, treatment, and outcome all take values in . The declarations CBNode, CBΩ, cbDAG, cbSWIGGraph, and continuousBackdoorSCM build a degenerate constant structural model whose purpose is to exercise the real-valued graph and kernel interfaces. The theorem cb_backdoor_criterion verifies the graphical backdoor criterion by computation, and cb_backdoor_identified applies the kernel-based backdoor pipeline once the required overlap and positivity conditions are supplied as hypotheses.

abbrev CBNode reviewed
Causalean.SCM.Examples.ContinuousBackdoor

The node set of the continuous-backdoor example consists of three positions representing, in order, the confounder, treatment, and outcome.

Definition (Lean source)
CBNode :
Type
Fin 3
Causalean.SCM.Examples.ContinuousBackdoor.CBNode · Causalean/SCM/Examples/ContinuousBackdoor.lean:78
abbrev CBΩ reviewed
Causalean.SCM.Examples.ContinuousBackdoor

The value-space assignment for the continuous-backdoor example gives every node the real-valued state space.

Definition (Lean source)
CBΩ :
CBNode → Type
fun _ => ℝ
Causalean.SCM.Examples.ContinuousBackdoor.CBΩ · Causalean/SCM/Examples/ContinuousBackdoor.lean:81 · uses CBNode
def Zidx reviewed
Causalean.SCM.Examples.ContinuousBackdoor

The confounder node index is the first of the three node positions in the continuous-backdoor example.

Definition (Lean source)
Zidx :
0
Causalean.SCM.Examples.ContinuousBackdoor.Zidx · Causalean/SCM/Examples/ContinuousBackdoor.lean:84 · uses CBNode
def Xidx reviewed
Causalean.SCM.Examples.ContinuousBackdoor

The treatment node index is the second of the three node positions in the continuous-backdoor example.

Definition (Lean source)
Xidx :
1
Causalean.SCM.Examples.ContinuousBackdoor.Xidx · Causalean/SCM/Examples/ContinuousBackdoor.lean:86 · uses CBNode
def Yidx reviewed
Causalean.SCM.Examples.ContinuousBackdoor

The outcome node index is the third of the three node positions in the continuous-backdoor example.

Definition (Lean source)
Yidx :
2
Causalean.SCM.Examples.ContinuousBackdoor.Yidx · Causalean/SCM/Examples/ContinuousBackdoor.lean:88 · uses CBNode
def cbEdgeBool reviewed
Causalean.SCM.Examples.ContinuousBackdoor

The Boolean edge indicator is true exactly for an arrow from confounder to treatment, from confounder to outcome, or from treatment to outcome.

Definition (Lean source)
cbEdgeBool :
fun a b
=> (a.val == 0 && b.val == 1) || (a.val == 0 && b.val == 2) || (a.val == 1 && b.val == 2)
Causalean.SCM.Examples.ContinuousBackdoor.cbEdgeBool · Causalean/SCM/Examples/ContinuousBackdoor.lean:95 · uses CBNode
def cbEdge reviewed
Causalean.SCM.Examples.ContinuousBackdoor

The edge relation of the continuous-backdoor graph holds exactly when the Boolean edge indicator is true, namely for arrows from confounder to treatment or outcome and from treatment to outcome.

Definition (Lean source)
cbEdge :
CBNodeCBNode → Prop
fun a b => cbEdgeBool a b = true
Causalean.SCM.Examples.ContinuousBackdoor.cbEdge · Causalean/SCM/Examples/ContinuousBackdoor.lean:102 · uses CBNode
def cbTopo reviewed
Causalean.SCM.Examples.ContinuousBackdoor

The topological-order label of the continuous-backdoor graph is each node's position, so it places the confounder before treatment and treatment before outcome.

Definition (Lean source)
cbTopo :
CBNode → ℕ
fun n => n.val
Causalean.SCM.Examples.ContinuousBackdoor.cbTopo · Causalean/SCM/Examples/ContinuousBackdoor.lean:109 · uses CBNode
def cbDAG reviewed
Causalean.SCM.Examples.ContinuousBackdoor

The directed acyclic graph of the continuous backdoor example has the stated three-node edge relation and topological ordering, and is acyclic.

Definition (Lean source)
cbDAG :
clause 1
clause 2
decEdge := inferInstance
clause 3
acyclic := DAG.acyclic_of_topoOrder cbTopo_lt
Causalean.SCM.Examples.ContinuousBackdoor.cbDAG · Causalean/SCM/Examples/ContinuousBackdoor.lean:117 · uses DAG , CBNode
def cbSWIGGraph reviewed
Causalean.SCM.Examples.ContinuousBackdoor

The pre-intervention SWIG graph for the continuous-backdoor example has no fixed or unobserved nodes and has the confounder, treatment, and outcome as observed random nodes.

Definition (Lean source)
cbSWIGGraph :
clause 1
clause 2
fixed := ∅
clause 3
observed := {SWIGNode.random Zidx, SWIGNode.random Xidx, SWIGNode.random Yidx}
clause 4
unobserved := ∅
clause 5
fixed_is_fixed := by intro s hs; simp at hs
clause 6
observed_is_random := by intro v hv; simp at hv rcases hv with rfl | rfl | rfl <;> exact ⟨_, rfl⟩
clause 7
unobserved_is_random := by intro u hu; simp at hu
clause 8
obs_unobs_disjoint := by rw [Finset.disjoint_right]; intro x hx; simp at hx
clause 9
dag_edges_classified := by decide
clause 10
fixed_image_in_observed := by intro s hs; simp at hs
clause 11
fixed_are_roots := by intro s hs; simp at hs
clause 12
unobs_are_roots := by intro u hu; simp at hu
clause 13
fixed_outside_fixed_isolated := by intro n _ refine ⟨?_, ?_⟩ · revert n; decide · revert n; decide
clause 14
all_children_in_observed := by decide
Causalean.SCM.Examples.ContinuousBackdoor.cbSWIGGraph · Causalean/SCM/Examples/ContinuousBackdoor.lean:127 · uses CBNode , SWIGGraph
def continuousBackdoorSCM reviewed
Causalean.SCM.Examples.ContinuousBackdoor

The continuous-backdoor structural causal model has the specified real-valued pre-intervention graph, no latent variables, nonparametric edges, and constant-zero structural responses for every observed node.

Definition (Lean source)
continuousBackdoorSCM :
clause 1
toSWIGGraph := cbSWIGGraph
clause 2
edgeTypes := EdgeTypeAssignment.allNonparametric cbSWIGGraph.dag
clause 3
iota_valueSpace := by intro s exact (notMem_empty s.val s.property).elim
clause 4
structFun := fun v => by rcases v with ⟨n, _⟩ cases n <;> exact fun _ => (0 : ℝ)
clause 5
structFun_measurable := by intro v rcases v with ⟨n, _⟩ cases n <;> exact measurable_const
clause 6
latentDist := fun u => (notMem_empty u.val u.property).elim
clause 7
isProbability_latent := by intro u exact (notMem_empty u.val u.property).elim
Causalean.SCM.Examples.ContinuousBackdoor.continuousBackdoorSCM · Causalean/SCM/Examples/ContinuousBackdoor.lean:158 · uses SCM , CBNode , CBΩ
theorem cb_backdoor_criterion reviewed
Causalean.SCM.Examples.ContinuousBackdoor

The observed confounder satisfies the graphical backdoor criterion relative to the treatment and outcome nodes in the continuous-backdoor example graph.

Formal statement
cbSWIGGraph.backdoorCriterion ({Xidx} : Finset CBNode) cb_Xrand_obs cb_Xfixed {SWIGNode.random Yidx} {SWIGNode.random Zidx}
Proof (Lean source)
theorem cb_backdoor_criterion : cbSWIGGraph.backdoorCriterion ({Xidx} : Finset CBNode) cb_Xrand_obs cb_Xfixed {SWIGNode.random Yidx} {SWIGNode.random Zidx} := by refine ⟨?_, ?_, ?_, ?_, ?_⟩ · -- Guard: `{random Z}` is observed. intro z hz rw [mem_singleton] at hz subst hz change SWIGNode.random Zidx ∈ ({SWIGNode.random Zidx, SWIGNode.random Xidx, SWIGNode.random Yidx} : Finset (SWIGNode CBNode)) simp · -- Guard: `{random Z}` is disjoint from `{random Y}`. decide · -- Guard: `{random Z}` is disjoint from `{random X}`. decide · -- Condition (i): no element of `{random Z}` is a descendant of `random X`. intro z hz D hD rw [mem_singleton] at hz hD subst hz; subst hD -- Goal: ¬ (initialSWIG cbDAG).isAncestor (.random X) (.random Z). -- The only edges from `random X` go to `random Y`; `Z` is not reachable. decide · -- Condition (ii): `{random Z} ∪ {fixed X}` d-separates `{random Y}` from -- `{random X}` in the splitMono graph. Discharged via `splitMonoDAG` -- (computable) + `decide`, mirroring `SCM/Examples/BackDoor.lean`. exact (by decide : (cbSWIGGraph.splitMonoDAG ({Xidx} : Finset CBNode)).dSep {SWIGNode.random Yidx} (image SWIGNode.random ({Xidx} : Finset CBNode)) ({SWIGNode.random Zidx} ∪ image SWIGNode.fixed ({Xidx} : Finset CBNode)))
theorem cb_backdoor_identified reviewed
Causalean.SCM.Examples.ContinuousBackdoor

Backdoor adjustment identity on the continuous-backdoor example. Fix an assignment s0 of values to the model's fixed background variables. If for every post-intervention background assignment, the do(X)-intervened marginal law of Z is absolutely continuous with respect to its purely observational marginal law — the Rule-2 joint overlap condition, and the product of the observational marginal laws of the treatment's random image and of Z is absolutely continuous with respect to their joint observational law — the joint positivity condition, then almost everywhere under that product measure, the conditional law of the outcome Y given Z under the intervention that fixes the treatment equals the purely observational conditional law of Y given both the treatment and Z — the backdoor Rule-2 adjustment identity.

Formal statement
s0 :
continuousBackdoorSCM.FixedValues
hOverlap :
hPositivity_ae :
(((continuousBackdoorSCM.obsKernel s0).map (valuesProjection cb_Xr_obs) ⊗ₘ const _ ((continuousBackdoorSCM.obsKernel s0).map (valuesProjection cb_Zobs))).map (fun p => valuesUnionMk p.1 p.2)) ≪ ((continuousBackdoorSCM.obsKernel s0).map (valuesProjection cb_XrZ_obs))
∀ᵐ p ∂((continuousBackdoorSCM.obsKernel s0).map (valuesProjection cb_Xr_obs) ⊗ₘ const _ ((continuousBackdoorSCM.obsKernel s0).map (valuesProjection cb_Zobs))), (continuousBackdoorSCM.fixSet ({Xidx} : Finset CBNode) cb_Xrand_obs cb_Xfixed).obsCondKernel {SWIGNode.random Yidx} {SWIGNode.random Zidx} ((SCM.fixSet_observed continuousBackdoorSCM ({Xidx} : Finset CBNode) cb_Xrand_obs cb_Xfixed).symm ▸ cb_Yobs) ((SCM.fixSet_observed continuousBackdoorSCM ({Xidx} : Finset CBNode) cb_Xrand_obs cb_Xfixed).symm ▸ cb_Zobs) (continuousBackdoorSCM.fixSetExtend ({Xidx} : Finset CBNode) cb_Xrand_obs cb_Xfixed s0 p.1, p.2)
= continuousBackdoorSCM.obsCondKernel {SWIGNode.random Yidx} (({Xidx} : Finset CBNode).image SWIGNode.random ∪ {SWIGNode.random Zidx}) cb_Yobs cb_XrZ_obs (s0, valuesUnionMk p.1 p.2)
Proof (Lean source)
theorem cb_backdoor_identified (s0 : continuousBackdoorSCM.FixedValues) (hOverlap : ∀ s : (continuousBackdoorSCM.fixSet ({Xidx} : Finset CBNode) cb_Xrand_obs cb_Xfixed).FixedValues, Rule2JointOverlap continuousBackdoorSCM ({Xidx} : Finset CBNode) cb_Xrand_obs cb_Xfixed {SWIGNode.random Zidx} cb_XrZ_obs s) (hPositivity_ae : (((continuousBackdoorSCM.obsKernel s0).map (valuesProjection cb_Xr_obs) ⊗ₘ const _ ((continuousBackdoorSCM.obsKernel s0).map (valuesProjection cb_Zobs))).map (fun p => valuesUnionMk p.1 p.2)) ≪ ((continuousBackdoorSCM.obsKernel s0).map (valuesProjection cb_XrZ_obs))) : ∀ᵐ p ∂((continuousBackdoorSCM.obsKernel s0).map (valuesProjection cb_Xr_obs) ⊗ₘ const _ ((continuousBackdoorSCM.obsKernel s0).map (valuesProjection cb_Zobs))), (continuousBackdoorSCM.fixSet ({Xidx} : Finset CBNode) cb_Xrand_obs cb_Xfixed).obsCondKernel {SWIGNode.random Yidx} {SWIGNode.random Zidx} ((SCM.fixSet_observed continuousBackdoorSCM ({Xidx} : Finset CBNode) cb_Xrand_obs cb_Xfixed).symm ▸ cb_Yobs) ((SCM.fixSet_observed continuousBackdoorSCM ({Xidx} : Finset CBNode) cb_Xrand_obs cb_Xfixed).symm ▸ cb_Zobs) (continuousBackdoorSCM.fixSetExtend ({Xidx} : Finset CBNode) cb_Xrand_obs cb_Xfixed s0 p.1, p.2) = continuousBackdoorSCM.obsCondKernel {SWIGNode.random Yidx} (({Xidx} : Finset CBNode).image SWIGNode.random ∪ {SWIGNode.random Zidx}) cb_Yobs cb_XrZ_obs (s0, valuesUnionMk p.1 p.2) := SCM.backdoor_rule2_ae continuousBackdoorSCM ({Xidx} : Finset CBNode) cb_Xrand_obs cb_Xfixed {SWIGNode.random Yidx} {SWIGNode.random Zidx} cb_Yobs cb_Zobs cb_Xr_obs cb_XrZ_obs cb_disj_YXr cb_disj_XrZ cb_backdoor_criterion s0 hOverlap hPositivity_ae
10 supporting declarations (lemmas, instances)
Frontdoor 6 core · 4 supporting This file constructs the canonical frontdoor graph with one latent confounder between treatment and outcome, an observed mediator, and no intervention fixed at the initial graph. ★ fdTopo_lt

Frontdoor Example

This file constructs the canonical frontdoor graph with one latent confounder between treatment and outcome, an observed mediator, and no intervention fixed at the initial graph. The declarations FDNode, fdEdge, fdDAG, and fdSWIG define the graph and standard SWIG representation. The examples verify the c-components, show that the recursive ID certificate idSucceedsRec succeeds for P(Y | do(X)), show that the simpler no-fixing reachability certificate does not apply to the same outcome district, and check that the executable idAlgorithm returns true on the concrete graph.

inductive FDNode reviewed
Causalean.SCM.Examples.Frontdoor

The frontdoor-example node type consists of the latent-confounder vertex, the treatment vertex, the mediator vertex, and the outcome vertex.

Definition (Lean source)
FDNode :
Type
fdU :
fdX :
fdM :
fdY :
deriving DecidableEq, Repr
Causalean.SCM.Examples.Frontdoor.FDNode · Causalean/SCM/Examples/Frontdoor.lean:34
def fdEdge reviewed
Causalean.SCM.Examples.Frontdoor

The frontdoor-edge relation contains exactly the arrow from the latent confounder to treatment, the arrow from the latent confounder to outcome, the arrow from treatment to the mediator, and the arrow from the mediator to outcome; all other ordered pairs have no edge.

Definition (Lean source)
fdEdge :
FDNodeFDNode → Prop
clause 1
| fdU, fdX => True
clause 2
| fdU, fdY => True
clause 3
| fdX, fdM => True
clause 4
| fdM, fdY => True
clause 5
| _, _ => False
Causalean.SCM.Examples.Frontdoor.fdEdge · Causalean/SCM/Examples/Frontdoor.lean:53 · uses FDNode
def fdTopo reviewed
Causalean.SCM.Examples.Frontdoor

The topological-order label for the frontdoor graph assigns label 0 to the latent confounder, label 1 to treatment, label 2 to the mediator, and label 3 to outcome.

Definition (Lean source)
fdTopo :
FDNode → ℕ
clause 1
| fdU => 0
clause 2
| fdX => 1
clause 3
| fdM => 2
clause 4
| fdY => 3
Causalean.SCM.Examples.Frontdoor.fdTopo · Causalean/SCM/Examples/Frontdoor.lean:69 · uses FDNode
theorem fdTopo_lt reviewed
Causalean.SCM.Examples.Frontdoor

Every edge of the frontdoor-example graph connects a node with a smaller assigned order label to one with a larger label, so the chosen ordering is a valid topological order.

Formal statement
u :
shared
v :
shared
u v :
fdEdge u v
Proof (Lean source)
theorem fdTopo_lt : ∀ u v, fdEdge u v → fdTopo u < fdTopo v := by intro u v h; cases u <;> cases v <;> simp_all [fdEdge, fdTopo]
Causalean.SCM.Examples.Frontdoor.fdTopo_lt · Causalean/SCM/Examples/Frontdoor.lean:76 · uses FDNode , fdEdge , fdTopo
def fdDAG reviewed
Causalean.SCM.Examples.Frontdoor

The frontdoor directed acyclic graph has the specified frontdoor edge relation and topological ordering, and is acyclic.

Definition (Lean source)
fdDAG :
clause 1
clause 2
decEdge := inferInstance
clause 3
acyclic := DAG.acyclic_of_topoOrder fdTopo_lt
def fdSWIG reviewed
Causalean.SCM.Examples.Frontdoor

The pre-intervention SWIG graph for the frontdoor example has the frontdoor directed acyclic graph, no fixed nodes, treatment, mediator, and outcome as observed random nodes, and the latent confounder as an unobserved random node.

Definition (Lean source)
fdSWIG :
clause 1
clause 2
fixed := ∅
clause 3
observed := {SWIGNode.random fdX, SWIGNode.random fdM, SWIGNode.random fdY}
clause 4
unobserved := {SWIGNode.random fdU}
clause 5
fixed_is_fixed := by intro s hs; simp at hs
clause 6
observed_is_random := by intro v hv; simp at hv rcases hv with rfl | rfl | rfl <;> exact ⟨_, rfl⟩
clause 7
unobserved_is_random := by intro u hu; simp at hu subst hu exact ⟨_, rfl⟩
clause 8
obs_unobs_disjoint := by decide
clause 9
dag_edges_classified := by decide
clause 10
fixed_image_in_observed := by intro s hs; simp at hs
clause 11
fixed_are_roots := by intro s hs; simp at hs
clause 12
unobs_are_roots := by intro u hu; simp at hu subst hu simpa [initialSWIG] using swig_random_root_of_root fdDAG ∅ fdU (by decide : fdDAG.parents fdU = ∅)
clause 13
fixed_outside_fixed_isolated := by intro n _ cases n <;> exact ⟨by decide, by decide⟩
clause 14
all_children_in_observed := by decide
4 supporting declarations (lemmas, instances)
  • instDecidableEqFDNode instance
    deriving DecidableEq, Repr
    Causalean.SCM.Examples.Frontdoor.instDecidableEqFDNode · Causalean/SCM/Examples/Frontdoor.lean:40
  • instReprFDNode instance
    deriving DecidableEq, Repr
    Causalean.SCM.Examples.Frontdoor.instReprFDNode · Causalean/SCM/Examples/Frontdoor.lean:40
  • instFintypeFDNode instance — A finite enumeration of the frontdoor-example node type is provided by the collection of its four named vertices together with the assertion that every frontdoor-example vertex belongs to that collection.
    instFintypeFDNode :
    clause 1
    elems := {fdU, fdX, fdM, fdY}
    clause 2
    complete := by intro x; cases x <;> simp
    Causalean.SCM.Examples.Frontdoor.instFintypeFDNode · Causalean/SCM/Examples/Frontdoor.lean:44
  • instDecidableRelFDNodeFdEdge instance — For every ordered pair of frontdoor-example vertices, a decision procedure for whether the pair is a directed edge is provided.
    instDecidableRelFDNodeFdEdge :
    by intro a b; cases a <;> cases b <;> simp [fdEdge] <;> infer_instance
    Causalean.SCM.Examples.Frontdoor.instDecidableRelFDNodeFdEdge · Causalean/SCM/Examples/Frontdoor.lean:61
IV 11 core · 5 supporting This file constructs the standard instrumental-variable graph with an instrument, a treatment, an outcome, and an unobserved confounder of the treatment-outcome relationship. ★ ivTopo_lt

Instrumental Variable Example

This file constructs the standard instrumental-variable graph with an instrument, a treatment, an outcome, and an unobserved confounder of the treatment-outcome relationship. It exercises the graphical, component, edge-type, and structural-model interfaces used by instrumental-variable examples elsewhere in the library.

inductive IVNode reviewed
Causalean.SCM.Examples.IV

For the instrumental-variable example, the set of node categories consists of an instrument, a treatment, an outcome, and an unobserved confounder.

Definition (Lean source)
IVNode :
Type
Z :
D :
Y :
U :
deriving DecidableEq
Causalean.SCM.Examples.IV.IVNode · Causalean/SCM/Examples/IV.lean:47
def repr reviewed
Causalean.SCM.Examples.IV.instReprIVNode

For each vertex of the instrumental-variable DAG and each natural-number precedence level, this method returns a formatted textual rendering of that vertex. There are no additional hypotheses or side conditions.

Definition (Lean source)
repr :
IVNodeNatFormat
clause 1
| Z, _ => "Causalean.SCM.Examples.IV.IVNode.Z"
clause 2
| D, _ => "Causalean.SCM.Examples.IV.IVNode.D"
clause 3
| Y, _ => "Causalean.SCM.Examples.IV.IVNode.Y"
clause 4
| U, _ => "Causalean.SCM.Examples.IV.IVNode.U"
Causalean.SCM.Examples.IV.instReprIVNode.repr · Causalean/SCM/Examples/IV.lean:59 · uses IVNode
def ivEdge reviewed
Causalean.SCM.Examples.IV

The instrumental-variable edge relation contains exactly the arrow from instrument to treatment, the arrow from treatment to outcome, the arrow from the latent confounder to treatment, and the arrow from the latent confounder to outcome; all other ordered pairs have no edge.

Definition (Lean source)
ivEdge :
IVNodeIVNode → Prop
clause 1
| Z, D => True
clause 2
| D, Y => True
clause 3
| U, D => True
clause 4
| U, Y => True
clause 5
| _, _ => False
Causalean.SCM.Examples.IV.ivEdge · Causalean/SCM/Examples/IV.lean:87 · uses IVNode
def ivTopo reviewed
Causalean.SCM.Examples.IV

The topological-order label for the instrumental-variable graph assigns label 0 to the latent confounder, label 1 to the instrument, label 2 to treatment, and label 3 to outcome.

Definition (Lean source)
ivTopo :
IVNode → ℕ
clause 1
| U => 0
clause 2
| Z => 1
clause 3
| D => 2
clause 4
| Y => 3
Causalean.SCM.Examples.IV.ivTopo · Causalean/SCM/Examples/IV.lean:105 · uses IVNode
theorem ivTopo_lt reviewed
Causalean.SCM.Examples.IV

Every edge of the instrumental-variable example graph connects a node with a smaller assigned order label to one with a larger label, so the chosen ordering is a valid topological order.

Formal statement
u :
shared
v :
shared
u v :
ivEdge u v
Proof (Lean source)
theorem ivTopo_lt : ∀ u v, ivEdge u v → ivTopo u < ivTopo v := by intro u v h; cases u <;> cases v <;> simp_all [ivEdge, ivTopo]
Causalean.SCM.Examples.IV.ivTopo_lt · Causalean/SCM/Examples/IV.lean:112 · uses IVNode , ivEdge , ivTopo
def ivDAG reviewed
Causalean.SCM.Examples.IV

The instrumental-variable directed acyclic graph has the stated instrumental-variable edge relation and topological ordering, and is acyclic.

Definition (Lean source)
ivDAG :
clause 1
clause 2
decEdge := inferInstance
clause 3
acyclic := DAG.acyclic_of_topoOrder ivTopo_lt
def ivSWIGGraph reviewed
Causalean.SCM.Examples.IV

The pre-intervention SWIG graph for the instrumental-variable example has the instrumental-variable directed acyclic graph, no fixed nodes, instrument, treatment, and outcome as observed random nodes, and the latent confounder as an unobserved random node.

Definition (Lean source)
ivSWIGGraph :
clause 1
clause 2
fixed := ∅
clause 3
observed := {SWIGNode.random Z, SWIGNode.random D, SWIGNode.random Y}
clause 4
unobserved := {SWIGNode.random U}
clause 5
fixed_is_fixed := by intro s hs; simp at hs
clause 6
observed_is_random := by intro v hv simp only [Finset.mem_insert, mem_singleton] at hv rcases hv with rfl | rfl | rfl <;> exact ⟨_, rfl⟩
clause 7
unobserved_is_random := by intro u hu simp only [mem_singleton] at hu subst u exact ⟨U, rfl⟩
clause 8
obs_unobs_disjoint := by decide
clause 9
dag_edges_classified := by decide
clause 10
fixed_image_in_observed := by intro s hs; simp at hs
clause 11
fixed_are_roots := by intro s hs; simp at hs
clause 12
unobs_are_roots := by intro u hu simp only [mem_singleton] at hu subst u simpa [initialSWIG] using (swig_random_root_of_root ivDAG ∅ U (by decide : ivDAG.parents U = ∅))
clause 13
fixed_outside_fixed_isolated := by intro n _ cases n <;> exact ⟨by decide, by decide⟩
clause 14
all_children_in_observed := by decide
def ivEdgeTypes reviewed
Causalean.SCM.Examples.IV

The edge-type assignment for the instrumental-variable graph classifies the instrument-to-treatment edge as strictly increasing and classifies every other ordered pair as nonparametric.

Definition (Lean source)
ivEdgeTypes :
where
edgeType
| Z, D => .monotonic .strictlyIncreasing
| _, _ => .nonparametric
def ivΩ reviewed
Causalean.SCM.Examples.IV

The value-space assignment for the toy instrumental-variable model gives every node a one-point state space.

Definition (Lean source)
ivΩ :
IVNode → Type
fun _ => Unit
Causalean.SCM.Examples.IV.ivΩ · Causalean/SCM/Examples/IV.lean:320 · uses IVNode
def ivSCM reviewed
Causalean.SCM.Examples.IV

The toy instrumental-variable structural causal model has the stated instrumental-variable graph, one-point node value spaces, constant structural functions, and a point-mass distribution for the latent root.

Definition (Lean source)
ivSCM :
clause 1
clause 2
fixed := ∅
clause 3
observed := {SWIGNode.random Z, SWIGNode.random D, SWIGNode.random Y}
clause 4
unobserved := {SWIGNode.random U}
clause 5
fixed_is_fixed := by intro s hs; simp at hs
clause 6
observed_is_random := by intro v hv; simp at hv rcases hv with rfl | rfl | rfl <;> exact ⟨_, rfl⟩
clause 7
unobserved_is_random := by intro u hu; simp at hu; subst hu; exact ⟨U, rfl⟩
clause 8
obs_unobs_disjoint := by decide
clause 9
dag_edges_classified := by decide
clause 10
fixed_image_in_observed := by intro s hs; simp at hs
clause 11
fixed_are_roots := by intro s hs; simp at hs
clause 12
unobs_are_roots := by intro u hu; simp at hu; subst hu simpa [initialSWIG] using (swig_random_root_of_root ivDAG ∅ U (by decide : ivDAG.parents U = ∅))
clause 13
fixed_outside_fixed_isolated := by intro n _ cases n <;> exact ⟨by decide, by decide⟩
clause 14
all_children_in_observed := by decide
clause 15
edgeTypes := EdgeTypeAssignment.allNonparametric (initialSWIG ivDAG)
clause 16
iota_valueSpace := by intro s exact (notMem_empty s.val s.property).elim
clause 17
structFun := fun v => by rcases v with ⟨n, _⟩ cases n <;> exact fun _ => ()
clause 18
structFun_measurable := by intro v rcases v with ⟨n, _⟩ cases n <;> exact measurable_const
clause 19
latentDist := fun u
=> by rcases u with ⟨n, _⟩ cases n <;> exact dirac ()
clause 20
isProbability_latent := by intro u rcases u with ⟨n, _⟩ cases n <;> exact inferInstanceAs (IsProbabilityMeasure (dirac (α := Unit) ()))
def ivDoDGraph reviewed
Causalean.SCM.Examples.IV

The intervention graph for treatment in the instrumental-variable example is the single-world intervention graph obtained by fixing treatment in the instrumental-variable directed acyclic graph.

Definition (Lean source)
ivDoDGraph :
5 supporting declarations (lemmas, instances)
  • instDecidableEqIVNode instance
    deriving DecidableEq
    Causalean.SCM.Examples.IV.instDecidableEqIVNode · Causalean/SCM/Examples/IV.lean:53
  • instReprIVNode instance — A textual rendering of an instrumental-variable node assigns to each of the four nodes its fully qualified constructor name by the stated rendering rule.
    instReprIVNode :
    reprPrec := instReprIVNode.repr
    Causalean.SCM.Examples.IV.instReprIVNode · Causalean/SCM/Examples/IV.lean:74
  • instFintypeIVNode instance — The finite enumeration of instrumental-variable nodes lists the instrument, treatment, outcome, and unobserved confounder, and establishes that every such node occurs in that list.
    instFintypeIVNode :
    clause 1
    elems := {Z, D, Y, U}
    clause 2
    complete := by intro x; cases x <;> simp
    Causalean.SCM.Examples.IV.instFintypeIVNode · Causalean/SCM/Examples/IV.lean:78
  • instDecidableRelIVNodeIvEdge instance — Decidability of the instrumental-variable edge relation determines, for every ordered pair of instrumental-variable nodes, whether that pair is an edge.
    instDecidableRelIVNodeIvEdge :
    by intro a b cases a <;> cases b <;> first | exact isTrue trivial | exact isFalse (by simp only [ivEdge]; exact fun h => h)
    Causalean.SCM.Examples.IV.instDecidableRelIVNodeIvEdge · Causalean/SCM/Examples/IV.lean:95
  • ivΩ_measurable instance — For each node of the toy instrumental-variable model, the measurable structure on its one-point value space is the trivial measurable structure.
    n :
    ivΩ_measurable n :
    fun _ => ⊤
    Causalean.SCM.Examples.IV.ivΩ_measurable · Causalean/SCM/Examples/IV.lean:326
Monotone­Counterfactual­Bound 6 core · 3 supporting This file gives a worked example of structural monotonicity in a two-node Boolean SCM. ★ monotoneCounterfactualBound★ monotoneCounterfactualBound_assumption_satisfiable★ monotoneCounterfactualBound_fails_without_monotonicity

Monotone Counterfactual Bound Example

This file gives a worked example of structural monotonicity in a two-node Boolean SCM. The target is the unit-level response contrast of the outcome equation when the parent coordinate is changed from false to true.

Without any structural restriction that contrast has logical range [-1, 1]. Under the monotone-mechanism assumption it must lie in [0, 1]. The companion counterexample below uses the reversing Boolean SCM as the reference model to show that graph and observational compatibility alone do not generally imply a [0, 1] response-contrast bound.

def boolScore reviewed
Causalean.SCM.Examples.MonotoneCounterfactualBound

For a Boolean value, its real-valued score is one when it is true and zero when it is false.

Definition (Lean source)
b :
boolScore b :
if b then 1 else 0
Causalean.SCM.Examples.MonotoneCounterfactualBound.boolScore · Causalean/SCM/Examples/MonotoneCounterfactualBound.lean:31
def boolParentAssignmentIn reviewed
Causalean.SCM.Examples.MonotoneCounterfactualBound

For a Boolean-chain structural causal model and a Boolean treatment value, the outcome-parent assignment gives each coordinate corresponding to a parent of the outcome that treatment value when it is the designated treatment parent and false otherwise.

Definition (Lean source)
b :
w :
{w // w ∈ M.dag.parents (SWIGNode.random y)}
boolParentAssignmentIn M b w :
by intro w rcases w with ⟨n, _⟩ cases n with | random n
=> cases n with | d => exact b | y => exact false | fixed n => cases n <;> exact false
def monotoneResponseContrast reviewed
Causalean.SCM.Examples.MonotoneCounterfactualBound

For each Boolean-chain structural causal model, the monotone response contrast is the real-valued difference between the scored outcome response when the designated treatment parent is true and when it is false, and it is zero whenever the outcome is not observed or the designated treatment parent is absent.

Definition (Lean source)
monotoneResponseContrast :
fun M
=> if hchild : SWIGNode.random y ∈ M.observed then if SWIGNode.random d ∈ M.dag.parents (SWIGNode.random y) then boolScore (M.structFun ⟨SWIGNode.random y, hchild⟩ (boolParentAssignmentIn M true))
- boolScore (M.structFun ⟨SWIGNode.random y, hchild⟩ (boolParentAssignmentIn M false)) else 0 else 0
theorem monotoneCounterfactualBound reviewed
Causalean.SCM.Examples.MonotoneCounterfactualBound

Structural monotonicity of the outcome mechanism in the treatment parent forces every response contrast in the compatible class to lie in the valid [0, 1] partial-identification interval.

Formal statement
compatibleInterval boolChainSWIG (MonotoneMechanism (Ω := boolChainΩ) (SWIGNode.random y) (SWIGNode.random d)) monotoneBoolSCM monotoneResponseContrastIcc (0 : ℝ) 1
Proof (Lean source)
theorem monotoneCounterfactualBound : compatibleInterval boolChainSWIG (MonotoneMechanism (Ω := boolChainΩ) (SWIGNode.random y) (SWIGNode.random d)) monotoneBoolSCM monotoneResponseContrastIcc (0 : ℝ) 1 := by intro z hz rcases hz with ⟨⟨M, hM⟩, hz⟩ rcases hM.2.1 with ⟨hchild, hparent, hmono⟩ have hparent_le : boolParentAssignmentIn M false ⟨SWIGNode.random d, hparent⟩ ≤ boolParentAssignmentIn M true ⟨SWIGNode.random d, hparent⟩ := by change false ≤ true decide have hsame : ∀ w, w.val ≠ SWIGNode.random d → boolParentAssignmentIn M false w = boolParentAssignmentIn M true w := by intro w hw rcases w with ⟨n, hn⟩ cases n with | random n => cases n with | d => simp at hw | y => rfl | fixed n => cases n <;> rfl have hresp : M.structFun ⟨SWIGNode.random y, hchild⟩ (boolParentAssignmentIn M false) ≤ M.structFun ⟨SWIGNode.random y, hchild⟩ (boolParentAssignmentIn M true) := hmono (boolParentAssignmentIn M false) (boolParentAssignmentIn M true) hparent_le hsame rw [← hz] change monotoneResponseContrast M ∈ Icc (0 : ℝ) 1 rw [responseContrast_eq_of_present M hchild hparent] exact boolScore_sub_mem_Icc hresp
theorem monotoneCounterfactualBound_assumption_satisfiable reviewed
Causalean.SCM.Examples.MonotoneCounterfactualBound

The class of structural causal models compatible with the Boolean-chain graph and monotone in the outcome's treatment parent, evaluated against the copying model as reference, is nonempty.

Formal statement
Proof (Lean source)
theorem monotoneCounterfactualBound_assumption_satisfiable : CompatibleSCM boolChainSWIG (MonotoneMechanism (Ω := boolChainΩ) (SWIGNode.random y) (SWIGNode.random d)) monotoneBoolSCM monotoneBoolSCM := by exact compatibleSCM_self _ _ _ rfl monotoneBoolSCM_satisfies
theorem monotoneCounterfactualBound_fails_without_monotonicity reviewed
Causalean.SCM.Examples.MonotoneCounterfactualBound

Without the monotonicity restriction, the unconstrained compatible class's response contrast need not lie in [0, 1].

Formal statement
Proof (Lean source)
theorem monotoneCounterfactualBound_fails_without_monotonicity : ¬ compatibleInterval boolChainSWIG (fun _ : SCM BoolChainNode boolChainΩ => True) antitoneBoolSCM monotoneResponseContrastIcc (0 : ℝ) 1 := by intro hsub have hmem : (-1 : ℝ) ∈ compatibleInterval boolChainSWIG (fun _ : SCM BoolChainNode boolChainΩ => True) antitoneBoolSCM monotoneResponseContrast := by refine ⟨⟨antitoneBoolSCM, ?_⟩, ?_⟩ · exact compatibleSCM_self _ _ _ rfl trivial · exact monotoneResponseContrast_antitoneBoolSCM have hbad := hsub hmem norm_num at hbad
3 supporting declarations (lemmas, instances)