DeepIV

DeepIV, developed in [Hartford], is a method for estimating the causal effects in the presence of the unobserved confounder between treatment and outcome variables. It applies deep learning methods to accurately characterize the causal relationships between the treatment and outcome when the instrumental variables (IV) are present. Due to the representation powers of deep learning models, it does not assume any parametric forms for the causal relationships.

Training a DeepIV has two steps and resembles the estimation procedure of a normal IV method. Specifically, we

  1. train a neural network, which we refer to as the treatment network \(F(Z, V)\), to estimate the distribution of the treatment \(X\) given the IV \(Z\) and covariate variables \(V\)

  2. train another neural network, which we refer to as the outcome network \(H(X, V)\), to estimate the outcome \(Y\) given treatment \(X\) and covariate variables \(V\).

The final causal effect can then be estimated by the outcome network \(H(X, W)\). For an instance, the CATE \(\tau(v)\) is estimated as

\[\tau(v) = H(X=x_t, V=v) - H(X=x_0, W=v).\]

Class Structures

class ylearn.estimator_model.deepiv.DeepIV(x_net=None, y_net=None, x_hidden_d=None, y_hidden_d=None, num_gaussian=5, is_discrete_treatment=False, is_discrete_outcome=False, is_discrete_instrument=False, categories='auto', random_state=2022)
Parameters:
  • x_net (ylearn.estimator_model.deepiv.Net, optional, default=None) – Representation of the mixture density network for continuous treatment or an usual classification net for discrete treatment. If None, the default neural network will be used. See ylearn.estimator_model.deepiv.Net for reference.

  • y_net (ylearn.estimator_model.deepiv.Net, optional, default=None) – Representation of the outcome network. If None, the default neural network will be used.

  • x_hidden_d (int, optional, default=None) – Dimension of the hidden layer of the default x_net of DeepIV.

  • y_hidden_d (int, optional, default=None) – Dimension of the hidden layer of the default y_net of DeepIV.

  • is_discrete_treatment (bool, default=False) –

  • is_discrete_instrument (bool, default=False) –

  • is_discrete_outcome (bool, default=False) –

  • num_gaussian (int, default=5) – Number of gaussians when using the mixture density network which will be directly ignored when the treatment is discrete.

  • random_state (int, default=2022) –

  • categories (str, optional, default='auto') –

fit(data, outcome, treatment, instrument=None, adjustment=None, approx_grad=True, sample_n=None, y_net_config=None, x_net_config=None, **kwargs)

Train the DeepIV model.

Parameters:
  • data (pandas.DataFrame) – Training dataset for training the estimator.

  • outcome (list of str, optional) – Names of the outcome.

  • treatment (list of str, optional) – Names of the treatment.

  • instrument (list of str, optional) – Names of the IV. Must provide for DeepIV.

  • adjustment (list of str, optional, default=None) – Names of the adjustment set ensuring the unconfoundness, which can also be seen as the covariates in the current version.

  • approx_grad (bool, default=True) – Whether use the approximated gradient as in [Hartford].

  • sample_n (int, optional, default=None) – Times of new samples when using the approx_grad technique.

  • x_net_config (dict, optional, default=None) – Configuration of the x_net.

  • y_net_config (dict, optional, default=None) – Configuration of the y_net.

Returns:

The trained DeepIV model

Return type:

instance of DeepIV

estimate(data=None, treat=None, control=None, quantity=None, marginal_effect=False, *args, **kwargs)

Estimate the causal effect with the type of the quantity.

Parameters:
  • data (pandas.DataFrame, optional, default=None) – Test data. The model will use the training data if set as None.

  • quantity (str, optional, default=None) –

    Option for returned estimation result. The possible values of quantity include:

    1. ’CATE’ : the estimator will evaluate the CATE;

    2. ’ATE’ : the estimator will evaluate the ATE;

    3. None : the estimator will evaluate the ITE or CITE.

  • treat (int, optional, default=None) – Value of the treatment, by default None. If None, then the model will set treat=1.

  • control (int, optional, default=None) – Value of the control, by default None. If None, then the model will set control=1.

Returns:

Estimated causal effects

Return type:

torch.tensor

effect_nji(data=None)

Calculate causal effects with different treatment values.

Returns:

Causal effects with different treatment values.

Return type:

ndarray

comp_transormer(x, categories='auto')

Transform the discrete treatment into one-hot vectors properly.

Parameters:
  • x (numpy.ndarray, shape (n, x_d)) – An array containing the information of the treatment variables.

  • categories (str or list, optional, default='auto') –

Returns:

The transformed one-hot vectors.

Return type:

numpy.ndarray