causal inference {bnlearn} R Documentation

Perform causal inference

Description

Perform interventions and counterfactuals, using Bayesian networks as causal models.

Usage

# network transformations used in causal inference.
mutilated(x, evidence)
twin(x)

# causal inference types.
intervention(x, evidence)
counterfactual(x, evidence, merging = TRUE)

Arguments

x

an object of class bn, bn.fit or scm.

evidence

a list, in the same format as the evidence for likelihood weighting (see cpquery).

merging

a boolean value. If TRUE, the twin network is reduced by node merging after introducing the counterfactual.

Details

mutilated() constructs the mutilated network arising from an ideal intervention setting the nodes involved to the values specified by evidence.

twin() constructs the twin network required to compute counterfactuals, separating noise (exogenous) from functional (factual) nodes and adding counterfactual nodes.

intervention() is an alias of mutilated().

counterfactual() constructs the twin network and introduces a counterfactual (that is, an intervention on the counterfactual nodes) before applying node merging (optional). The intervention in evidence is specified using the labels of the nodes in x, and is then applied to the corresponding counterfactual nodes.

Both twin() and counterfactual() label nodes as follows:

  • a counterfactual node has the label of the correspoding factual node with a period appended (as in paste0(label, ".")).

  • a noise node has the label of the corresponding factual node with a "u" prepended (as in paste0("u", label)).

Evidence in intervention() can reference factual and counterfactual nodes. Evidence in counterfactual() can onyl reference counterfactual nodes; factual nodes will be replaced by the corresponding counterfactual nodes with a warning. Referencing exogenous nodes in either function will produce an error.

Value

A bn, bn.fit or scm object, depending on the class of x.

Objects returned by twin() will additionally have class bn.twin (if x is a bn or bn.fit object) or scm.twin (if x is an scm object).

Objects returned by counterfactual() will additionally have classes bn.twin and bn.ctf (if x is a bn or bn.fit object) or scm.twin (if x is an scm object).

Author(s)

Marco Scutari

References

Balke A, Pearl J (2022). "Probabilistic Evaluation of Counterfactual Queries." Probabilistic and Causal Inference: The Works of Judea Pearl, 237–254. The original is in the Proceddings of AAAI, 1994.

Graham D, Lee CM, Perov Y (2019). "Copy, Paste, Infer: A Robust Analysis of Twin Networks for Counterfactual Inference." NeurIPS19 CausalML workshop.

Koller D, Friedman N (2009). Probabilistic Graphical Models: Principles and Techniques. MIT Press.

Shpitser I, PearlJ (2007). "What counterfactuals can be tested." Proceedings of the 23rd Conference on Uncertainty in Artificial Intelligence (UAI), 352–359.

Examples

# example from Graham, Lee and Perov.
dag = model2network("[C][A|C][B|C][D|A:B]")
intervention(dag, evidence = list(A = 0))
twin(dag)
counterfactual(dag, evidence = list(A. = 0), merging = FALSE)
counterfactual(dag, evidence = list(A. = 0), merging = TRUE)

[Package bnlearn version 5.2-20250910 Index]