Updating the docs and notebook for v0.7 (#371)

* updated docstrings to make sure they are in correct format

* Removed output from notebooks

* updated notebooks to fix any bugs

* updated refuter notebook

* updated format
This commit is contained in:
Amit Sharma 2022-02-03 09:17:38 +05:30 коммит произвёл GitHub
Родитель 5f2cd0963d
Коммит a676c595a5
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
36 изменённых файлов: 1008 добавлений и 23536 удалений

Просмотреть файл

@ -46,7 +46,7 @@ extensions = [
'sphinx_rtd_theme'
]
autodoc_mock_imports = ['matplotlib', 'causalml', 'pymc3']
autodoc_mock_imports = ['matplotlib', 'causalml', 'pymc3', 'econml']
# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']

Различия файлов скрыты, потому что одна или несколько строк слишком длинны

Просмотреть файл

@ -61,7 +61,7 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
@ -71,7 +71,7 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": null,
"metadata": {
"scrolled": true
},
@ -84,7 +84,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
@ -99,31 +99,9 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The history saving thread hit an unexpected error (OperationalError('disk I/O error')).History will not be written to the database.\n"
]
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAOAAAAASCAYAAABCd9LzAAAGfUlEQVR4nO3beYxfVRUH8E+xCMhSV2yMRuxItSra4opKtRpGU6MpxkRjwCWhxoAB0RK1Cp1qiLhQwQ1wQygJxgUXoqJYG7HiEmONEkVrbQsVWSoOAi0VEf849zFv3rw387v3Nz/qH79vMrlvOfd+z++8c+5y7p05Y2NjhhhiiH2D/Rr3r8On8FP8C/fjsj45Xo5v4mbsxU34AZa3yD4eX0oye7Ed5+ER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R5+nnZUz8drz3I5Snhy5efiUjGVPLOtQgdKfv90uDCVS2eQu0XsbY2KPb1Le2i7pM50yLVZqY1LMJ7KXn3sPrE2fq+YGbw5/W0RWxB3Jrlbq0YGFYB/SuV4x/t/pvKghvzCDvkq01ZfI+VylPDkyh+SZBeJdUN9Y3xNkvl8uj+vD71mQjUt7DVrukP02E/HowdYpw25Niu1cQlKfOxecXjhKBwolg0rRAAfKdaJ2yrhQSVhNggDPE0EeTOzVy1mK0Wq/ZjRFvlDxSb0bvyiD44Snlz5vfiidhwt1iybxIetT51Kfv90qLKlbdm4LjwulfcNuE4TuTYrtXEJSnysC28Q2c/L6w/7DcARscDcavJ+yA5cKebNp+ETtXejeIXoVa5Kz7aKRe0oTjF5I3qt6MkvMnmfJ5ejhCdXfo/uY1BjwjkuwRca70p+/yKxpmjufR0hToUw+ZjVQjF9bCZ69sOHRMLhWhO9emmdXJTYrMTGJSjxscPEMbc6FuNjwk6TssbNAFyR/pjY0zgGX07Xu0w+abABTxRp1+2Ntk4Rxlgn9k82J7kVosc8yeQPe7L4mJ8Umb0/isX2MjH1er+pyOUo4SnRqwS5PK/Hu0UqfIdYX4wIOxwojkd9vCa/HB8Wo8M2cXLksSKJsECccVzZ4CipQ74fPVhYIV+vXB+7WnQq14lvsijV2yPWhzfVG28G4GKxaKxjgYk9jB0tCnZhpzgrd5boQZaKnuFK8VF/1ZDfKvaXPijOPi7H30UWaa32XjaXo4SnRK8S5PJsFPuHS8QU9WDRG28S+2PrTT7x8SM8WWwhLBFrk7tFcK8XgX97g6OkDrPrR7OJxfL1yvWxr4vp5glibfg3fC7J7mwqNGf470hDDLHvMKgs6BBDDNEDhgE4xBD7EP8DGMvLynEwDHwAAAAASUVORK5CYII=\n",
"text/latex": [
"$\\displaystyle 1.6060040533144169$"
],
"text/plain": [
"1.6060040533144169"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"outputs": [],
"source": [
"(df[df.D == 1].mean() - df[df.D == 0].mean())['Y']"
]
@ -137,7 +115,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
@ -162,7 +140,7 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
@ -178,7 +156,7 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
@ -203,7 +181,7 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
@ -212,24 +190,9 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAOAAAAASCAYAAABCd9LzAAAH3klEQVR4nO3ae7BVVR0H8A9yDUwNyMI7pQXcoqg01CIzIJGkB2bSa5xGsyYlJx2iwnScUS/NNEApidUUvY2cXmZmo+GTEelBU+KkYwoJVwQfQYhhQCnUH7+1u/vuu8+55+wDl3/Od+bM2mft39rrtx6/51pDuru7tdFGGwcGB5XUHYXv4XH8Gz24GqOa/PYQnIfVeBb/wp9wfo1+m6Wvym+VfmbiNmzCLqzHz/HWGvQ9+G+N35MHcCxV+FqEO/GYGPs2rMEVOKKE/gici1/ib6nNM1iFT9Tgq9k2H6szjuy3p8Z4YHrq60kxz4/jVrynBn0rMnFWjqdziy+HFCxgF36H0fgVHsIkTMPDeBv+0UCncB0+gr/jJuzEqZiAZfhoi/RV+W22n0X4fPrOjdiKV+F0dCT6HxXa9GCkWKQinsWVB2gsVfj6D+7Fg6mfQ3Ei3iQ25IlCODOcj2/gCazARhyJ92MEfoEPiQ1Ztc1EnFHCK0zBKbgZp5W8/xIuEsr0N2I9X4oTcIdY6zxakYmjcT+G4jChLL+TJygK4K2YgTn4aq5+MT6DpWKyBsIs3IANidmtqf4FYjJPwwcSTRX6qvw2208nNmMLjhUbMMM03JW+Na7AV08qx2gc+3ssVfkajt0l9V/E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ffzLp0iLlYqzcJNiDyMeDDqRxfgzbLdtXyh4t4TmzeRYX64elbW0XsUZW+Kr/N9JOdI60o+f5OkSKfJVyOsmRIEZm7VsyaDcZYqvBVD48KAZkoElRbS2jm4ivC0k7XmDKo0qZe8iVDNsfba7x/OpWHlLRpZF0Oy9HVyhx/O/2WiHH2EcBsk80QljHvuhwuDhx34g81Pt4ozhSZuR+3SL+v+S3rZ1gqax01ZPVlKe0yZNmyorAOxliq8DUQXpbKsk1/sYjh7hMZyDIB3RdthgsXdY8QwFq4U8R+r9N/julNyuQVVjPrsrdO/8cLJb1KCPX/3dO8C/qICEbH4ILCB+YL7bhM3zONLrxWBP5FvKikbiK+LLRNMXvWLH0Vfpvt555UzsbLC23eLRZgt7gpkWGCcksyBl9Lz8WbM4Mxlip8jVfufh0kztRGi7E/XXh/Wer7z8KKNSJIVdoQCbFRIolUlnzJ8Kg4a3yFOHrIYwbeKaxjPtvazLrsElfNyn7ZhYBr0/+fZh8Z6CraX0VgOU2Y2ZP0vXbTIw6rx+rvV69OTD0g4pEJ4uxll4hdiinvZumr8NtsPweJ2OAdiTa7PzhBuKdDhCuxJNemW8SFK8Wi70h8zhTa+hbhthat5v4eSxW+5mKB0NwbUv9HimTFuDQX04UrmuEckbDaI26OlGUQexJNK20y3COysqcLAauHo8QcHy0s4hqxd88Q1vFM/W/bVFmXIrpFBrnfTZiOAuEj4oznC3iXuJz6hNhg8/XXdPVwvRjQWcKv3iyuAS0QwXKr9FX5baafvembF6Q2s8TB6zaxYa8RGjKPFeL86DhhIQ8VmnWV0JbL9L0HOVhjqcLXHeLe6+TUbqTQ9msT/TX6J0iyc8mhUpxTgrv1FaYqbQiFM1n95Esem0QG+3IhsFPxTyG4C0RMX8S+lIl+KFrANtpoYxCxv84B22ijjQbQFsA22jiA+B8ooTw7JS7HWgAAAABJRU5ErkJggg==\n",
"text/latex": [
"$\\displaystyle 0.9909850953227604$"
],
"text/plain": [
"0.9909850953227604"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"outputs": [],
"source": [
"(interventional_df[interventional_df.D == 1].mean() - interventional_df[interventional_df.D == 0].mean())['Y']"
]

Различия файлов скрыты, потому что одна или несколько строк слишком длинны

Различия файлов скрыты, потому что одна или несколько строк слишком длинны

Просмотреть файл

@ -10,7 +10,7 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
@ -25,129 +25,9 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>W0</th>\n",
" <th>v0</th>\n",
" <th>y</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>0.883800</td>\n",
" <td>True</td>\n",
" <td>6.032204</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>2.151652</td>\n",
" <td>True</td>\n",
" <td>8.274524</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>0.565327</td>\n",
" <td>True</td>\n",
" <td>5.615925</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>1.943763</td>\n",
" <td>True</td>\n",
" <td>9.943361</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>1.025108</td>\n",
" <td>True</td>\n",
" <td>6.526274</td>\n",
" </tr>\n",
" <tr>\n",
" <th>...</th>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>995</th>\n",
" <td>-1.452482</td>\n",
" <td>False</td>\n",
" <td>-1.081065</td>\n",
" </tr>\n",
" <tr>\n",
" <th>996</th>\n",
" <td>1.532964</td>\n",
" <td>False</td>\n",
" <td>2.817101</td>\n",
" </tr>\n",
" <tr>\n",
" <th>997</th>\n",
" <td>-0.350965</td>\n",
" <td>True</td>\n",
" <td>1.761346</td>\n",
" </tr>\n",
" <tr>\n",
" <th>998</th>\n",
" <td>-1.642007</td>\n",
" <td>False</td>\n",
" <td>-3.852874</td>\n",
" </tr>\n",
" <tr>\n",
" <th>999</th>\n",
" <td>0.641072</td>\n",
" <td>False</td>\n",
" <td>2.620429</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>1000 rows × 3 columns</p>\n",
"</div>"
],
"text/plain": [
" W0 v0 y\n",
"0 0.883800 True 6.032204\n",
"1 2.151652 True 8.274524\n",
"2 0.565327 True 5.615925\n",
"3 1.943763 True 9.943361\n",
"4 1.025108 True 6.526274\n",
".. ... ... ...\n",
"995 -1.452482 False -1.081065\n",
"996 1.532964 False 2.817101\n",
"997 -0.350965 True 1.761346\n",
"998 -1.642007 False -3.852874\n",
"999 0.641072 False 2.620429\n",
"\n",
"[1000 rows x 3 columns]"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"outputs": [],
"source": [
"data = dowhy.datasets.linear_dataset(beta=5,\n",
" num_common_causes=1,\n",
@ -166,32 +46,9 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<AxesSubplot:xlabel='v0'>"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAWoAAAEWCAYAAABPON1ZAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjMuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8vihELAAAACXBIWXMAAAsTAAALEwEAmpwYAAAN7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1AGOMpY9CbL+s/puGlnSipOcXHhKnkANji1ADQHEsfQBAcYQaAIoj1Bgrtj9i+78Gl490PQ/QBGvUGBu23yJpVtKM+kfV7Jb000me6XQwYBmcQo5VyfbVkh4bfDGwbP+BpJcl3bFwhp3tOyRdLOmLXc0JNMHSB1arL0n65UW3F64/tui+OfU/BB8ojT1qrEpJ9tg+zfZbJfUkPaP+56dMvP7/BOphjxqr2S2SPqT+t7p/SdLjks5Y9PjU4D6gNN5MxKpl+52SPifpVEk/L+kF9d9APGewyf3qv5nIp8KhNJY+sGolecj2BkmPJ3lCkmx/RtJ9g00+TaTxRsAeNQAUxxo1ABRHqAGgOEINAMURagAojlADQHGEGgCKI9QAUByhBoDi/h84tCMtUDB++gAAAABJRU5ErkJggg==\n",
"text/plain": [
"<Figure size 432x288 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"outputs": [],
"source": [
"# data['df'] is just a regular pandas.DataFrame\n",
"df.causal.do(x=treatment,\n",
@ -203,32 +60,9 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<AxesSubplot:xlabel='v0'>"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAWoAAAERCAYAAABSPe3hAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjMuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8vihELAAAACXBIWXMAAAsTAAALEwEAmpwYAAAMQ0lEQVR4nO3db4ylZ1nH8d/F7jarsrGyHYyy1GlCgxYMto7lBQbTNkoRoyEhCkkNcSX7QiUYNQZDbPwTDb4xrQkxWQErEalWICEQK41CDAktnW2r0FYiadBOpXRYIAKx0HYvX8xMO61T5szuOXvuPfv5JJPOM+eZZ68Xm2/v3HOf2eruADCu58x7AAC+PaEGGJxQAwxOqAEGJ9QAg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NgToWahVdXFO329u//rbM8Cp0uoWWhV9els7E9XkoNJLkny2e5+yVwHgz1w6oOF1t0/vP26qq5I8itzGgdOixU1552q+vQzAw4js6JmoVXVb2y7fE6SK5L895zGgdMi1Cy6Q9s+fzzJR5K8f06zwGkRahbW5htdDnX3b817FjgT3vDCQqqq/d39RJJXzHsWOFNW1CyqT2VjP/qeqvpQkluSfGPrxe7+wLwGg70SahbdwSQnk1ydp85TdxKh5pwh1Cyq52+e+PhMngr0FmdSOacINYtqX5Ln5umB3iLUnFO84YWFVFV3dfcV854DpsGpDxbVTitpOCdZUbOQqup53f3lec8B0yDUAIOz9QEwOKEGGJxQc16pqjdW1X9sfrxx3vPAJOxRc96oquclWU2yko2z1CeS/Gh3f2Wug8EuvOGFhVRVb0/yYHe/Y/P695I8keS2rdMgVXVbkmuTvG9ec8IkbH2wqP42yc9vu976/MFtX1tL8oKzNhGcJitqFlJ3311Vz6+q70+ylOQrSf43G7+kCc4pVtQssluSvC7JL2Rjhf1Qkhdue/3I5tdgaH6YyMKqqpck+YskFyX5iSTfzMYPELd+B8hd2fhhoncwMjRbHyys7r63qg4leai7v5AkVfWHSe7cvOUPRJpzgRU1wODsUQMMTqgBBifUAIMTaoDBCTXA4IQaYHBCDTC4/wNMrZa1m17lQQAAAABJRU5ErkJggg==\n",
"text/plain": [
"<Figure size 432x288 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"outputs": [],
"source": [
"df.causal.do(x={treatment: 1}, \n",
" variable_types={treatment:'b', outcome: 'c', common_cause: 'c'}, \n",
@ -240,7 +74,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
@ -259,308 +93,20 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": null,
"metadata": {
"scrolled": true
},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>W0</th>\n",
" <th>v0</th>\n",
" <th>y</th>\n",
" <th>propensity_score</th>\n",
" <th>weight</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>1.117996</td>\n",
" <td>False</td>\n",
" <td>2.497059</td>\n",
" <td>0.333225</td>\n",
" <td>3.000976</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>0.238462</td>\n",
" <td>False</td>\n",
" <td>0.509070</td>\n",
" <td>0.455258</td>\n",
" <td>2.196556</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>0.213945</td>\n",
" <td>False</td>\n",
" <td>2.279505</td>\n",
" <td>0.458815</td>\n",
" <td>2.179528</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>0.425245</td>\n",
" <td>False</td>\n",
" <td>-0.297296</td>\n",
" <td>0.428336</td>\n",
" <td>2.334615</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>2.301323</td>\n",
" <td>False</td>\n",
" <td>3.431520</td>\n",
" <td>0.200139</td>\n",
" <td>4.996525</td>\n",
" </tr>\n",
" <tr>\n",
" <th>...</th>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>995</th>\n",
" <td>0.621286</td>\n",
" <td>False</td>\n",
" <td>1.458936</td>\n",
" <td>0.400531</td>\n",
" <td>2.496683</td>\n",
" </tr>\n",
" <tr>\n",
" <th>996</th>\n",
" <td>1.642750</td>\n",
" <td>False</td>\n",
" <td>3.409962</td>\n",
" <td>0.268860</td>\n",
" <td>3.719407</td>\n",
" </tr>\n",
" <tr>\n",
" <th>997</th>\n",
" <td>0.409933</td>\n",
" <td>False</td>\n",
" <td>-0.635569</td>\n",
" <td>0.430529</td>\n",
" <td>2.322722</td>\n",
" </tr>\n",
" <tr>\n",
" <th>998</th>\n",
" <td>-0.063154</td>\n",
" <td>False</td>\n",
" <td>0.953209</td>\n",
" <td>0.499221</td>\n",
" <td>2.003123</td>\n",
" </tr>\n",
" <tr>\n",
" <th>999</th>\n",
" <td>1.532964</td>\n",
" <td>False</td>\n",
" <td>2.817101</td>\n",
" <td>0.281662</td>\n",
" <td>3.550353</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>1000 rows × 5 columns</p>\n",
"</div>"
],
"text/plain": [
" W0 v0 y propensity_score weight\n",
"0 1.117996 False 2.497059 0.333225 3.000976\n",
"1 0.238462 False 0.509070 0.455258 2.196556\n",
"2 0.213945 False 2.279505 0.458815 2.179528\n",
"3 0.425245 False -0.297296 0.428336 2.334615\n",
"4 2.301323 False 3.431520 0.200139 4.996525\n",
".. ... ... ... ... ...\n",
"995 0.621286 False 1.458936 0.400531 2.496683\n",
"996 1.642750 False 3.409962 0.268860 3.719407\n",
"997 0.409933 False -0.635569 0.430529 2.322722\n",
"998 -0.063154 False 0.953209 0.499221 2.003123\n",
"999 1.532964 False 2.817101 0.281662 3.550353\n",
"\n",
"[1000 rows x 5 columns]"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"outputs": [],
"source": [
"cdf_0"
]
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>W0</th>\n",
" <th>v0</th>\n",
" <th>y</th>\n",
" <th>propensity_score</th>\n",
" <th>weight</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>1.055191</td>\n",
" <td>True</td>\n",
" <td>5.738184</td>\n",
" <td>0.658568</td>\n",
" <td>1.518446</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>1.676538</td>\n",
" <td>True</td>\n",
" <td>7.187013</td>\n",
" <td>0.735005</td>\n",
" <td>1.360535</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>0.111945</td>\n",
" <td>True</td>\n",
" <td>4.353155</td>\n",
" <td>0.526346</td>\n",
" <td>1.899889</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>-0.840229</td>\n",
" <td>True</td>\n",
" <td>3.503758</td>\n",
" <td>0.389082</td>\n",
" <td>2.570151</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>0.556640</td>\n",
" <td>True</td>\n",
" <td>5.125285</td>\n",
" <td>0.590361</td>\n",
" <td>1.693878</td>\n",
" </tr>\n",
" <tr>\n",
" <th>...</th>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>995</th>\n",
" <td>0.018338</td>\n",
" <td>True</td>\n",
" <td>6.145009</td>\n",
" <td>0.512687</td>\n",
" <td>1.950507</td>\n",
" </tr>\n",
" <tr>\n",
" <th>996</th>\n",
" <td>0.094625</td>\n",
" <td>True</td>\n",
" <td>5.329991</td>\n",
" <td>0.523821</td>\n",
" <td>1.909048</td>\n",
" </tr>\n",
" <tr>\n",
" <th>997</th>\n",
" <td>0.711712</td>\n",
" <td>True</td>\n",
" <td>4.394407</td>\n",
" <td>0.612092</td>\n",
" <td>1.633741</td>\n",
" </tr>\n",
" <tr>\n",
" <th>998</th>\n",
" <td>1.928415</td>\n",
" <td>True</td>\n",
" <td>8.157832</td>\n",
" <td>0.762678</td>\n",
" <td>1.311169</td>\n",
" </tr>\n",
" <tr>\n",
" <th>999</th>\n",
" <td>-0.280647</td>\n",
" <td>True</td>\n",
" <td>5.377214</td>\n",
" <td>0.469032</td>\n",
" <td>2.132052</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>1000 rows × 5 columns</p>\n",
"</div>"
],
"text/plain": [
" W0 v0 y propensity_score weight\n",
"0 1.055191 True 5.738184 0.658568 1.518446\n",
"1 1.676538 True 7.187013 0.735005 1.360535\n",
"2 0.111945 True 4.353155 0.526346 1.899889\n",
"3 -0.840229 True 3.503758 0.389082 2.570151\n",
"4 0.556640 True 5.125285 0.590361 1.693878\n",
".. ... ... ... ... ...\n",
"995 0.018338 True 6.145009 0.512687 1.950507\n",
"996 0.094625 True 5.329991 0.523821 1.909048\n",
"997 0.711712 True 4.394407 0.612092 1.633741\n",
"998 1.928415 True 8.157832 0.762678 1.311169\n",
"999 -0.280647 True 5.377214 0.469032 2.132052\n",
"\n",
"[1000 rows x 5 columns]"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"outputs": [],
"source": [
"cdf_1"
]
@ -575,48 +121,18 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAANEAAAASCAYAAADFRjv1AAAHDUlEQVR4nO3ba6xdRRUH8F+hiMqjPmk1PqDVao2PVhStCoLIVVttwEc0BkRjawySWrQErVZuMYSiItY3vniUBKNSX6GiWBtrxUdUjBIESu0t1IpQ4ZaWtggFP6zZufvuu/e5Z/a5fvL8k5M5Z/bsWeu/7sysNWvmThocHNRHH320xwGV30N4pOFzZ4v+n4ZvYTseSP1/Do+vaTsJi/A77Mb9+APeX6MnPBEL8X3chr3YiY14b8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I/4LHNPNtgrpX74AAAAASUVORK5CYII=\n",
"text/latex": [
"$\\displaystyle 5.092590494260132$"
],
"text/plain": [
"5.092590494260132"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"outputs": [],
"source": [
"(cdf_1['y'] - cdf_0['y']).mean()"
]
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAOwAAAASCAYAAABYSzJ9AAAGl0lEQVR4nO3be6weRRkG8F9JVVQQDIqN0RiooA1BCxoUpUK9NCgYW29RA4qJVgMGgzaIF+yphggatNRbEMUbBqIV1FgvFSQRvGAMNMagUlpEWgSFolRbwBT9450vZ89+3+7ZmbPnaJPvSb7M6e7MvvM+z+zMO+9s501MTBhjjDH2Duwz4tpTcCnuxIP4E9bi8ZnPfi0+jetwP/6Dyxrqnpbut/32dLB5SqX+23q0cxI2Yht2Yyu+hWNb+lLCY06bEl/m4e24Af/Ev/AbvNPosQAX4BrcIXzfgZuwGgc1tMnRvgnTaUk+xyX+U6Z/Vz9Ok6Hj/FrjhfgFDsZ38Qccg3fjRLwQ93boJHwIzxbEbMMzW+puwpqGe0vwYvxwGntPxWeSvf16tHMBzhZ+fwf34Ol4FV6DNxsejCU85rYp8eUyvAl/xeXYhZfh83hB8qWOs3AjfpLaPRbPxwRWpr/vqLXJ0X4UumhZwnGJ/yX65/ixSYaO9Rf2c4KAM8UMOcAnhXDnidmoC84SYt2K43FtS91N6TcKv0zlF1raz8OXBalXYlVPdhakZ92NZwmhB1iKn+IjhgUr4TG3Ta4vK8RgvU0M7HvS9Ufi2zhVDMgra896HB4YYeM8fADvx+m1ezna19FVy1y+Svwv1T/Hj00ydKyGAQuxTIQVn601XC3Ch1PFDNsF12KzWNJLcaSYwbdjQ0u9M8VM9FbRz77sPE1wdIOpYhH+7cQTa9dLeOyT+yZfVqTyQpODFR7Cuenvd4143qiXFb6ZysNG3JuJ9l20LOG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mT9S6fTk/F1eAl+LzbSS0V48cFa/WvE4fIhIqyoYnn6MXkGdqzYvBPhx6ivPwYhQduXTX2gi5314pztpYKLq3CXCHtOFkmYcwx/ApfLY2mbHF+IY4jd+J3Ysy0S38nuFvu7O2v1XyGOMa4XoeK9IlN8vNi33WVq5nSA5cq0z0EJX7n+l+pfiml1rL+wW/Bc8bnViUKwv4hs2hp5M+lisamv4lCTCZrbDYu2SKTDmxInfaGrnYcFB2eIsGmFOJDfkdqtEzN9HSU8lnKfw9n65Mcp4qxvu8mzxW0j6l8tvps9TqwQB4pV6xZx1rjO5PFIFYvla5+LEr5y/S/VvwSddJw3/u91Y4yx9+D/+Rx2jDHGqGH8wo4xxl6E/wI6U/UPXeefgQAAAABJRU5ErkJggg==\n",
"text/latex": [
"$\\displaystyle 0.17478007931409847$"
],
"text/plain": [
"0.17478007931409847"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"outputs": [],
"source": [
"1.96*(cdf_1['y'] - cdf_0['y']).std() / np.sqrt(len(df))"
]
@ -630,105 +146,9 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<table class=\"simpletable\">\n",
"<caption>OLS Regression Results</caption>\n",
"<tr>\n",
" <th>Dep. Variable:</th> <td>y</td> <th> R-squared (uncentered):</th> <td> 0.970</td> \n",
"</tr>\n",
"<tr>\n",
" <th>Model:</th> <td>OLS</td> <th> Adj. R-squared (uncentered):</th> <td> 0.970</td> \n",
"</tr>\n",
"<tr>\n",
" <th>Method:</th> <td>Least Squares</td> <th> F-statistic: </th> <td>1.620e+04</td>\n",
"</tr>\n",
"<tr>\n",
" <th>Date:</th> <td>Tue, 02 Mar 2021</td> <th> Prob (F-statistic):</th> <td> 0.00</td> \n",
"</tr>\n",
"<tr>\n",
" <th>Time:</th> <td>20:29:26</td> <th> Log-Likelihood: </th> <td> -1414.1</td> \n",
"</tr>\n",
"<tr>\n",
" <th>No. Observations:</th> <td> 1000</td> <th> AIC: </th> <td> 2832.</td> \n",
"</tr>\n",
"<tr>\n",
" <th>Df Residuals:</th> <td> 998</td> <th> BIC: </th> <td> 2842.</td> \n",
"</tr>\n",
"<tr>\n",
" <th>Df Model:</th> <td> 2</td> <th> </th> <td> </td> \n",
"</tr>\n",
"<tr>\n",
" <th>Covariance Type:</th> <td>nonrobust</td> <th> </th> <td> </td> \n",
"</tr>\n",
"</table>\n",
"<table class=\"simpletable\">\n",
"<tr>\n",
" <td></td> <th>coef</th> <th>std err</th> <th>t</th> <th>P>|t|</th> <th>[0.025</th> <th>0.975]</th> \n",
"</tr>\n",
"<tr>\n",
" <th>x1</th> <td> 1.7444</td> <td> 0.031</td> <td> 55.843</td> <td> 0.000</td> <td> 1.683</td> <td> 1.806</td>\n",
"</tr>\n",
"<tr>\n",
" <th>x2</th> <td> 5.0338</td> <td> 0.052</td> <td> 97.742</td> <td> 0.000</td> <td> 4.933</td> <td> 5.135</td>\n",
"</tr>\n",
"</table>\n",
"<table class=\"simpletable\">\n",
"<tr>\n",
" <th>Omnibus:</th> <td> 4.501</td> <th> Durbin-Watson: </th> <td> 1.900</td>\n",
"</tr>\n",
"<tr>\n",
" <th>Prob(Omnibus):</th> <td> 0.105</td> <th> Jarque-Bera (JB): </th> <td> 4.538</td>\n",
"</tr>\n",
"<tr>\n",
" <th>Skew:</th> <td> 0.147</td> <th> Prob(JB): </th> <td> 0.103</td>\n",
"</tr>\n",
"<tr>\n",
" <th>Kurtosis:</th> <td> 2.851</td> <th> Cond. No. </th> <td> 2.50</td>\n",
"</tr>\n",
"</table><br/><br/>Notes:<br/>[1] R² is computed without centering (uncentered) since the model does not contain a constant.<br/>[2] Standard Errors assume that the covariance matrix of the errors is correctly specified."
],
"text/plain": [
"<class 'statsmodels.iolib.summary.Summary'>\n",
"\"\"\"\n",
" OLS Regression Results \n",
"=======================================================================================\n",
"Dep. Variable: y R-squared (uncentered): 0.970\n",
"Model: OLS Adj. R-squared (uncentered): 0.970\n",
"Method: Least Squares F-statistic: 1.620e+04\n",
"Date: Tue, 02 Mar 2021 Prob (F-statistic): 0.00\n",
"Time: 20:29:26 Log-Likelihood: -1414.1\n",
"No. Observations: 1000 AIC: 2832.\n",
"Df Residuals: 998 BIC: 2842.\n",
"Df Model: 2 \n",
"Covariance Type: nonrobust \n",
"==============================================================================\n",
" coef std err t P>|t| [0.025 0.975]\n",
"------------------------------------------------------------------------------\n",
"x1 1.7444 0.031 55.843 0.000 1.683 1.806\n",
"x2 5.0338 0.052 97.742 0.000 4.933 5.135\n",
"==============================================================================\n",
"Omnibus: 4.501 Durbin-Watson: 1.900\n",
"Prob(Omnibus): 0.105 Jarque-Bera (JB): 4.538\n",
"Skew: 0.147 Prob(JB): 0.103\n",
"Kurtosis: 2.851 Cond. No. 2.50\n",
"==============================================================================\n",
"\n",
"Notes:\n",
"[1] R² is computed without centering (uncentered) since the model does not contain a constant.\n",
"[2] Standard Errors assume that the covariance matrix of the errors is correctly specified.\n",
"\"\"\""
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"outputs": [],
"source": [
"model = OLS(np.asarray(df[outcome]), np.asarray(df[[common_cause, treatment]], dtype=np.float64))\n",
"result = model.fit()\n",

Различия файлов скрыты, потому что одна или несколько строк слишком длинны

Различия файлов скрыты, потому что одна или несколько строк слишком длинны

Просмотреть файл

@ -17,7 +17,7 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
@ -60,96 +60,9 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>Z0</th>\n",
" <th>W0</th>\n",
" <th>W1</th>\n",
" <th>v0</th>\n",
" <th>y</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>1.0</td>\n",
" <td>0.112689</td>\n",
" <td>-0.501474</td>\n",
" <td>8.076574</td>\n",
" <td>80.106461</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>0.0</td>\n",
" <td>0.645347</td>\n",
" <td>-0.072829</td>\n",
" <td>-0.219279</td>\n",
" <td>-0.092377</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>0.0</td>\n",
" <td>0.323480</td>\n",
" <td>0.989825</td>\n",
" <td>0.365947</td>\n",
" <td>6.900517</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>0.0</td>\n",
" <td>0.030437</td>\n",
" <td>1.334423</td>\n",
" <td>1.740524</td>\n",
" <td>20.319910</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>1.0</td>\n",
" <td>1.377841</td>\n",
" <td>0.628397</td>\n",
" <td>11.938058</td>\n",
" <td>125.523936</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Z0 W0 W1 v0 y\n",
"0 1.0 0.112689 -0.501474 8.076574 80.106461\n",
"1 0.0 0.645347 -0.072829 -0.219279 -0.092377\n",
"2 0.0 0.323480 0.989825 0.365947 6.900517\n",
"3 0.0 0.030437 1.334423 1.740524 20.319910\n",
"4 1.0 1.377841 0.628397 11.938058 125.523936"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"outputs": [],
"source": [
"# Value of the coefficient [BETA]\n",
"BETA = 10\n",
@ -178,7 +91,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
@ -193,7 +106,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
@ -218,37 +131,9 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Estimand type: nonparametric-ate\n",
"\n",
"### Estimand : 1\n",
"Estimand name: backdoor\n",
"Estimand expression:\n",
" d \n",
"─────(Expectation(y|W1,W0))\n",
"d[v₀] \n",
"Estimand assumption 1, Unconfoundedness: If U→{v0} and U→y then P(y|v0,W1,W0,U) = P(y|v0,W1,W0)\n",
"\n",
"### Estimand : 2\n",
"Estimand name: iv\n",
"Estimand expression:\n",
"Expectation(Derivative(y, [Z0])*Derivative([v0], [Z0])**(-1))\n",
"Estimand assumption 1, As-if-random: If U→→y then ¬(U →→{Z0})\n",
"Estimand assumption 2, Exclusion: If we remove {Z0}→{v0}, then ¬({Z0}→y)\n",
"\n",
"### Estimand : 3\n",
"Estimand name: frontdoor\n",
"No such variable found!\n",
"\n"
]
}
],
"outputs": [],
"source": [
"identified_estimand = model.identify_effect(proceed_when_unidentifiable=True)\n",
"print(identified_estimand)"
@ -263,46 +148,11 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": null,
"metadata": {
"scrolled": true
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"*** Causal Estimate ***\n",
"\n",
"## Identified estimand\n",
"Estimand type: nonparametric-ate\n",
"\n",
"### Estimand : 1\n",
"Estimand name: iv\n",
"Estimand expression:\n",
"Expectation(Derivative(y, [Z0])*Derivative([v0], [Z0])**(-1))\n",
"Estimand assumption 1, As-if-random: If U→→y then ¬(U →→{Z0})\n",
"Estimand assumption 2, Exclusion: If we remove {Z0}→{v0}, then ¬({Z0}→y)\n",
"\n",
"## Realized estimand\n",
"Realized estimand: Wald Estimator\n",
"Realized estimand type: nonparametric-ate\n",
"Estimand expression:\n",
" -1\n",
"Expectation(Derivative(y, Z0))⋅Expectation(Derivative(v0, Z0)) \n",
"Estimand assumption 1, As-if-random: If U→→y then ¬(U →→{Z0})\n",
"Estimand assumption 2, Exclusion: If we remove {Z0}→{v0}, then ¬({Z0}→y)\n",
"Estimand assumption 3, treatment_effect_homogeneity: Each unit's treatment ['v0'] is affected in the same way by common causes of ['v0'] and y\n",
"Estimand assumption 4, outcome_effect_homogeneity: Each unit's outcome y is affected in the same way by common causes of ['v0'] and y\n",
"\n",
"Target units: ate\n",
"\n",
"## Estimate\n",
"Mean value: 9.99706705820163\n",
"\n"
]
}
],
"outputs": [],
"source": [
"causal_estimate = model.estimate_effect( identified_estimand,\n",
" method_name=\"iv.instrumental_variable\",\n",
@ -327,21 +177,9 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Refute: Use a Dummy Outcome\n",
"Estimated effect:0\n",
"New effect:4.657654751543888e-05\n",
"p value:0.49\n",
"\n"
]
}
],
"outputs": [],
"source": [
"ref = model.refute_estimate(identified_estimand,\n",
" causal_estimate,\n",
@ -373,7 +211,7 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
@ -397,21 +235,9 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Refute: Use a Dummy Outcome\n",
"Estimated effect:0\n",
"New effect:-1.1692081553648758e-05\n",
"p value:0.47\n",
"\n"
]
}
],
"outputs": [],
"source": [
"ref = model.refute_estimate(identified_estimand,\n",
" causal_estimate,\n",

Различия файлов скрыты, потому что одна или несколько строк слишком длинны

Различия файлов скрыты, потому что одна или несколько строк слишком длинны

Различия файлов скрыты, потому что одна или несколько строк слишком длинны

Различия файлов скрыты, потому что одна или несколько строк слишком длинны

Различия файлов скрыты, потому что одна или несколько строк слишком длинны

Различия файлов скрыты, потому что одна или несколько строк слишком длинны

Различия файлов скрыты, потому что одна или несколько строк слишком длинны

Просмотреть файл

@ -11,7 +11,7 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
@ -38,26 +38,18 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Graph Generated.\n",
"Dataframe Generated.\n"
]
}
],
"outputs": [],
"source": [
"n = 10\n",
"p = 0.5\n",
"\n",
"graph = nx.generators.random_graphs.fast_gnp_random_graph(n, p, directed=True)\n",
"G = nx.generators.random_graphs.fast_gnp_random_graph(n, p, directed=True)\n",
"graph = nx.DiGraph([(u,v) for (u,v) in G.edges() if u<v])\n",
"nodes = []\n",
"for i in graph.nodes:\n",
"\tnodes.append(str(i))\n",
" nodes.append(str(i))\n",
"adjacency_matrix = np.asarray(nx.to_numpy_matrix(graph))\n",
"graph_dot = graph_operations.adjacency_matrix_to_graph(adjacency_matrix, nodes)\n",
"graph_dot = graph_operations.str_to_dot(graph_dot.source)\n",
@ -78,19 +70,9 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Time taken for initializing model = 0.10432791709899902\n",
"Time taken for vanilla identification = 0.5290114879608154\n",
"Time taken for optimized backdoor identification = 0.2413492202758789\n"
]
}
],
"outputs": [],
"source": [
"start = time.time()\n",
"\n",
@ -114,7 +96,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"It can be observed that the optimized backdoor search makes causal identification significantly faster as compared to the vanilla implementation."
"It can be observed that the optimized backdoor search makes causal identification faster as compared to the vanilla implementation."
]
}
],
@ -123,7 +105,7 @@
"hash": "31f2aee4e71d21fbe5cf8b01ff0e069b9275f58929596ceb00d14d90e3e16cd6"
},
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
@ -137,7 +119,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.5"
"version": "3.8.12"
},
"toc": {
"base_numbering": 1,

Различия файлов скрыты, потому что одна или несколько строк слишком длинны

Различия файлов скрыты, потому что одна или несколько строк слишком длинны

Различия файлов скрыты, потому что одна или несколько строк слишком длинны

Просмотреть файл

@ -499,7 +499,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.10"
"version": "3.8.5"
},
"toc": {
"base_numbering": 1,

Просмотреть файл

@ -16,7 +16,7 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
@ -60,7 +60,7 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
@ -76,7 +76,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
@ -103,7 +103,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
@ -136,209 +136,9 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>pldel</th>\n",
" <th>birattnd</th>\n",
" <th>brstate</th>\n",
" <th>stoccfipb</th>\n",
" <th>mager8</th>\n",
" <th>ormoth</th>\n",
" <th>mrace</th>\n",
" <th>meduc6</th>\n",
" <th>dmar</th>\n",
" <th>mplbir</th>\n",
" <th>...</th>\n",
" <th>infant_id</th>\n",
" <th>dlivord_min</th>\n",
" <th>dtotord_min</th>\n",
" <th>bord</th>\n",
" <th>brstate_reg</th>\n",
" <th>stoccfipb_reg</th>\n",
" <th>mplbir_reg</th>\n",
" <th>wt</th>\n",
" <th>treatment</th>\n",
" <th>outcome</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>1.0</td>\n",
" <td>1.0</td>\n",
" <td>1.0</td>\n",
" <td>1.0</td>\n",
" <td>3.0</td>\n",
" <td>0.0</td>\n",
" <td>1.0</td>\n",
" <td>3.0</td>\n",
" <td>1.0</td>\n",
" <td>1.0</td>\n",
" <td>...</td>\n",
" <td>35.0</td>\n",
" <td>3.0</td>\n",
" <td>3.0</td>\n",
" <td>2.0</td>\n",
" <td>5.0</td>\n",
" <td>5.0</td>\n",
" <td>5.0</td>\n",
" <td>936.0</td>\n",
" <td>0</td>\n",
" <td>0.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>1.0</td>\n",
" <td>1.0</td>\n",
" <td>1.0</td>\n",
" <td>1.0</td>\n",
" <td>3.0</td>\n",
" <td>0.0</td>\n",
" <td>1.0</td>\n",
" <td>3.0</td>\n",
" <td>1.0</td>\n",
" <td>1.0</td>\n",
" <td>...</td>\n",
" <td>34.0</td>\n",
" <td>3.0</td>\n",
" <td>3.0</td>\n",
" <td>1.0</td>\n",
" <td>5.0</td>\n",
" <td>5.0</td>\n",
" <td>5.0</td>\n",
" <td>1006.0</td>\n",
" <td>1</td>\n",
" <td>0.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>1.0</td>\n",
" <td>1.0</td>\n",
" <td>1.0</td>\n",
" <td>1.0</td>\n",
" <td>3.0</td>\n",
" <td>0.0</td>\n",
" <td>1.0</td>\n",
" <td>2.0</td>\n",
" <td>0.0</td>\n",
" <td>1.0</td>\n",
" <td>...</td>\n",
" <td>47.0</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>5.0</td>\n",
" <td>5.0</td>\n",
" <td>5.0</td>\n",
" <td>737.0</td>\n",
" <td>0</td>\n",
" <td>0.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>1.0</td>\n",
" <td>1.0</td>\n",
" <td>1.0</td>\n",
" <td>1.0</td>\n",
" <td>3.0</td>\n",
" <td>0.0</td>\n",
" <td>1.0</td>\n",
" <td>2.0</td>\n",
" <td>0.0</td>\n",
" <td>1.0</td>\n",
" <td>...</td>\n",
" <td>46.0</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>5.0</td>\n",
" <td>5.0</td>\n",
" <td>5.0</td>\n",
" <td>850.0</td>\n",
" <td>1</td>\n",
" <td>1.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>1.0</td>\n",
" <td>1.0</td>\n",
" <td>1.0</td>\n",
" <td>1.0</td>\n",
" <td>3.0</td>\n",
" <td>0.0</td>\n",
" <td>1.0</td>\n",
" <td>3.0</td>\n",
" <td>1.0</td>\n",
" <td>1.0</td>\n",
" <td>...</td>\n",
" <td>52.0</td>\n",
" <td>1.0</td>\n",
" <td>1.0</td>\n",
" <td>1.0</td>\n",
" <td>5.0</td>\n",
" <td>5.0</td>\n",
" <td>5.0</td>\n",
" <td>1830.0</td>\n",
" <td>0</td>\n",
" <td>0.0</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>5 rows × 53 columns</p>\n",
"</div>"
],
"text/plain": [
" pldel birattnd brstate stoccfipb mager8 ormoth mrace meduc6 dmar \\\n",
"0 1.0 1.0 1.0 1.0 3.0 0.0 1.0 3.0 1.0 \n",
"1 1.0 1.0 1.0 1.0 3.0 0.0 1.0 3.0 1.0 \n",
"2 1.0 1.0 1.0 1.0 3.0 0.0 1.0 2.0 0.0 \n",
"3 1.0 1.0 1.0 1.0 3.0 0.0 1.0 2.0 0.0 \n",
"4 1.0 1.0 1.0 1.0 3.0 0.0 1.0 3.0 1.0 \n",
"\n",
" mplbir ... infant_id dlivord_min dtotord_min bord brstate_reg \\\n",
"0 1.0 ... 35.0 3.0 3.0 2.0 5.0 \n",
"1 1.0 ... 34.0 3.0 3.0 1.0 5.0 \n",
"2 1.0 ... 47.0 NaN NaN NaN 5.0 \n",
"3 1.0 ... 46.0 NaN NaN NaN 5.0 \n",
"4 1.0 ... 52.0 1.0 1.0 1.0 5.0 \n",
"\n",
" stoccfipb_reg mplbir_reg wt treatment outcome \n",
"0 5.0 5.0 936.0 0 0.0 \n",
"1 5.0 5.0 1006.0 1 0.0 \n",
"2 5.0 5.0 737.0 0 0.0 \n",
"3 5.0 5.0 850.0 1 1.0 \n",
"4 5.0 5.0 1830.0 0 0.0 \n",
"\n",
"[5 rows x 53 columns]"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"outputs": [],
"source": [
"cols = [ 'pldel', 'birattnd', 'brstate', 'stoccfipb', 'mager8',\n",
" 'ormoth', 'mrace', 'meduc6', 'dmar', 'mplbir', 'mpre5', 'adequacy',\n",
@ -355,19 +155,9 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"0.16421895861148197\n",
"0.1894192256341789\n",
"ATE -0.025200267022696926\n"
]
}
],
"outputs": [],
"source": [
"df = df.astype({\"treatment\":'bool'}, copy=False) #explicitly assigning treatment column as boolean \n",
"\n",
@ -390,7 +180,7 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": null,
"metadata": {
"scrolled": true
},
@ -414,36 +204,11 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": null,
"metadata": {
"scrolled": true
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Estimand type: nonparametric-ate\n",
"\n",
"### Estimand : 1\n",
"Estimand name: backdoor\n",
"Estimand expression:\n",
" d \n",
"────────────(Expectation(outcome|gestat10))\n",
"d[treatment] \n",
"Estimand assumption 1, Unconfoundedness: If U→{treatment} and U→outcome then P(outcome|treatment,gestat10,U) = P(outcome|treatment,gestat10)\n",
"\n",
"### Estimand : 2\n",
"Estimand name: iv\n",
"No such variable found!\n",
"\n",
"### Estimand : 3\n",
"Estimand name: frontdoor\n",
"No such variable found!\n",
"\n"
]
}
],
"outputs": [],
"source": [
"identified_estimand = model.identify_effect(proceed_when_unidentifiable=True)\n",
"print(identified_estimand)"
@ -465,39 +230,9 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"*** Causal Estimate ***\n",
"\n",
"## Identified estimand\n",
"Estimand type: nonparametric-ate\n",
"\n",
"### Estimand : 1\n",
"Estimand name: backdoor\n",
"Estimand expression:\n",
" d \n",
"────────────(Expectation(outcome|gestat10))\n",
"d[treatment] \n",
"Estimand assumption 1, Unconfoundedness: If U→{treatment} and U→outcome then P(outcome|treatment,gestat10,U) = P(outcome|treatment,gestat10)\n",
"\n",
"## Realized estimand\n",
"b: outcome~treatment+gestat10\n",
"Target units: ate\n",
"\n",
"## Estimate\n",
"Mean value: -0.025200267022700423\n",
"p-value: [7.18902894e-08]\n",
"\n",
"ATE -0.025200267022696926\n",
"Causal Estimate is -0.025200267022700423\n"
]
}
],
"outputs": [],
"source": [
"estimate = model.estimate_effect(identified_estimand,\n",
" method_name=\"backdoor.linear_regression\", test_significance=True\n",
@ -517,26 +252,9 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/home/amit/py-envs/env3.8/lib/python3.8/site-packages/sklearn/utils/validation.py:72: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n",
" return f(**kwargs)\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Causal Estimate is -0.012600133511348465\n",
"ATE -0.025200267022696926\n"
]
}
],
"outputs": [],
"source": [
"estimate = model.estimate_effect(identified_estimand,\n",
" method_name=\"backdoor.propensity_score_matching\"\n",
@ -563,28 +281,9 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/home/amit/py-envs/env3.8/lib/python3.8/site-packages/sklearn/utils/validation.py:72: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n",
" return f(**kwargs)\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Refute: Add a Random Common Cause\n",
"Estimated effect:-0.012600133511348465\n",
"New effect:-0.02728638184245661\n",
"\n"
]
}
],
"outputs": [],
"source": [
"refute_results=model.refute_estimate(identified_estimand, estimate,\n",
" method_name=\"random_common_cause\")\n",
@ -600,67 +299,9 @@
},
{
"cell_type": "code",
"execution_count": 12,
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/home/amit/py-envs/env3.8/lib/python3.8/site-packages/sklearn/utils/validation.py:72: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n",
" return f(**kwargs)\n",
"/home/amit/py-envs/env3.8/lib/python3.8/site-packages/sklearn/utils/validation.py:72: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n",
" return f(**kwargs)\n",
"/home/amit/py-envs/env3.8/lib/python3.8/site-packages/sklearn/utils/validation.py:72: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n",
" return f(**kwargs)\n",
"/home/amit/py-envs/env3.8/lib/python3.8/site-packages/sklearn/utils/validation.py:72: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n",
" return f(**kwargs)\n",
"/home/amit/py-envs/env3.8/lib/python3.8/site-packages/sklearn/utils/validation.py:72: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n",
" return f(**kwargs)\n",
"/home/amit/py-envs/env3.8/lib/python3.8/site-packages/sklearn/utils/validation.py:72: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n",
" return f(**kwargs)\n",
"/home/amit/py-envs/env3.8/lib/python3.8/site-packages/sklearn/utils/validation.py:72: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n",
" return f(**kwargs)\n",
"/home/amit/py-envs/env3.8/lib/python3.8/site-packages/sklearn/utils/validation.py:72: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n",
" return f(**kwargs)\n",
"/home/amit/py-envs/env3.8/lib/python3.8/site-packages/sklearn/utils/validation.py:72: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n",
" return f(**kwargs)\n",
"/home/amit/py-envs/env3.8/lib/python3.8/site-packages/sklearn/utils/validation.py:72: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n",
" return f(**kwargs)\n",
"/home/amit/py-envs/env3.8/lib/python3.8/site-packages/sklearn/utils/validation.py:72: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n",
" return f(**kwargs)\n",
"/home/amit/py-envs/env3.8/lib/python3.8/site-packages/sklearn/utils/validation.py:72: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n",
" return f(**kwargs)\n",
"/home/amit/py-envs/env3.8/lib/python3.8/site-packages/sklearn/utils/validation.py:72: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n",
" return f(**kwargs)\n",
"/home/amit/py-envs/env3.8/lib/python3.8/site-packages/sklearn/utils/validation.py:72: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n",
" return f(**kwargs)\n",
"/home/amit/py-envs/env3.8/lib/python3.8/site-packages/sklearn/utils/validation.py:72: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n",
" return f(**kwargs)\n",
"/home/amit/py-envs/env3.8/lib/python3.8/site-packages/sklearn/utils/validation.py:72: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n",
" return f(**kwargs)\n",
"/home/amit/py-envs/env3.8/lib/python3.8/site-packages/sklearn/utils/validation.py:72: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n",
" return f(**kwargs)\n",
"/home/amit/py-envs/env3.8/lib/python3.8/site-packages/sklearn/utils/validation.py:72: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n",
" return f(**kwargs)\n",
"/home/amit/py-envs/env3.8/lib/python3.8/site-packages/sklearn/utils/validation.py:72: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n",
" return f(**kwargs)\n",
"/home/amit/py-envs/env3.8/lib/python3.8/site-packages/sklearn/utils/validation.py:72: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n",
" return f(**kwargs)\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Refute: Use a Placebo Treatment\n",
"Estimated effect:-0.012600133511348465\n",
"New effect:-0.01735856141522029\n",
"p value:0.43718357128183105\n",
"\n"
]
}
],
"outputs": [],
"source": [
"res_placebo=model.refute_estimate(identified_estimand, estimate,\n",
" method_name=\"placebo_treatment_refuter\", placebo_type=\"permute\",\n",
@ -677,67 +318,9 @@
},
{
"cell_type": "code",
"execution_count": 13,
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/home/amit/py-envs/env3.8/lib/python3.8/site-packages/sklearn/utils/validation.py:72: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n",
" return f(**kwargs)\n",
"/home/amit/py-envs/env3.8/lib/python3.8/site-packages/sklearn/utils/validation.py:72: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n",
" return f(**kwargs)\n",
"/home/amit/py-envs/env3.8/lib/python3.8/site-packages/sklearn/utils/validation.py:72: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n",
" return f(**kwargs)\n",
"/home/amit/py-envs/env3.8/lib/python3.8/site-packages/sklearn/utils/validation.py:72: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n",
" return f(**kwargs)\n",
"/home/amit/py-envs/env3.8/lib/python3.8/site-packages/sklearn/utils/validation.py:72: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n",
" return f(**kwargs)\n",
"/home/amit/py-envs/env3.8/lib/python3.8/site-packages/sklearn/utils/validation.py:72: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n",
" return f(**kwargs)\n",
"/home/amit/py-envs/env3.8/lib/python3.8/site-packages/sklearn/utils/validation.py:72: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n",
" return f(**kwargs)\n",
"/home/amit/py-envs/env3.8/lib/python3.8/site-packages/sklearn/utils/validation.py:72: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n",
" return f(**kwargs)\n",
"/home/amit/py-envs/env3.8/lib/python3.8/site-packages/sklearn/utils/validation.py:72: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n",
" return f(**kwargs)\n",
"/home/amit/py-envs/env3.8/lib/python3.8/site-packages/sklearn/utils/validation.py:72: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n",
" return f(**kwargs)\n",
"/home/amit/py-envs/env3.8/lib/python3.8/site-packages/sklearn/utils/validation.py:72: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n",
" return f(**kwargs)\n",
"/home/amit/py-envs/env3.8/lib/python3.8/site-packages/sklearn/utils/validation.py:72: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n",
" return f(**kwargs)\n",
"/home/amit/py-envs/env3.8/lib/python3.8/site-packages/sklearn/utils/validation.py:72: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n",
" return f(**kwargs)\n",
"/home/amit/py-envs/env3.8/lib/python3.8/site-packages/sklearn/utils/validation.py:72: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n",
" return f(**kwargs)\n",
"/home/amit/py-envs/env3.8/lib/python3.8/site-packages/sklearn/utils/validation.py:72: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n",
" return f(**kwargs)\n",
"/home/amit/py-envs/env3.8/lib/python3.8/site-packages/sklearn/utils/validation.py:72: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n",
" return f(**kwargs)\n",
"/home/amit/py-envs/env3.8/lib/python3.8/site-packages/sklearn/utils/validation.py:72: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n",
" return f(**kwargs)\n",
"/home/amit/py-envs/env3.8/lib/python3.8/site-packages/sklearn/utils/validation.py:72: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n",
" return f(**kwargs)\n",
"/home/amit/py-envs/env3.8/lib/python3.8/site-packages/sklearn/utils/validation.py:72: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n",
" return f(**kwargs)\n",
"/home/amit/py-envs/env3.8/lib/python3.8/site-packages/sklearn/utils/validation.py:72: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n",
" return f(**kwargs)\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Refute: Use a subset of data\n",
"Estimated effect:-0.012600133511348465\n",
"New effect:-0.04436048398312549\n",
"p value:0.3529814152616\n",
"\n"
]
}
],
"outputs": [],
"source": [
"res_subset=model.refute_estimate(identified_estimand, estimate,\n",
" method_name=\"data_subset_refuter\", subset_fraction=0.9,\n",

Различия файлов скрыты, потому что одна или несколько строк слишком длинны

Различия файлов скрыты, потому что одна или несколько строк слишком длинны

Различия файлов скрыты, потому что одна или несколько строк слишком длинны

Просмотреть файл

@ -9,4 +9,5 @@
dowhy_demo_dummy_outcome_refuter.ipynb
dowhy_multiple_treatments.ipynb
dowhy_refuter_notebook
dowhy_causal_discovery_example.ipynb
identifying_effects_using_id_algorithm.ipynb

Просмотреть файл

@ -9,6 +9,7 @@
dowhy_estimation_methods
dowhy-simple-iv-example
load_graph_example
dowhy_interpreter.ipynb
dowhy_causal_api
do_sampler_demo

Различия файлов скрыты, потому что одна или несколько строк слишком длинны

Просмотреть файл

@ -59,19 +59,20 @@ class CausalAccessor(object):
:param x: str, list, dict: The causal state on which to intervene, and (optional) its interventional value(s).
:param method: The inference method to use with the sampler. Currently, `'mcmc'`, `'weighting'`, and
`'kernel_density'` are supported. The `mcmc` sampler requires `pymc3>=3.7`.
`'kernel_density'` are supported. The `mcmc` sampler requires `pymc3>=3.7`.
:param num_cores: int: if the inference method only supports sampling a point at a time, this will parallelize
sampling.
sampling.
:param variable_types: dict: The dictionary containing the variable types. Must contain the union of the causal
state, control variables, and the outcome.
state, control variables, and the outcome.
:param outcome: str: The outcome variable.
:param params: dict: extra parameters to set as attributes on the sampler object
:param dot_graph: str: A string specifying the causal graph.
:param common_causes: list: A list of strings containing the variable names to control for.
:param estimand_type: str: 'nonparametric-ate' is the only one currently supported. Others may be added later, to allow for specific, parametric estimands.
:param proceed_when_unidentifiable: bool: A flag to over-ride user prompts to proceed when effects aren't
identifiable with the assumptions provided.
identifiable with the assumptions provided.
:param stateful: bool: Whether to retain state. By default, the do operation is stateless.
:return: pandas.DataFrame: A DataFrame containing the sampled outcome
"""
x, keep_original_treatment = self.parse_x(x)
@ -88,20 +89,20 @@ class CausalAccessor(object):
estimand_type=estimand_type,
proceed_when_unidentifiable=proceed_when_unidentifiable)
#self._identified_estimand = self._causal_model.identify_effect()
if not bool(variable_types): #check if the variables dictionary is empty
variable_types = dict(self._obj.dtypes) #Convert the series containing data types to a dictionary
for key in variable_types.keys():
variable_types[key] = self.convert_to_custom_type(variable_types[key].name) #Obtain the custom type corrosponding to each data type
variable_types[key] = self.convert_to_custom_type(variable_types[key].name) #Obtain the custom type corrosponding to each data type
elif len(self._obj.columns) > len(variable_types):
all_variables = dict(self._obj.dtypes)
all_variables = dict(self._obj.dtypes)
for key in all_variables.keys():
if key not in variable_types:
variable_types[key] = self.convert_to_custom_type(all_variables[key].name)
elif len(self._obj.columns) < len(variable_types):
raise Exception('Number of variables in the DataFrame is lesser than the variable_types dict')
raise Exception('Number of variables in the DataFrame is lesser than the variable_types dict')
if not self._sampler:
self._method = method

Просмотреть файл

@ -136,12 +136,12 @@ class CausalEstimator:
Creates a new object with new_data and the identified_estimand
:param new_data: np.ndarray, pd.Series, pd.DataFrame
The newly assigned data on which the estimator should run
The newly assigned data on which the estimator should run
:param identified_estimand: IdentifiedEstimand
An instance of the identified estimand class that provides the information with
respect to which causal pathways are employed when the treatment effects the outcome
An instance of the identified estimand class that provides the information with
respect to which causal pathways are employed when the treatment effects the outcome
:param estimate: CausalEstimate
It is an already existing estimate whose properties we wish to replicate
It is an already existing estimate whose properties we wish to replicate
:returns: An instance of the same estimator class that had generated the given estimate.
"""

Просмотреть файл

@ -14,7 +14,7 @@ class IDExpression:
def __init__(self):
self._product = []
self._sum = []
def add_product(self, element):
'''
Add an estimator to the list of product.
@ -22,7 +22,7 @@ class IDExpression:
:param element: Estimator to append to the product list.
'''
self._product.append(element)
def add_sum(self, element):
'''
Add variables to the list.
@ -51,7 +51,7 @@ class IDExpression:
'''
if estimator is None:
return None
string = ""
if isinstance(estimator, IDExpression):
s = True if len(estimator.get_val(return_type="sum"))>0 else False
@ -111,7 +111,7 @@ class IDIdentifier(CausalIdentifier):
except:
raise Exception("The graph must be a directed acyclic graph (DAG).")
self._node_names = OrderedSet(graph._graph.nodes)
def identify_effect(self, treatment_names=None, outcome_names=None, adjacency_matrix=None, node_names=None):
'''
Implementation of the ID algorithm.
@ -122,7 +122,8 @@ class IDIdentifier(CausalIdentifier):
:param treatment_names: OrderedSet comprising names of treatment variables.
:param outcome_names:OrderedSet comprising names of outcome variables.
:param adjacency_matrix: Graph adjacency matrix.
:param node_names: OrderedSet comprising names of all nodes in the graph.
:param node_names: OrderedSet comprising names of all nodes in the graph
:returns: target estimand, an instance of the IDExpression class.
'''
if adjacency_matrix is None:
@ -134,12 +135,12 @@ class IDIdentifier(CausalIdentifier):
if node_names is None:
node_names = self._node_names
node2idx, idx2node = self._idx_node_mapping(node_names)
# Estimators list for returning after identification
estimators = IDExpression()
# Line 1
# If no action has been taken, the effect on Y is just the marginal of the observational distribution P(v) on Y.
# If no action has been taken, the effect on Y is just the marginal of the observational distribution P(v) on Y.
if len(treatment_names) == 0:
identifier = IDExpression()
estimator = {}
@ -159,8 +160,8 @@ class IDIdentifier(CausalIdentifier):
node_names = node_names.intersection(ancestors)
adjacency_matrix = induced_graph(node_set=node_names, adjacency_matrix=adjacency_matrix, node2idx=node2idx)
return self.identify_effect(treatment_names=treatment_names, outcome_names=outcome_names, adjacency_matrix=adjacency_matrix, node_names=node_names)
# Line 3 - forces an action on any node where such an action would have no effect on Y – assuming we already acted on X.
# Line 3 - forces an action on any node where such an action would have no effect on Y – assuming we already acted on X.
# Modify adjacency matrix to obtain that corresponding to do(X)
adjacency_matrix_do_x = adjacency_matrix.copy()
for x in treatment_names:
@ -171,7 +172,7 @@ class IDIdentifier(CausalIdentifier):
W = node_names.difference(treatment_names).difference(ancestors)
if len(W) != 0:
return self.identify_effect(treatment_names = treatment_names.union(W), outcome_names=outcome_names, adjacency_matrix=adjacency_matrix, node_names=node_names)
# Line 4 - Decomposes the problem into a set of smaller problems using the key property of C-component factorization of causal models.
# If the entire graph is a single C-component already, further problem decomposition is impossible, and we must provide base cases.
# Modify adjacency matrix to remove treatment variables
@ -190,13 +191,13 @@ class IDIdentifier(CausalIdentifier):
estimators.add_product(identifier)
return estimators
# Line 5 - The algorithms fails due to the presence of a hedge - the graph G, and a subgraph S that does not contain any X nodes.
S = c_components[0]
c_components_G = find_c_components(adjacency_matrix=adjacency_matrix, node_set=node_names, idx2node=idx2node)
if len(c_components_G)==1 and c_components_G[0] == node_names:
return None
# Line 6 - If there are no bidirected arcs from X to the other nodes in the current subproblem under consideration, then we can replace acting on X by conditioning, and thus solve the subproblem.
if S in c_components_G:
sum_over_set = S.difference(outcome_names)
@ -219,11 +220,11 @@ class IDIdentifier(CausalIdentifier):
C = S.difference(component)
if C.is_empty() is None:
return self.identify_effect(treatment_names=treatment_names.intersection(component), outcome_names=outcome_names, adjacency_matrix=induced_graph(node_set=component, adjacency_matrix=adjacency_matrix,node2idx=node2idx), node_names=node_names)
def _idx_node_mapping(self, node_names):
'''
Obtain the node name to index and index to node name mappings.
:param node_names: Name of all nodes in the graph.
:return: node to index and index to node mappings.
'''
@ -232,4 +233,4 @@ class IDIdentifier(CausalIdentifier):
for i, node in enumerate(node_names.get_all()):
node2idx[node] = i
idx2node[i] = node
return node2idx, idx2node
return node2idx, idx2node

Просмотреть файл

@ -233,9 +233,8 @@ class CausalModel:
:param target_units: (Experimental) The units for which the treatment effect should be estimated. This can be of three types. (1) a string for common specifications of target units (namely, "ate", "att" and "atc"), (2) a lambda function that can be used as an index for the data (pandas DataFrame), or (3) a new DataFrame that contains values of the effect_modifiers and effect will be estimated only for this new data.
:param effect_modifiers: Names of effect modifier variables can be (optionally) specified here too, since they do not affect identification. If None, the effect_modifiers from the CausalModel are used.
:param fit_estimator: Boolean flag on whether to fit the estimator.
Setting it to False is useful to estimate the effect on new data using a previously fitted estimator.
Setting it to False is useful to estimate the effect on new data using a previously fitted estimator.
:param method_params: Dictionary containing any method-specific parameters. These are passed directly to the estimating method. See the docs for each estimation method for allowed method-specific params.
:returns: An instance of the CausalEstimate class, containing the causal effect estimate
and other method-dependent information
@ -336,7 +335,7 @@ class CausalModel:
CausalModel.identify_effect method
:param method_name: any of the estimation method to be used. See docs for estimate_effect method for a list of supported estimation methods.
:param fit_estimator: Boolean flag on whether to fit the estimator.
Setting it to False is useful to compute the do-operation on new data using a previously fitted estimator.
Setting it to False is useful to compute the do-operation on new data using a previously fitted estimator.
:param method_params: Dictionary containing any method-specific parameters. These are passed directly to the estimating method.
:returns: an instance of the CausalEstimate class, containing the causal effect estimate

Просмотреть файл

@ -98,7 +98,7 @@ class CausalRefuter:
""" Tests the statistical significance of the estimate obtained to the simulations produced by a refuter.
The basis behind using the sample statistics of the refuter when we are in fact testing the estimate,
is due to the fact that, we would ideally expect them to follow the same distribition
is due to the fact that, we would ideally expect them to follow the same distribition.
For refutation tests (e.g., placebo refuters), consider the null distribution as a distribution of effect
estimates over multiple simulations with placebo treatment, and compute how likely the true estimate (e.g.,
@ -108,22 +108,22 @@ class CausalRefuter:
For sensitivity analysis tests (e.g., bootstrap, subset or common cause refuters), the null distribution captures
the distribution of effect estimates under the "true" dataset (e.g., with an additional confounder or different
sampling), and we compute the probability of the obtained estimate under this distribution. If the probability is
lower than the p-value, then the estimator method fails the test
lower than the p-value, then the estimator method fails the test.
Null Hypothesis: The estimate is a part of the distribution
Alternative Hypothesis: The estimate does not fall in the distribution.
Null Hypothesis- The estimate is a part of the distribution
Alternative Hypothesis- The estimate does not fall in the distribution.
:param 'estimate': CausalEstimate
The estimate obtained from the estimator for the original data.
The estimate obtained from the estimator for the original data.
:param 'simulations': np.array
An array containing the result of the refuter for the simulations
An array containing the result of the refuter for the simulations
:param 'test_type': string, default 'auto'
The type of test the user wishes to perform.
The type of test the user wishes to perform.
:param 'significance_level': float, default 0.05
The significance level for the statistical test
The significance level for the statistical test
:returns: significance_dict: Dict
A Dict containing the p_value and a boolean that indicates if the result is statistically significant
A Dict containing the p_value and a boolean that indicates if the result is statistically significant
"""
# Initializing the p_value
p_value = 0

Просмотреть файл

@ -370,32 +370,33 @@ class AddUnobservedCommonCause(CausalRefuter):
def include_simulated_confounder(self, convergence_threshold = 0.1, c_star_max = 1000):
'''
This function simulates an unobserved confounder based on the data using the following steps:
1. It calculates the "residuals" from the treatment and outcome model
i.) The outcome model has outcome as the dependent variable and all the observed variables including treatment as independent variables
ii.) The treatment model has treatment as the dependent variable and all the observed variables as independent variables.
1. It calculates the "residuals" from the treatment and outcome model
i.) The outcome model has outcome as the dependent variable and all the observed variables including treatment as independent variables
ii.) The treatment model has treatment as the dependent variable and all the observed variables as independent variables.
2. U is an intermediate random variable drawn from the normal distribution with the weighted average of residuals as mean and a unit variance
U ~ N(c1*d_y + c2*d_t, 1)
where
*d_y and d_t are residuals from the treatment and outcome model
*c1 and c2 are coefficients to the residuals
2. U is an intermediate random variable drawn from the normal distribution with the weighted average of residuals as mean and a unit variance
U ~ N(c1*d_y + c2*d_t, 1)
where
*d_y and d_t are residuals from the treatment and outcome model
*c1 and c2 are coefficients to the residuals
3. The final U, which is the simulated unobserved confounder is obtained by debiasing the intermediate variable U by residualising it with X
3. The final U, which is the simulated unobserved confounder is obtained by debiasing the intermediate variable U by residualising it with X
Choosing the coefficients c1 and c2:
The coefficients are chosen based on these basic assumptions:
1. There is a hyperbolic relationship satisfying c1*c2 = c_star
2. c_star is chosen from a range of possible values based on the correlation of the obtained simulated variable with outcome and treatment.
3. The product of correlations with treatment and outcome should be at a minimum distance to the maximum correlations with treatment and outcome in any of the observed confounders
4. The ratio of the weights should be such that they maintain the ratio of the maximum possible observed coefficients within some confidence interval
1. There is a hyperbolic relationship satisfying c1*c2 = c_star
2. c_star is chosen from a range of possible values based on the correlation of the obtained simulated variable with outcome and treatment.
3. The product of correlations with treatment and outcome should be at a minimum distance to the maximum correlations with treatment and outcome in any of the observed confounders
4. The ratio of the weights should be such that they maintain the ratio of the maximum possible observed coefficients within some confidence interval
:param c_star_max: The maximum possible value for the hyperbolic curve on which the coefficients to the residuals lie. It defaults to 1000 in the code if not specified by the user.
:type int
:type int
:param convergence_threshold: The threshold to check the plateauing of the correlation while selecting a c_star. It defaults to 0.1 in the code if not specified by the user
:type float
:returns final_U: The simulated values of the unobserved confounder based on the data
:type pandas.core.series.Series
:type float
:returns: The simulated values of the unobserved confounder based on the data
:type pandas.core.series.Series
'''
@ -548,7 +549,7 @@ class AddUnobservedCommonCause(CausalRefuter):
def generate_confounder_from_residuals(self, c1, c2, d_y, d_t, X):
'''
This function takes the residuals from the treatment and outcome model and their coefficients and simulates the intermediate random variable U by taking
the row wise normal distribution corresponding to each residual value and then debiasing the intermediate variable to get the final variable
the row wise normal distribution corresponding to each residual value and then debiasing the intermediate variable to get the final variable.
:param c1: coefficient to the residual from the outcome model
:type float
@ -559,7 +560,7 @@ class AddUnobservedCommonCause(CausalRefuter):
:param d_t: residuals from the treatment model
:type list
:returns final_U: The simulated values of the unobserved confounder based on the data
:returns: The simulated values of the unobserved confounder based on the data
:type pandas.core.series.Series
'''

Просмотреть файл

@ -41,7 +41,7 @@ class DummyOutcomeRefuter(CausalRefuter):
outcome y. Note that since f(W) simply defines a new DGP for the simulated
outcome, it need not be the correct structural equation from W to y.
2. We obtain the value of dummy outcome as:
``y_dummy = h(t) + f(W)``
``y_dummy = h(t) + f(W)``
To prevent overfitting, we fit f(W) for one value of T and then use it to
generate data for other values of t. Future support for identification
@ -71,26 +71,26 @@ class DummyOutcomeRefuter(CausalRefuter):
t --->y
h(t)
Supports additional parameters that can be specified in the refute_estimate() method.
:param num_simulations: The number of simulations to be run, which defaults to ``CausalRefuter.DEFAULT_NUM_SIMULATIONS``
:type num_simulations: int, optional
:param transformation_list: It is a list of actions to be performed to obtain the outcome, which defaults to ``DummyOutcomeRefuter.DEFAULT_TRANSFORMATION``.
The default transformation is as follows:
``[("zero",""),("noise", {'std_dev':1} )]``
:type transformation_list: list, optional
:type transformation_list: list, optional
Each of the actions within a transformation is one of the following types:
* function argument: function ``pd.Dataframe -> np.ndarray``
* function argument: function ``pd.Dataframe -> np.ndarray``
It takes in a function that takes the input data frame as the input and outputs the outcome
variable. This allows us to create an output varable that only depends on the covariates and does not depend
on the treatment variable.
* string argument
* string argument
* Currently it supports some common estimators like
@ -130,14 +130,14 @@ class DummyOutcomeRefuter(CausalRefuter):
dummy data.
:type true_causal_effect: function
The equation for the dummy outcome is given by
``y_hat = h(t) + f(W)``
The equation for the dummy outcome is given by
``y_hat = h(t) + f(W)``
where
where
* ``y_hat`` is the dummy outcome
* ``h(t)`` is the function that gives the true causal effect
* ``f(W)`` is the best estimate of ``y`` obtained keeping ``t`` constant. This ensures that the variation in output of function ``f(w)`` is not caused by ``t``.
* ``y_hat`` is the dummy outcome
* ``h(t)`` is the function that gives the true causal effect
* ``f(W)`` is the best estimate of ``y`` obtained keeping ``t`` constant. This ensures that the variation in output of function ``f(w)`` is not caused by ``t``.
.. note:: The true causal effect should take an input of the same shape as the treatment and the output should match the shape of the outcome
@ -145,8 +145,8 @@ class DummyOutcomeRefuter(CausalRefuter):
This is ``True`` by default, which in turn selects all variables leaving the treatment and the outcome
:type required_variables: int, list, bool, optional
1. An integer argument refers to how many variables will be used for estimating the value of the outcome
2. A list explicitly refers to which variables will be used to estimate the outcome
1. An integer argument refers to how many variables will be used for estimating the value of the outcome
2. A list explicitly refers to which variables will be used to estimate the outcome
Furthermore, it gives the ability to explictly select or deselect the covariates present in the estimation of the
outcome. This is done by either adding or explicitly removing variables from the list as shown below:
@ -154,7 +154,7 @@ class DummyOutcomeRefuter(CausalRefuter):
* We need to pass required_variables = ``[W0,W1]`` if we want ``W0`` and ``W1``.
* We need to pass required_variables = ``[-W0,-W1]`` if we want all variables excluding ``W0`` and ``W1``.
3. If the value is True, we wish to include all variables to estimate the value of the outcome.
3. If the value is True, we wish to include all variables to estimate the value of the outcome.
.. warning:: A ``False`` value is ``INVALID`` and will result in an ``error``.
@ -513,14 +513,14 @@ class DummyOutcomeRefuter(CausalRefuter):
"""
A function that takes in any sklearn estimator and returns a trained estimator
- 'action': str
The sklearn estimator to be used.
- 'X_train': np.ndarray
The variable used to estimate the value of outcome.
- 'outcome': np.ndarray
The variable which we wish to estimate.
- 'func_args': variable length keyworded argument
The parameters passed to the estimator.
:param 'action': str
The sklearn estimator to be used.
:param 'X_train': np.ndarray
The variable used to estimate the value of outcome.
:param 'outcome': np.ndarray
The variable which we wish to estimate.
:param 'func_args': variable length keyworded argument
The parameters passed to the estimator.
"""
estimator = self._get_regressor_object(action, **func_args)
X = X_train
@ -534,10 +534,10 @@ class DummyOutcomeRefuter(CausalRefuter):
"""
Return a sklearn estimator object based on the estimator and corresponding parameters
- 'action': str
The sklearn estimator used.
- 'func_args': variable length keyworded argument
The parameters passed to the sklearn estimator.
:param 'action': str
The sklearn estimator used.
:param 'func_args': variable length keyworded argument
The parameters passed to the sklearn estimator.
"""
if action == "linear_regression":
return LinearRegression(**func_args)
@ -558,10 +558,10 @@ class DummyOutcomeRefuter(CausalRefuter):
Otherwise we make use of the Fisher Yates shuffle.
Refer to https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle for more details.
'outcome': np.ndarray
The outcome variable to be permuted.
'permute_fraction': float [0, 1]
The fraction of rows permuted.
:param 'outcome': np.ndarray
The outcome variable to be permuted.
:param 'permute_fraction': float [0, 1]
The fraction of rows permuted.
'''
if permute_fraction == 1:
outcome = pd.DataFrame(outcome)
@ -585,9 +585,11 @@ class DummyOutcomeRefuter(CausalRefuter):
"""
Add white noise with mean 0 and standard deviation = std_dev
- 'outcome': np.ndarray
The outcome variable, to which the white noise is added.
- 'std_dev': float
The standard deviation of the white noise.
:param 'outcome': np.ndarray
The outcome variable, to which the white noise is added.
:param 'std_dev': float
The standard deviation of the white noise.
:returns: outcome with added noise
"""
return outcome + np.random.normal(scale=std_dev,size=outcome.shape[0])

Просмотреть файл

@ -4,14 +4,13 @@ def query_yes_no(question, default=True):
Source: https://stackoverflow.com/questions/3041986/apt-command-line-interface-like-yes-no-input
If invalid input is given, the user will be asked until they actually give valid input.
Args:
question(str): A question that is presented to the user.
default(bool|None): The default value when enter is pressed with no value.
Side Effects: Blocks program execution until valid input(y/n) is given.
:param question(str): A question that is presented to the user.
:param default(bool|None): The default value when enter is pressed with no value.
When None, there is no default value and the query will loop.
Returns:
A bool indicating whether user has entered yes or no.
Side Effects:
Blocks program execution until valid input(y/n) is given.
:returns: A bool indicating whether user has entered yes or no.
"""
yes_list = ["yes", "y"]
no_list = ["no", "n"]