Skip to content

dseparated

Signature/Parameters

def dseparated(self, var1 = None, var2 = None, conditional = None)

Determine whether two variables are d-separated given a conditioning set.

Parameters:

Name Type Description Default
var1 str

Name of the first variable.

None
var2 str

Name of the second variable.

None
conditional Sequence[str] or None

Variables to condition on. Provide an iterable of node names. When None, no conditioning is applied.

None

Returns:

Type Description
bool

True if the variables are d-separated given conditional, otherwise False.

Examples:

>>> G = DAG(graph="X -> Z -> Y")
>>> G.dseparated("X", "Y")
False
>>> G.dseparated("X", "Y", conditional=["Z"])
True
Source code in causalinf/gcm.py
def dseparated(self, var1=None, var2=None, conditional=None):
    """
    Determine whether two variables are d-separated given a conditioning set.

    Parameters
    ----------
    var1 : str
        Name of the first variable.
    var2 : str
        Name of the second variable.
    conditional : Sequence[str] or None, optional
        Variables to condition on. Provide an iterable of node names. When
        ``None``, no conditioning is applied.

    Returns
    -------
    bool
        ``True`` if the variables are d-separated given ``conditional``,
        otherwise ``False``.

    Examples
    --------
    >>> G = DAG(graph="X -> Z -> Y")
    >>> G.dseparated("X", "Y")
    False
    >>> G.dseparated("X", "Y", conditional=["Z"])
    True
    """
    assert var1 and isinstance(var1, str), "'var1' (a str) must be provided."
    assert var2 and isinstance(var2, str), "'var2' (a str) must be provided."

    if conditional is None:
        conditional = NULL
    res = dagitty.dseparated(self.__dagitty__, X = var1, Y = var2, Z=conditional)[0]
    return res