估计器模型:估计因果效应

对于有 \(do\)-operator 的因果效应,用被称为 识别 的方法把它转变为对应的统计估计量之后,因果推断的任务现在变成估计统计估计量, 即转变后的因果效应。在深入到任何具体的因果效应估计方法之前,我们简要的介绍因果效应估计的问题设置。

问题设置

因果模型 中介绍了每个因果结构都有对应的被称为因果图的DAG。此外,一个DAG \(G\) 的每一个子父家庭表示一个确定性函数。

\[X_i = F_i (pa_i, \eta_i), i = 1, \dots, n,\]

其中, \(pa_i\)\(x_i\)\(G\) 中的父节点,且 \(\eta_i\) 是随机扰动,表示外生的未在分析中出现的。我们称这些函数为 关于因果结构的 Structural Equation Model 。对于一组满足后门准则(参考 识别)的变量 \(W\)\(X\)\(Y\) 的因果效应由公式给出

\[P(y|do(x)) = \sum_w P(y| x, w)P(w).\]

在这样的情况下,上述等式有效的变量 \(X\) 也被命名为 “条件可忽略的给定 \(W\)” 在 潜在结果 的框架中。 满足这个条件的变量组 \(W\) 被 称为 调整集合 。在结构化方程模型的语言里,这些关系编码如

\[\begin{split}X & = F_1 (W, \epsilon),\\ Y & = F_2 (W, X, \eta).\end{split}\]

我们的问题可以用结构化方程模型表示。

估计器模型

YLearn实现了几个用于估计因果效应的估计器模型

\[\mathbb{E}[F_2(x_1, W, \eta) - F_2(x_0, W, \eta)]\]

在ATE中和

\[\mathbb{E}[F_2(x_1, W, V, \eta) - F_2(x_0, W, V, \eta)]\]

在CATE中的估计将会成为YLearn中不同的合适的 估计器模型 的任务。YLearn中概念 EstimatorModel 就是为这个目的设计的

一个常见的 EstimatorModel 应该有如下结构:

class BaseEstModel:
    """
    Base class for various estimator model.

    Parameters
    ----------
    random_state : int, default=2022
    is_discrete_treatment : bool, default=False
        Set this to True if the treatment is discrete.
    is_discrete_outcome : bool, default=False
        Set this to True if the outcome is discrete.
    categories : str, optional, default='auto'

    """
    def fit(
        self,
        data,
        outcome,
        treatment,
        **kwargs,
    ):
        """Fit the estimator model.

        Parameters
        ----------
        data : pandas.DataFrame
            The dataset used for training the model

        outcome : str or list of str, optional
            Names of the outcome variables

        treatment : str or list of str
            Names of the treatment variables

        Returns
        -------
        instance of BaseEstModel
            The fitted estimator model.
        """

    def estimate(
        self,
        data=None,
        quantity=None,
        **kwargs
    ):
        """Estimate the causal effect.

        Parameters
        ----------
        data : pd.DataFrame, optional
            The test data for the estimator to evaluate the causal effect, note
            that the estimator directly evaluate all quantities in the training
            data if data is None, by default None

        quantity : str, optional
            The possible values of quantity include:
                'CATE' : the estimator will evaluate the CATE;
                'ATE' : the estimator will evaluate the ATE;
                None : the estimator will evaluate the ITE or CITE, by default None

        Returns
        -------
        ndarray
            The estimated causal effect with the type of the quantity.
        """

    def effect_nji(self, data=None, *args, **kwargs):
        """Return causal effects for all possible values of treatments.

        Parameters
        ----------
        data : pd.DataFrame, optional
            The test data for the estimator to evaluate the causal effect, note
            that the estimator directly evaluate all quantities in the training
            data if data is None, by default None
        """