Overview of Doubly Robust Learners, application examples, and examples of implementation in python

Machine Learning Artificial Intelligence Digital Transformation Reinforce Learning Python Intelligent information Probabilistic Generative Model Explainable Machine Learning Mathematics Natural Language Processing Ontology Technology Problem Solving Relational Data Learning Statistical Causal Search Economy and Business Physics & Mathematics Navigation of this blog 
Doubly Robust Learners

Doubly Robust Learners is one of the statistical methods used in the context of causal inference, which aims to obtain more robust results by combining two estimation methods when estimating causal effects from observed data.

Doubly Robust Learners is effective based on the following two factors

Propensity Score estimation:

In Doubly Robust Learners, there are several ways to estimate the propensity score. The propensity score is a model that predicts the probability of receiving an intervention (treatment) and is used to balance confounding factors between groups that received the intervention and those that did not. The main propensity score estimation methods are described below.

    • Logistic regression model: The most common method is to estimate propensity scores with a logistic regression model. In this case, logistic regression is used to estimate the probability of receiving an intervention, with the presence of intervention as the objective variable and confounding factors as explanatory variables.
    • Machine learning algorithms: In addition to logistic regression, other machine learning algorithms such as decision trees, random forests, and neural networks may be used to estimate propensity scores. This can be especially useful when capturing nonlinear relationships or when there are many confounding factors.
    • Inverse Probability Weighting (IPW): After propensity scores are estimated, IPW can be used to correct for the effects of confounding factors. IPW reduces confounding bias by adjusting the weights of the groups that received the intervention and those that did not.
    • Propensity score matching: Another method uses propensity scores to match 1:1 the group that received the intervention with the group that did not receive the intervention that has similar characteristics. This allows for a balance of confounding factors.

In Doubly Robust Learners, it is important to choose the appropriate method for propensity score estimation and to properly correct for the effects of confounding factors, so that the estimated propensity scores and outcome models can be used to more accurately estimate causal effects.

Models to Predict Treatment Effects:

Doubly Robust Learners prepares what is called an “outcome model” (Outcome Model) for the model used to predict the effect of a procedure (intervention, treatment). The outcome model models the observed outcome (response variable) with respect to the intervention and confounding factors, and aims to estimate causal effects more accurately by combining propensity score estimation and the outcome model.

Outcome models are generally constructed using the following approaches

    • Linear regression models: The simplest approach is to use linear regression models. In an outcome model, intervention variables, propensity scores, and possible confounders are used as explanatory variables to predict the observed outcome (response variable). However, linear regression can have difficulty capturing nonlinear relationships.
    • Machine Learning Algorithms: Machine learning algorithms such as decision trees, random forests, support vector machines, and neural networks may be used to capture nonlinear relationships. This can be especially useful when considering high-dimensional data and complex relationships.
    • Nonparametric methods: Nonparametric methods such as Kernel regression or local regression may be used as the outcome model, rather than parametric models such as logistic or linear regression. These methods allow for more flexible modeling of relationships.

The outcome model is used in conjunction with propensity scores to estimate the effect of the treatment. While propensity scores serve to balance interventions and confounding factors, outcome models are used to predict actual outcomes, and in Doubly Robust Learners, an appropriate combination of both propensity score estimation and outcome models improves robustness to causal effect estimation.

Combining these elements, Doubly Robust Learners is doubly robust, allowing for more accurate causal effect estimation if the propensity score estimation is accurate, even if some of the assumptions of the model predicting the effect of the treatment are wrong.

Doubly Robust Learners are widely used to reduce bias and ensure consistency of effects in the context of causal inference, and this approach can be useful for causal estimation in real-world problems, such as estimating treatment effects and evaluating interventions.

However, Doubly Robust Learners also depends on data assumptions and model assumptions, so caution should be exercised, and accurate propensity score estimation and appropriate model selection are important, and the appropriate method should be selected based on the nature of the data and the objectives of the study. Translated with www.DeepL.com/Translator (free version)

Doubly Robust Learners Processing Procedure

Doubly Robust Learners is a method for estimating the effects of procedures (interventions, treatments) in causal inference, combining both propensity score estimation and outcome models for robust estimation. The following is a brief description of the Doubly Robust Learners procedure.

  1. Data preprocessing: Appropriate preprocessing of the data to be analyzed. This includes processing missing values in the data, removing unnecessary features, and encoding categorical variables.
  2. Estimation of propensity scores: Estimate propensity scores from the data. The propensity score serves as a model to predict the probability of receiving the intervention. Estimate propensity scores using logistic regression, machine learning algorithms, nonparametric methods, etc.
  3. Weighting: The propensity score is used to weight individual data points. By weighting, propensity scores serve to balance interventions and confounding factors.
  4. Building the outcome model: The weighted data are used to build the outcome model. The outcome model will be a model that uses the intervention and confounding factors as explanatory variables and predicts the observed outcome (response variable). Linear regression, machine learning algorithms, and nonparametric methods will be used to construct the outcome model.
  5. Estimation of treatment effects: Both propensity scores and outcome models will be used to estimate the effects of the treatment. Combining the estimated propensity score and the outcome model, a double probability correction is performed to estimate the causal effect.
  6. Assessing Robustness: In Doubly Robust Learners, combining both propensity score estimation and the outcome model improves robustness, but may still contain bias and uncertainty. Therefore, the robustness of the estimation results should be evaluated to confirm their reliability.
Libraries and Platforms Used for Doubly Robust Learners

The following describes the libraries and platforms that can be used to implement Doubly Robust Learners.

<Python Libraries>

  • CausalML: CausalML is a library in Python that provides various algorithms related to causal inference.

<Package of R>

  • DRIP: DRIP (Doubly Robust IPW Estimation) is a package in R that provides tools for estimating causal effects based on Doubly Robust Learners.

<TensorFlow Probability (TFP) / PyTorch>

  • TensorFlow Probability and PyTorch are machine learning frameworks that provide numerical computation libraries and machine learning algorithms that can be used to implement Doubly Robust Learners.

These libraries and platforms provide useful tools for implementing Doubly Robust Learners, specifically for estimating propensity scores, building outcome models, and implementing double probability correction.

About the Application of Doubly Robust Learners

Doubly Robust Learners is a widely used method in the context of causal inference, and there are a variety of actual applications. The following are some of the typical applications of Doubly Robust Learners.

  • Medical research: In the medical domain, Doubly Robust Learners are used to evaluate the effects of specific treatments or drugs. For example, when one wants to estimate the effect of a new drug in an observational study rather than in a randomized experimental trial (RCT), propensity score estimation is combined with an outcome model to more accurately assess the effect of the treatment.
  • Educational Policy Evaluation: Doubly Robust Learners is also applied to evaluate the effects of educational policies. For example, when estimating the effect of a particular educational program or policy on students’ academic performance, propensity score estimation and outcome models are used to evaluate causal effects.
  • Evaluation of Marketing and Advertising Effectiveness: Doubly Robust Learners are sometimes used to evaluate the effectiveness of marketing and advertising. For example, when estimating the effect of a particular advertising campaign on product sales, propensity score estimation and outcome models are used to assess causal effects.
  • Environmental Policy Evaluation: Doubly Robust Learners are also applied to evaluate the effects of environmental policies. For example, when estimating the extent to which a particular environmental measure contributes to reducing environmental pollution, propensity score estimation and outcome models are used to evaluate causal effects.

These are only a few examples, and Doubly Robust Learners can be a general-purpose method used in a variety of domains. It is widely applied as a useful method in situations where causal effects are more accurately estimated from observed data to solve problems where causal inference is important.

For an example implementation in python applying Doubly Robust Learners to evaluate the effectiveness of a specific treatment or drug

An example implementation in python using Doubly Robust Learners to evaluate the effectiveness of a specific treatment or drug is presented. Here, simple pseudo data is used to estimate propensity scores, build an outcome model, and perform a double probability correction. Actual data would require more complex models and data preprocessing, but the following is an example that demonstrates the basic concepts.

import numpy as np
import pandas as pd
from sklearn.linear_model import LogisticRegression
from sklearn.ensemble import RandomForestRegressor
from sklearn.metrics import mean_squared_error

# Function to generate simple pseudo data
def generate_pseudo_data(n_samples):
    np.random.seed(42)
    X = np.random.randn(n_samples, 2)  # Generate two features as confounders
    T = np.random.randint(0, 2, size=n_samples)  # Randomly select 0 or 1 treatment
    Y0 = 2*X[:, 0] + 3*X[:, 1] + 0.5*T + np.random.randn(n_samples)  # Result of no treatment
    Y1 = 2*X[:, 0] + 3*X[:, 1] + 0.5*T + 2  # Results with treatment
    Y = (1 - T) * Y0 + T * Y1  # Actual Results
    data = pd.DataFrame({'X0': X[:, 0], 'X1': X[:, 1], 'T': T, 'Y': Y})
    return data

# Function to estimate propensity score
def estimate_propensity_score(X, T):
    model = LogisticRegression()
    model.fit(X, T)
    return model.predict_proba(X)[:, 1]

# Functions to build the result model
def build_outcome_model(X, T, Y):
    model = RandomForestRegressor()
    model.fit(np.hstack([X, T.reshape(-1, 1)]), Y)
    return model

# Functions to implement Doubly Robust Learners
def doubly_robust_learners(data):
    X = data[['X0', 'X1']].values
    T = data['T'].values
    Y = data['Y'].values

    # Estimation of Propensity Scores
    propensity_scores = estimate_propensity_score(X, T)

    # Building a Results Model
    outcome_model = build_outcome_model(X, T, Y)

    # Estimation of treatment effects with double probability correction
    Y_treated = outcome_model.predict(np.hstack([X, np.ones_like(T).reshape(-1, 1)]))
    Y_untreated = outcome_model.predict(np.hstack([X, np.zeros_like(T).reshape(-1, 1)]))

    weights_treated = T / propensity_scores
    weights_untreated = (1 - T) / (1 - propensity_scores)

    treatment_effect = np.mean((Y_treated - Y) * weights_treated) + np.mean((Y - Y_untreated) * weights_untreated)

    return treatment_effect

if __name__ == "__main__":
    n_samples = 1000
    data = generate_pseudo_data(n_samples)
    treatment_effect = doubly_robust_learners(data)
    print("Estimated treatment effect:", treatment_effect)

In this code, the generate_pseudo_data function generates simple pseudo data, the estimate_propensity_score function estimates propensity scores, and the build_outcome_model function builds the outcome model. Then, Doubly Robust Learners is implemented with the doubly_robust_learners function to estimate the treatment effect.

For an example implementation in python that applies Doubly Robust Learners to estimate the effect of a specific educational program or educational policy on students’ academic performance

An example of a python implementation applying Doubly Robust Learners to estimate the effect of an educational program or policy on students’ academic performance is presented. Here, we use simple pseudo data to estimate propensity scores, build an outcome model, and perform a double probability correction.

import numpy as np
import pandas as pd
from sklearn.linear_model import LogisticRegression
from sklearn.ensemble import RandomForestRegressor
from sklearn.metrics import mean_squared_error

# Function to generate simple pseudo data
def generate_pseudo_data(n_samples):
    np.random.seed(42)
    study_hours = np.random.randint(0, 10, size=n_samples)  # Study Time
    treatment = np.random.randint(0, 2, size=n_samples)  # Randomly select 0 or 1 educational program
    baseline_score = 60 + 10 * study_hours + np.random.randn(n_samples)  # Academic performance without educational programs
    treatment_effect = 5  # Effectiveness of Educational Programs
    treatment_score = baseline_score + treatment * treatment_effect  # Academic performance with educational programs
    data = pd.DataFrame({'StudyHours': study_hours, 'Treatment': treatment, 'BaselineScore': baseline_score, 'TreatmentScore': treatment_score})
    return data

# Function to estimate propensity score
def estimate_propensity_score(X, T):
    model = LogisticRegression()
    model.fit(X, T)
    return model.predict_proba(X)[:, 1]

# Functions to build the result model
def build_outcome_model(X, T, Y):
    model = RandomForestRegressor()
    model.fit(np.hstack([X, T.reshape(-1, 1)]), Y)
    return model

# Functions to implement Doubly Robust Learners
def doubly_robust_learners(data):
    X = data[['StudyHours']].values
    T = data['Treatment'].values
    Y = data['TreatmentScore'].values

    # Estimation of Propensity Scores
    propensity_scores = estimate_propensity_score(X, T)

    # Building a Results Model
    outcome_model = build_outcome_model(X, T, Y)

    # Estimation of treatment effects with double probability correction
    Y_treated = outcome_model.predict(np.hstack([X, np.ones_like(T).reshape(-1, 1)]))
    Y_untreated = outcome_model.predict(np.hstack([X, np.zeros_like(T).reshape(-1, 1)]))

    weights_treated = T / propensity_scores
    weights_untreated = (1 - T) / (1 - propensity_scores)

    treatment_effect = np.mean((Y_treated - Y) * weights_treated) + np.mean((Y - Y_untreated) * weights_untreated)

    return treatment_effect

if __name__ == "__main__":
    n_samples = 1000
    data = generate_pseudo_data(n_samples)
    treatment_effect = doubly_robust_learners(data)
    print("Estimated treatment effect:", treatment_effect)

In this example, studyHours (StudyHours) is treated as a confounding factor and the educational program (Treatment) as a treatment. The effect of the educational program (treatment_effect) is assumed to be 5. It is important to use appropriate features and models according to the actual data. In addition, more accurate estimation of causal effects can be achieved by pre-processing the data and adjusting the hyperparameters.

On an Example Python Implementation of Applying Doubly Robust Learners to Estimate the Effect of a Specific Advertising Campaign on Product Sales

An example implementation in python of applying Doubly Robust Learners to estimate the effect of an advertising campaign on product sales is presented. Here, simple pseudo data is used to estimate propensity scores, build an outcome model, and perform a double probability correction.

import numpy as np
import pandas as pd
from sklearn.linear_model import LogisticRegression
from sklearn.ensemble import RandomForestRegressor
from sklearn.metrics import mean_squared_error

# Function to generate simple pseudo data
def generate_pseudo_data(n_samples):
    np.random.seed(42)
    ad_budget = np.random.randint(0, 1000, size=n_samples)  # advertising budget
    treatment = np.random.randint(0, 2, size=n_samples)  # Randomly select 0 or 1 ad campaign
    baseline_sales = 1000 + 2 * ad_budget + np.random.randn(n_samples) * 50  # Sales without advertising campaign
    treatment_effect = 200  # Effectiveness of Advertising Campaigns
    treatment_sales = baseline_sales + treatment * treatment_effect  # Sales with advertising campaign
    data = pd.DataFrame({'AdBudget': ad_budget, 'Treatment': treatment, 'BaselineSales': baseline_sales, 'TreatmentSales': treatment_sales})
    return data

# Function to estimate propensity score
def estimate_propensity_score(X, T):
    model = LogisticRegression()
    model.fit(X, T)
    return model.predict_proba(X)[:, 1]

# Functions to build the result model
def build_outcome_model(X, T, Y):
    model = RandomForestRegressor()
    model.fit(np.hstack([X, T.reshape(-1, 1)]), Y)
    return model

# Functions to implement Doubly Robust Learners
def doubly_robust_learners(data):
    X = data[['AdBudget']].values
    T = data['Treatment'].values
    Y = data['TreatmentSales'].values

    # Estimation of Propensity Scores
    propensity_scores = estimate_propensity_score(X, T)

    # Building a Results Model
    outcome_model = build_outcome_model(X, T, Y)

    # Estimation of treatment effects with double probability correction
    Y_treated = outcome_model.predict(np.hstack([X, np.ones_like(T).reshape(-1, 1)]))
    Y_untreated = outcome_model.predict(np.hstack([X, np.zeros_like(T).reshape(-1, 1)]))

    weights_treated = T / propensity_scores
    weights_untreated = (1 - T) / (1 - propensity_scores)

    treatment_effect = np.mean((Y_treated - Y) * weights_treated) + np.mean((Y - Y_untreated) * weights_untreated)

    return treatment_effect

if __name__ == "__main__":
    n_samples = 1000
    data = generate_pseudo_data(n_samples)
    treatment_effect = doubly_robust_learners(data)
    print("Estimated treatment effect:", treatment_effect)

In this example, the advertising budget (AdBudget) is treated as a confounding factor and the advertising campaign (Treatment) as a treatment. The effectiveness of the ad campaign (treatment_effect) is assumed to be 200.

On an example implementation in python that applies Doubly Robust Learners to estimate the extent to which a particular environmental measure contributes to the reduction of environmental pollution

An example implementation in python of applying Doubly Robust Learners to estimate the extent to which a particular environmental measure contributes to the reduction of environmental pollution is presented. Here, simple pseudo-data is used to estimate propensity scores, build an outcome model, and perform a double probability correction.

import numpy as np
import pandas as pd
from sklearn.linear_model import LogisticRegression
from sklearn.ensemble import RandomForestRegressor
from sklearn.metrics import mean_squared_error

# Function to generate simple pseudo data
def generate_pseudo_data(n_samples):
    np.random.seed(42)
    pollution_reduction = np.random.randint(0, 100, size=n_samples)  # Pollution reduction rate due to environmental measures
    treatment = np.random.randint(0, 2, size=n_samples)  # Randomly select 0 or 1 environmental measure
    baseline_pollution = 100 + np.random.randn(n_samples) * 10  # Pollution levels without environmental measures
    treatment_effect = 20  # Effectiveness of Environmental Measures
    treatment_pollution = baseline_pollution - treatment * (baseline_pollution * pollution_reduction / 100)  # Pollution level with environmental measures
    data = pd.DataFrame({'PollutionReduction': pollution_reduction, 'Treatment': treatment, 'BaselinePollution': baseline_pollution, 'TreatmentPollution': treatment_pollution})
    return data

# Function to estimate propensity score
def estimate_propensity_score(X, T):
    model = LogisticRegression()
    model.fit(X, T)
    return model.predict_proba(X)[:, 1]

# Functions to build the result model
def build_outcome_model(X, T, Y):
    model = RandomForestRegressor()
    model.fit(np.hstack([X, T.reshape(-1, 1)]), Y)
    return model

# Functions to implement Doubly Robust Learners
def doubly_robust_learners(data):
    X = data[['PollutionReduction']].values
    T = data['Treatment'].values
    Y = data['TreatmentPollution'].values

    # Estimation of Propensity Scores
    propensity_scores = estimate_propensity_score(X, T)

    # Building a Results Model
    outcome_model = build_outcome_model(X, T, Y)

    # Estimation of treatment effects with double probability correction
    Y_treated = outcome_model.predict(np.hstack([X, np.ones_like(T).reshape(-1, 1)]))
    Y_untreated = outcome_model.predict(np.hstack([X, np.zeros_like(T).reshape(-1, 1)]))

    weights_treated = T / propensity_scores
    weights_untreated = (1 - T) / (1 - propensity_scores)

    treatment_effect = np.mean((Y_treated - Y) * weights_treated) + np.mean((Y - Y_untreated) * weights_untreated)

    return treatment_effect

if __name__ == "__main__":
    n_samples = 1000
    data = generate_pseudo_data(n_samples)
    treatment_effect = doubly_robust_learners(data)
    print("Estimated treatment effect:", treatment_effect)

In this example, the PollutionReduction from environmental measures (PollutionReduction) is used as a confounding factor, and environmental measures (Treatment) are treated as a treatment. The treatment_effect is assumed to be 20.

Reference Information and Reference Books

Details of causal inference and causal search are described in “Statistical Causal Inference and Causal Search. See also that contents.

Causal Inference in Statistics” is available as a reference book.

Causal Inference and Discovery in Python: Unlock the secrets of modern causal machine learning with DoWhy, EconML, PyTorch and more

Causal Inference in Python: Applying Causal Inference in the Tech Industry

Causal Inference for Data Science

コメント

Exit mobile version
タイトルとURLをコピーしました