Git Product home page Git Product logo

dscolby / causalelm.jl Goto Github PK

View Code? Open in Web Editor NEW
18.0 1.0 0.0 2.4 MB

Taking causal inference to the extreme!

Home Page: https://dscolby.github.io/CausalELM.jl/

License: MIT License

Julia 100.00%
causal-inference causal-machine-learning extreme-learning-machine g-computation interrupted-time-series metalearning observational-studies quasi-experimental assumption-check double-machine-learning

causalelm.jl's Introduction

Build Status Code Coverage License Documentation Develmopmental Documentation

CausalELM enables estimation of causal effects in settings where a randomized control trial would be impossible or infeasible. Estimation of the average treatment effect (ATE), intent to treat effect (ITE), and average treatment effect on the treated (ATT) can be estimated via G-computation or double machine learning (DML) while the ATE or cumulative treatment effect (CTE) can be estimated from an interrupted time series analysis. CausalELM also supports estimation of individual treatment effects or conditional average treatment effects (CATE) via S-learning, T-learning, X-learning, and R-learning. The underlying machine learning model for all these estimators is an extreme learning machine or L2 regularized extreme learning machine. Furthermore, once a model has been estimated, CausalELM can summarize the model, including computing p-values via randomization inference, and conduct sensitivity analysis. All of this can be done in foru lines of code.

Extreme Learning Machines and Causal Inference

In some cases we would like to know the causal effect of some intervention but we do not have the counterfactual, making conventional methods of statistical analysis infeasible. However, it may still be possible to get an unbiased estimate of the causal effect (ATE, ATE, or ITT) by predicting the counterfactual and comparing it to the observed outcomes. This is the approach CausalELM takes to conduct interrupted time series analysis, G-Computation, DML, and meatlearning via S-Learners, T-Learners, X-Learners, and R-learners. In interrupted time series analysis, we want to estimate the effect of some intervention on the outcome of a single unit that we observe during multiple time periods. For example, we might want to know how the announcement of a merger affected the price of Stock A. To do this, we need to know what the price of stock A would have been if the merger had not been announced, which we can predict with machine learning methods. Then, we can compare this predicted counterfactual to the observed price data to estimate the effect of the merger announcement. In another case, we might want to know the effect of medicine X on disease Y but the administration of X was not random and it might have also been administered at mulitiple time periods, which would produce biased estimates. To overcome this, G-computation models the observed data, uses the model to predict the outcomes if all patients recieved the treatment, and compares it to the predictions of the outcomes if none of the patients recieved the treatment. Double machine learning (DML) takes a similar approach but also models the treatment mechanism and uses it to adjust the initial estimates. This approach has three advantages. First, it is more efficient with high dimensional data than conventional methods. Second, it allows one to model complex, nonlinear relationships between the treatment and the outcome. Finally, it is a doubly robust estimator, meaning that only the model of the outcome OR the model of the treatment mechanism has to be correctly specified to yield unbiased estimates. The DML implementation in CausalELM. also overcomes bias from regularization by employing cross fitting. Furthermore, we might be more interested in how much an individual can benefit from a treatment, as opposed to the average treatment effect. Depending on the characteristics of our data, we can use metalearning methods such as S-Learning, T-Learning, X-Learning, or R-Learning to do so. In all of these scenarios, how well we estimate the treatment effect depends on how well we can predict the counterfactual. The most common approaches to getting accurate predictions of the counterfactual are to use a super learner, which combines multiple machine learning methods and requires extensive tuning, or tree-based methods, which also have large hyperparameter spaces. In these cases hyperparameter tuning can be computationally expensive and requires researchers to make arbitrary decisions about how many and what models to use, how much regularization to apply, the depth of trees, interaction effects, etc. On the other hands, ELMs are able to achieve good accuracy on a variety of regression and classification tasks and generalize well. Moreover, they have a much smaller hyperparameter space to tune and are fast to train becasue they do not use backpropagation to update their weights like conventional neural networks.

CausalELM Features

  • Simple interface enables estimating causal effects in only a few lines of code
  • Validate and test sensitivity of a model to possible violations of its assumption in one line of code
  • Estimation of p-values and standard errors via asymptotic randomization inference
  • Incorporates latest research from statistics, machine learning, econometrics, and biostatistics
  • Analytically derived L2 penalty reduces cross validation time and multicollinearity
  • Fast automatic cross validation works with longitudinal, panel, and time series data
  • Includes 13 activation functions and allows user-defined activation functions
  • Single interface for continous, binary, and categorical outcome variables
  • No dependencies outside of the Julia standard library

What's New?

  • Added support for dataframes
  • Estimators can handle any array whose values are <:Real
  • Estimator constructors are now called with model(X, T, Y) instead of model(X, Y, T)
  • Eliminated unnecessary type constraints on many methods
  • Improved documentation
  • Permutation of continuous treatments draws from a continuous, instead of discrete uniform distribution during randomization inference

Next Steps

The priority for v0.6 will be on implementing doubly robust estimation for the average effect (ATE/ATT) as well as the CATE. We will also make minor improvements for speed, maintainability, etc.

Disclaimer

CausalELM is extensively tested and almost every function or method has multiple tests. That being said, CausalELM is still in the early/ish stages of development and may have some bugs. Also, expect breaking releases for now.

Contributing

All contributions are welcome. Before submitting a pull request please read the contribution guidlines.

causalelm.jl's People

Contributors

dscolby avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

causalelm.jl's Issues

Change contributor guide

Add that for functions with multiple methods there should be a function definition with no parameters in the main module that includes the docstring for all the methods.

Make methods and functions more general

Currently, most of the functions and methods only work with floats but they should be able to accept any real numbers or subtypes of real numbers. This should be a very easy fix.

TagBot trigger issue

This issue is used to trigger TagBot; feel free to unsubscribe.

If you haven't already, you should update your TagBot.yml to include issue comment triggers.
Please see this post on Discourse for instructions and more details.

If you'd like for me to do this for you, comment TagBot fix on this issue.
I'll open a PR within a few hours, please be patient!

Make sigmoid layer for binary classifiers

Currently, classification is done by just using the sigmoid activation function, which is basically just regression. This could potentially lead to predicted probabilities being outside of [0, 1]. Instead, for classification we should use a normal ELM with ReLU or another activation to get raw predictions and apply the sigmoid to those outputs similar to the way we use a softmax layer for multiclass classification.

Mild refactoring

Change multi-line function definitions and calls to

 foo(arg1, arg2, 
        arg3, arg4)

remove docstrings from every struct field and only put docstrings at the top of each struct.

Make models compatible with other data types

Right now the models work on arrays but they should be able to work with other input like dataframes, tables, etc. This will also require figuring out what people usually use to read and manipulate their data in Julia. Getting this done will probably be a v0.4 task.

Make better looking documentation

This is not a priority and it will take a while. It is going to require working with CSS. Right now the theme is clean but the color palette is very bland.

Add support for GPUs

Priority should probably be integration with CUDA, then Intel, then ATI, then Mac. In theory this should be easy but we should watch for type instability.

Add W argument

Add W parameter for covariates for the treatment function in double machine learning, X learning, doubly robust estimation, and R learning.

Calculate p-values for ITS using alternative type of permutation

The current permutation test for p-values using ITS estimates the null distribution by using alternative cutoff points for pre and post-intervention periods. Instead, we should permute the order of the post-treatment observations to estimate null effects and use those estimated effects under permuted post-treatment observations to estimate the null distribution.

As a reminder, we can easily create permutations using a[shuffle(1:end), :].

Make smaller functions and methods

Specifically, for the estimators and metalearners we should make a separate risk ratio function; we should find a way to make estimate_causal_effect! for g-computation smaller; estimate_causal_effect! for double machine learning should definitely be broken up into smaller functions; and crossfitting_sets should also be smaller. These smaller functions will then need to be testes.

Implement E-values for all estimators

ITS conducts sensitivity analysis by generating random variables and re-estimating the causal effect. Instead, we should implement E-values, as proposed by VanderWeele, Tyler J., and Peng Ding. "Sensitivity analysis in observational research: introducing the E-value." Annals of internal medicine 167, no. 4 (2017): 268-274. Besides ITS, we should implement this as a test of confounding/exchangeability for all estimators.

The steps to implement are:

Start with the observed effect estimate (e.g., mean difference or average treatment effect) from your study, denoted as MEAN_OBS.

Calculate the lower and upper confidence limits (LL and UL) for your observed effect estimate (MEAN_OBS) based on the confidence interval from your statistical analysis.

To calculate MD_U (Minimum Strength for Upper Limit):

Start with the UL (Upper Confidence Limit) of the mean difference.

Mathematically, you can set up the following equation:

MD_U * MEAN_OBS = UL

Solve for MD_U:

MD_U = UL / MEAN_OBS

To calculate MD_L (Minimum Strength for Lower Limit):

Start with the LL (Lower Confidence Limit) of the mean difference.

Set up the following equation:

MD_L * MEAN_OBS = LL

Solve for MD_L:

MD_L = LL / MEAN_OBS

It's common for researchers to consider an E-value greater than 2 as indicative of a relatively strong association, meaning that unmeasured confounding would need to be at least twice as strong as the observed effect to explain it away. However, this is a heuristic, and the specific threshold for what is considered "high" may vary based on the field and the judgment of the researchers involved in a given study.

Update Docstrings

They should have separate sections for notes and references and not have "..." to sandwich the arguments section. The updated format should also be in the contributor guidelines.

Add doctests

While all of the examples in the documentation are from the unit tests and have all passed, it would be better to make as many doc tests as possible.

However, a lot of the tests give the expected output and fail even though they are correct, so we need to figure out how to get doctests working.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.