Created
January 21, 2019 15:42
-
-
Save akelleh/9b486a2208102476a1a7be770afe6a31 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "cells": [ | |
| { | |
| "cell_type": "code", | |
| "execution_count": 12, | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "from dowhy.do_why import CausalModel\n", | |
| "import dowhy.datasets\n" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 13, | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "data = dowhy.datasets.linear_dataset(beta=10,\n", | |
| " num_common_causes=5,\n", | |
| " num_instruments = 2,\n", | |
| " num_samples=1000,\n", | |
| " treatment_is_binary=True)\n" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 14, | |
| "metadata": { | |
| "scrolled": true | |
| }, | |
| "outputs": [ | |
| { | |
| "name": "stderr", | |
| "output_type": "stream", | |
| "text": [ | |
| "WARNING:dowhy.do_why:Causal Graph not provided. DoWhy will construct a graph based on data inputs.\n", | |
| "INFO:dowhy.causal_identifier:Common causes of treatment and outcome:{'X3', 'X0', 'X1', 'X4', 'U', 'X2'}\n" | |
| ] | |
| }, | |
| { | |
| "name": "stdout", | |
| "output_type": "stream", | |
| "text": [ | |
| "['X3', 'X1', 'X0', 'X4', 'X2']\n", | |
| "yes\n", | |
| "{'observed': 'yes'}\n", | |
| "yes\n", | |
| "{'observed': 'yes'}\n", | |
| "yes\n", | |
| "{'observed': 'yes'}\n", | |
| "yes\n", | |
| "{'observed': 'yes'}\n", | |
| "yes\n", | |
| "{'observed': 'yes'}\n", | |
| "Model to find the causal effect of treatment v on outcome y\n", | |
| "{'observed': 'yes'}\n", | |
| "{'observed': 'yes'}\n", | |
| "{'observed': 'yes'}\n", | |
| "{'observed': 'yes'}\n", | |
| "{'label': 'Unobserved Confounders', 'observed': 'no'}\n", | |
| "There are unobserved common causes. Causal effect cannot be identified.\n", | |
| "WARN: Do you want to continue by ignoring these unobserved confounders? [y/n] \n", | |
| "Please respond with 'y' or 'n'\n", | |
| "WARN: Do you want to continue by ignoring these unobserved confounders? [y/n] \n", | |
| "Please respond with 'y' or 'n'\n", | |
| "WARN: Do you want to continue by ignoring these unobserved confounders? [y/n] yes\n" | |
| ] | |
| }, | |
| { | |
| "name": "stderr", | |
| "output_type": "stream", | |
| "text": [ | |
| "INFO:dowhy.causal_identifier:Instrumental variables for treatment and outcome:[]\n" | |
| ] | |
| } | |
| ], | |
| "source": [ | |
| "model= CausalModel(\n", | |
| " data=data[\"df\"],\n", | |
| " treatment=data[\"treatment_name\"],\n", | |
| " outcome=data[\"outcome_name\"],\n", | |
| " common_causes=data[\"common_causes_names\"])\n", | |
| "\n", | |
| "identified_estimand = model.identify_effect()\n" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 15, | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "name": "stderr", | |
| "output_type": "stream", | |
| "text": [ | |
| "INFO:dowhy.causal_estimator:INFO: Using Linear Regression Estimator\n", | |
| "INFO:dowhy.causal_estimator:b: y~v+X3+X0+X1+X4+X2\n", | |
| "INFO:dowhy.causal_estimator:INFO: Using Linear Regression Estimator\n", | |
| "INFO:dowhy.causal_estimator:b: y~v+X3+X0+X1+X4+X2\n" | |
| ] | |
| }, | |
| { | |
| "name": "stdout", | |
| "output_type": "stream", | |
| "text": [ | |
| "LinearRegressionEstimator\n", | |
| "LinearRegressionEstimator\n" | |
| ] | |
| }, | |
| { | |
| "data": { | |
| "image/png": "iVBORw0KGgoAAAANSUhEUgAAAN8AAAASCAYAAADbjwtGAAAABHNCSVQICAgIfAhkiAAAAoZJREFUaIHt2rtrVEEUx/GPoo0i8VVYKAghauEfYJnYC4K2PkALCxXBQhCEdEkhPkhjpRbaCVpJtBBB7QQtRI0PjBZRG0mMImowFjuLYXPv3TCbvQw4P7jM7jnzO/Od4rD37h2ysrKS0F6M4AG+YhbX2ng24jIm8BPjuIA1EevH1KrDkypX3ktaXOtwGDfxBj8whYc4hKUVa3iq0XDTeKF98/Xic5h3C8O4F76/DDALVUytOjypcuW9pMd1JMQncB1DGk07GeI3sKRgDTCAvjChX/vmuxPmHGuJnwvxSxXexahVhydVrhhPqlwxnhS5dmKX+b9wG/AhzN9TsMY89atuvt6Qf1ew2Cp8w3esXMBaMbXq8KTKlfeSJleVTodaI81A5T1oGw2E8S7+tOSm8QgrsKNLterwpMqV95ImV5V+h3GmGeik+baG8VVJ/nUYt3SpVh2eVLliPKlyxXhS5SrTMuwPn0ebwU6aryeMUyX5Znx1l2rV4UmVK8aTKleMJ1WuMg1jO25rPEOis+bLyspqr+M4qfHP6L65iU6ar9n1PSX5ZnyyS7Xq8KTKFeNJlSvGkypXq47iIp5rPD9+mZvspPnGwlh2v9sXxrL75U5r1eFJlSvGkypXjCdVrrk6ofHP5jONxvtUUqNQ/fKrhlS58l7S5GrqVPA9wXoR6tedl+y92Ibli1Drf32ZG+tJlSvGkyrXmRB/jLUF9Uq1G1fDNRqKvJ0TO9syv/XozZB/R2/GFB/XGQ/5zYtQqw5Pqlx5L+lxHQjxGZzHYMF1sGANQnK24hov8GzCFXzEL7xXfVB1XHHzxdSqy5MqV95LWlyDqvtnFvcr1snKysrKysrKyspabP0Fsh8vMEoo1HYAAAAASUVORK5CYII=\n", | |
| "text/latex": [ | |
| "$$10.000000000000002$$" | |
| ], | |
| "text/plain": [ | |
| "10.000000000000002" | |
| ] | |
| }, | |
| "execution_count": 15, | |
| "metadata": {}, | |
| "output_type": "execute_result" | |
| } | |
| ], | |
| "source": [ | |
| "model.do(1., \n", | |
| " identified_estimand=identified_estimand,\n", | |
| " method_name=\"backdoor.linear_regression\",\n", | |
| " test_significance=False) - \\\n", | |
| "model.do(0., \n", | |
| " identified_estimand=identified_estimand,\n", | |
| " method_name=\"backdoor.linear_regression\",\n", | |
| " test_significance=False)" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [] | |
| } | |
| ], | |
| "metadata": { | |
| "kernelspec": { | |
| "display_name": "Python 3", | |
| "language": "python", | |
| "name": "python3" | |
| }, | |
| "language_info": { | |
| "codemirror_mode": { | |
| "name": "ipython", | |
| "version": 3 | |
| }, | |
| "file_extension": ".py", | |
| "mimetype": "text/x-python", | |
| "name": "python", | |
| "nbconvert_exporter": "python", | |
| "pygments_lexer": "ipython3", | |
| "version": "3.6.7" | |
| } | |
| }, | |
| "nbformat": 4, | |
| "nbformat_minor": 2 | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment