Identification
Identification algorithms.
Identification
Algorithm |
Implementation |
|---|---|
|
|
Tian ID [tian03a] |
|
IDC [shpitser2008] |
|
ID* [shpitser2012] |
|
IDC* [shpitser2012] |
|
Cyclic ID [forre2019] |
|
gID [correa2019] |
|
gID* [correa2021] |
|
Data ID [nabi2020] |
This table partially draws from [tikka2021], which made a nice review of non-counterfactual identification methods.
Transport
Algorithm |
Implementation |
|---|---|
Surrogate Outcomes [tikka2018] |
|
Transportability [correa2020] |
|
Counterfactual Transportability |
|
- class Identification(query: Query, graph: NxMixedGraph, estimand: Expression | None = None)[source]
A package of a query and resulting estimand from identification on a graph.
Instantiate an identification.
- Parameters:
query – The generalized identification query (outcomes/treatments/conditions)
graph – The graph
estimand – If none is given, will use the joint distribution over all variables in the graph.
- classmethod from_parts(outcomes: Variable | Iterable[Variable], treatments: Variable | Iterable[Variable], graph: NxMixedGraph, estimand: Expression | None = None, conditions: Variable | Iterable[Variable] | None = None) Identification[source]
Instantiate an identification.
- Parameters:
outcomes – The outcomes in the query
treatments – The treatments in the query (e.g., counterfactual variables)
conditions – The conditions in the query (e.g., coming after the bar)
graph – The graph
estimand – If none is given, will use the joint distribution over all variables in the graph.
- Returns:
An identification object
- classmethod from_expression(*, query: Probability | Distribution, graph: NxMixedGraph, estimand: Expression | None = None) Identification[source]
Instantiate an identification.
- Parameters:
query – The query probability expression
graph – The graph
estimand – If none is given, will use the joint distribution over all variables in the graph.
- Returns:
An identification object
- exchange_observation_with_action(variables: Variable | Iterable[Variable]) Identification[source]
Move the condition variable(s) to the treatments.
- exchange_action_with_observation(variables: Variable | Iterable[Variable]) Identification[source]
Move the treatment variable(s) to the conditions.
- with_treatments(extra_treatments: Iterable[Variable]) Identification[source]
Create a new identification with additional treatments.
- uncondition() Identification[source]
Move the conditions to outcomes.
- class Query(outcomes: Variable | Iterable[Variable], treatments: Variable | Iterable[Variable], conditions: None | Variable | Iterable[Variable] = None)[source]
An identification query.
Instantiate an identification.
- Parameters:
outcomes – The outcomes in the query
treatments – The treatments in the query (e.g., counterfactual variables)
conditions – The conditions in the query (e.g., coming after the bar)
- classmethod from_str(outcomes: str | Iterable[str], treatments: str | Iterable[str], conditions: Iterable[str] | None = None) Query[source]
Construct a query from text variable names.
- classmethod from_expression(query: Probability | Distribution) Query[source]
Instantiate an identification.
- Parameters:
query – The query probability expression
- Returns:
An identification tuple
- Raises:
ValueError – If there are ragged counterfactual variables in the query
- exchange_observation_with_action(variables: Variable | Iterable[Variable]) Query[source]
Move the condition variable(s) to the treatments.
- exchange_action_with_observation(variables: Variable | Iterable[Variable]) Query[source]
Move the treatment variable(s) to the conditions.
- with_treatments(extra_treatments: Iterable[Variable]) Query[source]
Create a new identification with additional treatments.
- property expression: Expression
Return the query as a Probabilistic expression.
- cyclic_id(graph: Annotated[NxMixedGraph, InPaperAs('G')], outcomes: Annotated[Variable | Iterable[Variable], InPaperAs('Y')], interventions: Annotated[Variable | Iterable[Variable], InPaperAs('W')], *, ordering: Sequence[Variable] | None = None) Annotated[Expression, InPaperAs('P(Y \\mid do(W))')][source]
Identify causal effects in cyclic graphs.
- Parameters:
graph – Causal graph
outcomes – Target variables \(Y\)
interventions – Intervention variables \(W\)
ordering – Ordering of variables in the graph. If not given, an apt-order is calculated with
get_apt_order()
- Returns:
Identified causal effect \(P(Y | do(W))\)
- Raises:
ValueError – If preconditions are violated.
Unidentifiable – If the causal effect cannot be identified based on the query and graph.
- id_star(graph: NxMixedGraph, event: dict[Variable, Intervention], *, _number_recursions: int = 0) Expression[source]
Apply the
ID*algorithm to the graph from [shpitser2012].
- idc(identification: Identification, *, ordering: Sequence[Variable] | None = None) Expression[source]
Run the IDC algorithm from [shpitser2008].
- Parameters:
identification – The identification tuple
ordering – A topological ordering of the variables. If not passed, is calculated from the directed component of the mixed graph.
- Returns:
An expression created by the
identify()algorithm after simplifying the original query
Raises “Unidentifiable” if no appropriate identification can be found.
- idc_star(graph: NxMixedGraph, outcomes: dict[Variable, Intervention], conditions: dict[Variable, Intervention], *, _number_recursions: int = 0) Expression[source]
Run the IDC* algorithm from [shpitser2012].
- Parameters:
graph – The causal graph
outcomes – The outcome events corresponds to \(\gamma\)
conditions – The condition events corresponds to \(\delta\)
_number_recursions – The number of times the algorithm has recurred
- Returns:
An expression created by the
idc_star()algorithm after simplifying the original query- Raises:
ValueError – If ID* returns zero
- identify(identification: Identification, *, ordering: Sequence[Variable] | None = None) Expression[source]
Run the ID algorithm from [shpitser2006].
- Parameters:
identification – The identification tuple
ordering – A topological ordering of the variables. If not passed, is calculated from the directed component of the mixed graph.
- Returns:
the expression corresponding to the identification
- Raises:
Unidentifiable – If no appropriate identification can be found
See also
identify_outcomes()for a more idiomatic way of running the ID algorithm given a graph, treatments, and outcomes.
- identify_outcomes(graph: NxMixedGraph, treatments: Variable | Iterable[Variable], outcomes: Variable | Iterable[Variable], conditions: None | Variable | Iterable[Variable] = None, *, strict: Literal[True] = False, ordering: Sequence[Variable] | None = None) Expression[source]
- identify_outcomes(graph: NxMixedGraph, treatments: Variable | Iterable[Variable], outcomes: Variable | Iterable[Variable], conditions: None | Variable | Iterable[Variable] = None, *, strict: Literal[False] = False, ordering: Sequence[Variable] | None = None) Expression | None
Calculate the estimand for the treatment(s)m outcome(s), and optional condition(s).
- Parameters:
graph – An acyclic directed mixed graph
treatments – The node or nodes that are treated
outcomes – The node or nodes that are outcomes
conditions – Optional condition or condition nodes. If given, uses the IDC algorithm via
y0.algorithm.identify.idc(). Otherwise, uses the ID algorithm viay0.algorithm.identify.identify().strict – If true, raises an error identification fails rather than returning None
ordering – A topological ordering of the variables. If not passed, is calculated from the directed component of the mixed graph.
- Returns:
An expression representing the estimand if the query is identifiable. If the query is not identifiable, returns none.
Do Calculus.
- rule_2_of_do_calculus_applies(graph: Annotated[NxMixedGraph, InPaperAs('G')], *, treatments: Annotated[set[Variable], InPaperAs('\\mathbf{X}')], outcomes: Annotated[set[Variable], InPaperAs('\\mathbf{Y}')], conditions: Annotated[set[Variable], InPaperAs('\\mathbf{Z}')], condition: Variable) bool[source]
Check if Rule 2 of the Do-Calculus applies to the conditioned variable.
- Parameters:
graph – The graph
treatments – The treatments
conditions – The conditions
outcomes – The outcomes
condition – The condition to check
- Returns:
If rule 2 applies, see below.
If Rule 2 of the do calculus applies to the conditioned variable, then it can be converted to a do variable.
\[\begin{split}\newcommand\ci{\perp\!\!\!\perp} \newcommand{\ubar}[1]{\underset{\bar{}}{#1}} \newcommand{\obar}[1]{\overset{\bar{}}{#1}} \text{if } (\exists Z \in \mathbf{Z})(\mathbf{Y} \ci Z | \mathbf{X}, \mathbf{Z} - \{Z\})_{G_{\bar{\mathbf{X}}\ubar{Z}}} \\ \text{then } P(\mathbf{Y}|do(\mathbf{X}),\mathbf{Z}) = P(\mathbf Y|do(\mathbf X), do(Z), \mathbf{Z} - \{Z\})\end{split}\]