Skip to content

identification_analysis

Signature/Parameters

def identification_analysis(self, exposure = None, outcome = None, conditional = None, causal_probability = 'maybe', iv = 'maybe', verbose = True)

Run identification analysis for the specified exposure-outcome pair.

Parameters:

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

Exposure variable(s) of interest. When None, the current DAG exposure roles are used.

None
outcome str or None

Outcome variable. Defaults to the first DAG outcome role when omitted.

None
conditional str or list[str] or None

Variables to condition the causal effect on. Strings are promoted to single-element lists.

None
causal_probability (always, maybe)

Controls whether causal probabilities are computed. With 'maybe' (default) probabilities are evaluated only when identification by adjustment fails; 'always' forces computation.

'always'
iv (always, maybe)

Identification using instrumental variable. Use 'maybe' (default) to run analysis only when identification by adjustment fails; use 'always' to force IV evaluation.

'always'
verbose bool

When True (default), results are printed via self.print.

True

Returns:

Type Description
None
Notes

Results printed and can be retrieved using .identification and .print(). See examples.

Examples:

>>> G = DAG(graph="X -> Y")
>>> G.identification_analysis(exposure="X", outcome="Y", verbose=False)
>>> G.identification_analysis(exposure="X", outcome="Y", verbose=False)
>>> G.identification()        # to print
>>> G.print('identification') # to print
>>> G.identification_dict     # dictionary
Source code in causalinf/gcm.py
def identification_analysis(self, exposure=None, outcome=None,
                            conditional = None,
                            causal_probability='maybe',
                            iv='maybe',
                            verbose=True
                            ):
    """
    Run identification analysis for the specified exposure-outcome pair.

    Parameters
    ----------
    exposure : str or list[str] or None, optional
        Exposure variable(s) of interest. When ``None``, the current DAG
        exposure roles are used.
    outcome : str or None, optional
        Outcome variable. Defaults to the first DAG outcome role when
        omitted.
    conditional : str or list[str] or None, optional
        Variables to condition the causal effect on. Strings are promoted to
        single-element lists.
    causal_probability : {'always', 'maybe'}, optional
        Controls whether causal probabilities are computed. With ``'maybe'``
        (default) probabilities are evaluated only when identification by
         adjustment fails; ``'always'`` forces computation.
    iv : {'always', 'maybe'}, optional
        Identification using instrumental variable. Use ``'maybe'`` (default)
        to run analysis only when identification by
         adjustment fails; use ``'always'`` to force IV evaluation.
    verbose : bool, optional
        When ``True`` (default), results are printed via ``self.print``.

    Returns
    -------
    None

    Notes
    -----
    Results printed and can be retrieved using <DAG>.identification
    and <dag>.print(). See examples.

    Examples
    --------
    >>> G = DAG(graph="X -> Y")
    >>> G.identification_analysis(exposure="X", outcome="Y", verbose=False)
    >>> G.identification_analysis(exposure="X", outcome="Y", verbose=False)

    >>> G.identification()        # to print
    >>> G.print('identification') # to print
    >>> G.identification_dict     # dictionary
    """
    assert not outcome or isinstance(outcome, str), 'Outcome must be a string.'
    assert not exposure or (isinstance(exposure, str) or isinstance(exposure, list)), 'Exposure must be a string or list.'

    assert outcome or self.outcome, "No outcome found."
    assert exposure or self.exposure, "No exposure found."

    exposure = exposure or self.exposure
    outcome = outcome or self.outcome[0]
    conditional = [conditional] if isinstance(conditional, str) else conditional

    assert exposure is not None, "Exposure must be provided."
    assert outcome is not None, "Outcome must be provided."

    self.__identification__ = identification(G=self,
                                             exposure = exposure,
                                             outcome = outcome,
                                             conditional = conditional,
                                             causal_probability = causal_probability,
                                             iv = iv,
                                             verbose=verbose)
    if verbose:
        self.print('identification')

    return None