Skip to main content

Casual Inference

Project description

Causal inference is an important component of the experiment evaluation. We highly recommend to have a look at the open-source book: Causal Inference for The Brave and True

Please find the software documentation here: https://amazon-science.github.io/azcausal/latest/

Currently, azcausal provides two well-known and widely used causal inference methods: Difference-in-Difference (DID) and Synthetic Difference-in-Difference (SDID). Moreover, error estimates via Placebo, Boostrap, or JackKnife are available.

Installation

To install the current release, please execute:

pip install git+https://github.com/amazon-science/azcausal.git

Usage

from azcausal.core.error import JackKnife
from azcausal.core.panel import CausalPanel
from azcausal.data import CaliforniaProp99
from azcausal.estimators.panel.sdid import SDID
from azcausal.util import to_panels


# load an example data set with the columns Year, State, PacksPerCapita, treated.
df = CaliforniaProp99().df()

# create the panel data from the frame and define the causal types
data = to_panels(df, 'Year', 'State', ['PacksPerCapita', 'treated'])
ctypes = dict(outcome='PacksPerCapita', time='Year', unit='State', intervention='treated')

# initialize the panel
panel = CausalPanel(data).setup(**ctypes)

# initialize an estimator object, here synthetic difference in difference (sdid)
estimator = SDID()

# run the estimator
result = estimator.fit(panel)

# run the error validation method
estimator.error(result, JackKnife())

# plot the results
estimator.plot(result)

# print out information about the estimate
print(result.summary(title="CaliforniaProp99"))
╭──────────────────────────────────────────────────────────────────────────────╮
|                               CaliforniaProp99                               |
├──────────────────────────────────────────────────────────────────────────────┤
|                                    Panel                                     |
|  Time Periods: 31 (19/12)                                  total (pre/post)  |
|  Units: 39 (38/1)                                       total (contr/treat)  |
├──────────────────────────────────────────────────────────────────────────────┤
|                                     ATT                                      |
|  Effect (±SE): -15.60 (±2.9161)                                              |
|  Confidence Interval (95%): [-21.32 , -9.8884]                          (-)  |
|  Observed: 60.35                                                             |
|  Counter Factual: 75.95                                                      |
├──────────────────────────────────────────────────────────────────────────────┤
|                                  Percentage                                  |
|  Effect (±SE): -20.54 (±3.8393)                                              |
|  Confidence Interval (95%): [-28.07 , -13.02]                           (-)  |
|  Observed: 79.46                                                             |
|  Counter Factual: 100.00                                                     |
├──────────────────────────────────────────────────────────────────────────────┤
|                                  Cumulative                                  |
|  Effect (±SE): -187.25 (±34.99)                                              |
|  Confidence Interval (95%): [-255.83 , -118.66]                         (-)  |
|  Observed: 724.20                                                            |
|  Counter Factual: 911.45                                                     |
╰──────────────────────────────────────────────────────────────────────────────╯
docs/source/images/sdid.png

Estimators

Contact

Feel free to contact me if you have any questions:

Julian Blank (blankjul [at] amazon.com)
Amazon.com
Applied Scientist, Amazon
410 Terry Ave N, Seattle 98109, WA.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

azcausal-0.2.4.tar.gz (255.0 kB view details)

Uploaded Source

File details

Details for the file azcausal-0.2.4.tar.gz.

File metadata

  • Download URL: azcausal-0.2.4.tar.gz
  • Upload date:
  • Size: 255.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.16

File hashes

Hashes for azcausal-0.2.4.tar.gz
Algorithm Hash digest
SHA256 85205313f7a9be3fa91dff32240c21cec999cf797bcaa767d0901c05cbfc6207
MD5 46a4608c1be52c492d98b4dd5ecd5b61
BLAKE2b-256 bfaa5a15b3c910dd8eda0b4f7c0bd675ed3106c4f3bc19da53ed3522418d1747

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page