Giter Site home page Giter Site logo

IPW computation about causallib HOT 3 CLOSED

winston-zillow avatar winston-zillow commented on May 20, 2024
IPW computation

from causallib.

Comments (3)

ehudkr avatar ehudkr commented on May 20, 2024

Hi Winston, not a bug 🙃 🐞

The equation you presented is limited to binary treatment scenarios, while causallib's implementation scales to arbitrary number of treatment values.
Reformulating your equation in the binary case, treated observations ($A_i=1$) are weighted with $\frac{1}{\Pr[A=1|X]}$ and control observations ($A_i=0$) are weighted with $\frac{1}{1-\Pr[A=1|X]} = \frac{1}{\Pr[A=0|X]}$. The generalization is therefore quite straightforward if we observe that each observation $i$ is weighted by the inverse probability of being assigned to their observed treatment group: $w_i=\frac{1}{\Pr[A=a_i|X=x_i]}$.
Causallib's implementation tries to make the most generalized calculation by first considering for each $i$ the probabilities for every possible treatment (hence the probabilities matrix, which is similar to the output of a predict_proba()), and only slicing for the required values according to the treatment assignment at the very end.

Thanks for bringing this up, and sorry for causing any confusion. I hope I was able to clear some of it up.
Please feel free if there's anything else.

from causallib.

ehudkr avatar ehudkr commented on May 20, 2024

To justify this further. There are other small benefits to this implementation that I have yet to seize.
For example, generalizing the average treatment effect on the treated/controls (ATT/ATC) to any arbitrary treatment level v can be simply done by multiplying the inverse probability matrix (weight_matrix) by the corresponding probability column: weight_matrix *= probabilities[v]. Then the column corresponding to v is all ones ($p_{i,v}$ times its inverse) and all the rest of the columns are the odds with respect to v.

I hope this gives better context to the design decisions.

from causallib.

winston-zillow avatar winston-zillow commented on May 20, 2024

I see. You turn the binary one-class label to a multi-class label first. That works. Thanks.

from causallib.

Related Issues (18)

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.