Skip to content

paths

Signature/Parameters

def paths(self, exposure = None, outcome = None, adj_set = None, directed = False)

Get paths between exposure and outcome, optionally conditioning on a set.

Parameters:

Name Type Description Default
exposure str or list[str] or None

Exposure node(s). Defaults to the DAG’s exposure role when omitted.

None
outcome str or list[str] or None

Outcome node(s). Defaults to the DAG’s outcome role when omitted.

None
adj_set Sequence[str] or None

Conditioning set supplied to dagitty.paths. None is passed through to indicate no adjustment.

None
directed bool

When True, restrict to directed paths from exposure to outcome. Defaults to False.

False

Returns:

Type Description
dict[str, dict[str, Any]]

Mapping from path strings to dictionaries with keys 'open' and 'adj_set' indicating path status and conditioning set.

Examples:

>>> G = DAG(graph="X -> Z -> Y")
>>> G.paths(exposure="X", outcome="Y", directed=True)
{'X -> Z -> Y': {'open': True, 'adj_set': None}}
Source code in causalinf/gcm.py
def paths(self, exposure=None, outcome=None, adj_set=None, directed=False):
    """
    Get paths between exposure and outcome, optionally conditioning on a set.

    Parameters
    ----------
    exposure : str or list[str] or None, optional
        Exposure node(s). Defaults to the DAG's exposure role when omitted.
    outcome : str or list[str] or None, optional
        Outcome node(s). Defaults to the DAG's outcome role when omitted.
    adj_set : Sequence[str] or None, optional
        Conditioning set supplied to ``dagitty.paths``. ``None`` is passed
        through to indicate no adjustment.
    directed : bool, optional
        When ``True``, restrict to directed paths from exposure to outcome.
        Defaults to ``False``.

    Returns
    -------
    dict[str, dict[str, Any]]
        Mapping from path strings to dictionaries with keys ``'open'`` and
        ``'adj_set'`` indicating path status and conditioning set.

    Examples
    --------
    >>> G = DAG(graph="X -> Z -> Y")
    >>> G.paths(exposure="X", outcome="Y", directed=True)
    {'X -> Z -> Y': {'open': True, 'adj_set': None}}
    """
    exposure = exposure or self.exposure
    outcome = outcome or self.outcome

    assert exposure, "Exposure must be provided."
    assert outcome, "Outcome must be provided."

    adj = adj_set or NULL
    paths_info = dagitty.paths(self.__dagitty__, exposure, to=outcome, Z=adj, directed=directed)
    paths = list(paths_info.rx2['paths'])
    are_open = list(paths_info.rx2['open'])

    return {path:{'open':is_open, 'adj_set':adj_set} for path, is_open in zip(paths, are_open)}