better support for multivariate treatment in identification symbolic outputs

This commit is contained in:
Amit Sharma 2019-12-23 06:00:50 +05:30
Родитель 449fe0d34e
Коммит 532208e05d
5 изменённых файлов: 211 добавлений и 693 удалений

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

@ -13,7 +13,7 @@
},
{
"cell_type": "code",
"execution_count": 24,
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
@ -23,7 +23,7 @@
},
{
"cell_type": "code",
"execution_count": 25,
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
@ -47,7 +47,7 @@
},
{
"cell_type": "code",
"execution_count": 26,
"execution_count": 3,
"metadata": {},
"outputs": [
{
@ -86,62 +86,62 @@
" <tr>\n",
" <th>0</th>\n",
" <td>1.0</td>\n",
" <td>0.977197</td>\n",
" <td>-0.513249</td>\n",
" <td>-1.085495</td>\n",
" <td>-0.947936</td>\n",
" <td>-0.836739</td>\n",
" <td>-0.241959</td>\n",
" <td>0.297495</td>\n",
" <td>1.104464</td>\n",
" <td>-1.243507</td>\n",
" <td>2.078729</td>\n",
" <td>-0.035286</td>\n",
" <td>-1.763171</td>\n",
" <td>True</td>\n",
" <td>-0.443120</td>\n",
" <td>11.701762</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>1.0</td>\n",
" <td>0.133648</td>\n",
" <td>1.718109</td>\n",
" <td>1.532397</td>\n",
" <td>-0.441355</td>\n",
" <td>0.338025</td>\n",
" <td>1.321070</td>\n",
" <td>0.940643</td>\n",
" <td>1.552100</td>\n",
" <td>0.374128</td>\n",
" <td>-0.198048</td>\n",
" <td>-0.202730</td>\n",
" <td>0.024421</td>\n",
" <td>True</td>\n",
" <td>23.899661</td>\n",
" <td>13.893867</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>0.0</td>\n",
" <td>0.261689</td>\n",
" <td>2.167228</td>\n",
" <td>-0.133905</td>\n",
" <td>-0.641217</td>\n",
" <td>1.669584</td>\n",
" <td>0.555210</td>\n",
" <td>1.0</td>\n",
" <td>0.782048</td>\n",
" <td>0.413752</td>\n",
" <td>-0.404527</td>\n",
" <td>1.963213</td>\n",
" <td>1.579329</td>\n",
" <td>0.539134</td>\n",
" <td>True</td>\n",
" <td>24.951954</td>\n",
" <td>22.024896</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>1.0</td>\n",
" <td>0.699376</td>\n",
" <td>-0.164822</td>\n",
" <td>1.277675</td>\n",
" <td>-1.814968</td>\n",
" <td>-0.757798</td>\n",
" <td>0.253259</td>\n",
" <td>True</td>\n",
" <td>8.803943</td>\n",
" <td>0.542946</td>\n",
" <td>-2.670037</td>\n",
" <td>0.290079</td>\n",
" <td>-0.104658</td>\n",
" <td>-1.642732</td>\n",
" <td>3.386802</td>\n",
" <td>False</td>\n",
" <td>6.253032</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>1.0</td>\n",
" <td>0.669321</td>\n",
" <td>0.703854</td>\n",
" <td>0.818505</td>\n",
" <td>0.106033</td>\n",
" <td>0.139291</td>\n",
" <td>-0.996312</td>\n",
" <td>0.0</td>\n",
" <td>0.369742</td>\n",
" <td>-0.503177</td>\n",
" <td>0.160772</td>\n",
" <td>2.177942</td>\n",
" <td>-0.401280</td>\n",
" <td>1.727678</td>\n",
" <td>True</td>\n",
" <td>15.721275</td>\n",
" <td>25.160176</td>\n",
" </tr>\n",
" <tr>\n",
" <th>...</th>\n",
@ -157,63 +157,63 @@
" </tr>\n",
" <tr>\n",
" <th>9995</th>\n",
" <td>1.0</td>\n",
" <td>0.952999</td>\n",
" <td>0.983547</td>\n",
" <td>1.205418</td>\n",
" <td>-0.845736</td>\n",
" <td>-1.665635</td>\n",
" <td>-0.285645</td>\n",
" <td>True</td>\n",
" <td>9.965975</td>\n",
" <td>0.0</td>\n",
" <td>0.314375</td>\n",
" <td>0.410457</td>\n",
" <td>0.025014</td>\n",
" <td>-1.307578</td>\n",
" <td>0.495262</td>\n",
" <td>0.247480</td>\n",
" <td>False</td>\n",
" <td>-2.947694</td>\n",
" </tr>\n",
" <tr>\n",
" <th>9996</th>\n",
" <td>1.0</td>\n",
" <td>0.893868</td>\n",
" <td>0.147810</td>\n",
" <td>0.320192</td>\n",
" <td>-0.776280</td>\n",
" <td>-0.458415</td>\n",
" <td>-0.824306</td>\n",
" <td>0.0</td>\n",
" <td>0.134332</td>\n",
" <td>-0.249336</td>\n",
" <td>0.936425</td>\n",
" <td>0.620813</td>\n",
" <td>1.940425</td>\n",
" <td>0.880728</td>\n",
" <td>True</td>\n",
" <td>8.452899</td>\n",
" <td>18.983531</td>\n",
" </tr>\n",
" <tr>\n",
" <th>9997</th>\n",
" <td>0.0</td>\n",
" <td>0.818243</td>\n",
" <td>0.422534</td>\n",
" <td>-0.360710</td>\n",
" <td>-0.761213</td>\n",
" <td>-1.156205</td>\n",
" <td>0.996336</td>\n",
" <td>0.121186</td>\n",
" <td>0.285559</td>\n",
" <td>0.554069</td>\n",
" <td>0.496691</td>\n",
" <td>-0.324387</td>\n",
" <td>-2.102712</td>\n",
" <td>True</td>\n",
" <td>5.366551</td>\n",
" <td>4.754810</td>\n",
" </tr>\n",
" <tr>\n",
" <th>9998</th>\n",
" <td>1.0</td>\n",
" <td>0.485403</td>\n",
" <td>0.665532</td>\n",
" <td>1.046824</td>\n",
" <td>-1.026499</td>\n",
" <td>0.815819</td>\n",
" <td>2.431939</td>\n",
" <td>0.0</td>\n",
" <td>0.400960</td>\n",
" <td>-0.326070</td>\n",
" <td>1.179469</td>\n",
" <td>1.196163</td>\n",
" <td>-0.216770</td>\n",
" <td>-0.173123</td>\n",
" <td>True</td>\n",
" <td>20.121092</td>\n",
" <td>15.567185</td>\n",
" </tr>\n",
" <tr>\n",
" <th>9999</th>\n",
" <td>0.0</td>\n",
" <td>0.334394</td>\n",
" <td>1.608105</td>\n",
" <td>-1.329177</td>\n",
" <td>-2.369921</td>\n",
" <td>0.185035</td>\n",
" <td>-0.092841</td>\n",
" <td>1.0</td>\n",
" <td>0.831188</td>\n",
" <td>0.038508</td>\n",
" <td>-0.016273</td>\n",
" <td>-0.491554</td>\n",
" <td>0.557856</td>\n",
" <td>-0.444803</td>\n",
" <td>True</td>\n",
" <td>10.156217</td>\n",
" <td>6.544583</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
@ -221,36 +221,36 @@
"</div>"
],
"text/plain": [
" Z0 Z1 W0 W1 W2 W3 W4 v0 \\\n",
"0 1.0 0.977197 -0.513249 -1.085495 -0.947936 -0.836739 -0.241959 True \n",
"1 1.0 0.133648 1.718109 1.532397 -0.441355 0.338025 1.321070 True \n",
"2 0.0 0.261689 2.167228 -0.133905 -0.641217 1.669584 0.555210 True \n",
"3 1.0 0.699376 -0.164822 1.277675 -1.814968 -0.757798 0.253259 True \n",
"4 1.0 0.669321 0.703854 0.818505 0.106033 0.139291 -0.996312 True \n",
"... ... ... ... ... ... ... ... ... \n",
"9995 1.0 0.952999 0.983547 1.205418 -0.845736 -1.665635 -0.285645 True \n",
"9996 1.0 0.893868 0.147810 0.320192 -0.776280 -0.458415 -0.824306 True \n",
"9997 0.0 0.818243 0.422534 -0.360710 -0.761213 -1.156205 0.996336 True \n",
"9998 1.0 0.485403 0.665532 1.046824 -1.026499 0.815819 2.431939 True \n",
"9999 0.0 0.334394 1.608105 -1.329177 -2.369921 0.185035 -0.092841 True \n",
" Z0 Z1 W0 W1 W2 W3 W4 v0 \\\n",
"0 1.0 0.297495 1.104464 -1.243507 2.078729 -0.035286 -1.763171 True \n",
"1 1.0 0.940643 1.552100 0.374128 -0.198048 -0.202730 0.024421 True \n",
"2 1.0 0.782048 0.413752 -0.404527 1.963213 1.579329 0.539134 True \n",
"3 1.0 0.542946 -2.670037 0.290079 -0.104658 -1.642732 3.386802 False \n",
"4 0.0 0.369742 -0.503177 0.160772 2.177942 -0.401280 1.727678 True \n",
"... ... ... ... ... ... ... ... ... \n",
"9995 0.0 0.314375 0.410457 0.025014 -1.307578 0.495262 0.247480 False \n",
"9996 0.0 0.134332 -0.249336 0.936425 0.620813 1.940425 0.880728 True \n",
"9997 0.0 0.121186 0.285559 0.554069 0.496691 -0.324387 -2.102712 True \n",
"9998 0.0 0.400960 -0.326070 1.179469 1.196163 -0.216770 -0.173123 True \n",
"9999 1.0 0.831188 0.038508 -0.016273 -0.491554 0.557856 -0.444803 True \n",
"\n",
" y \n",
"0 -0.443120 \n",
"1 23.899661 \n",
"2 24.951954 \n",
"3 8.803943 \n",
"4 15.721275 \n",
"0 11.701762 \n",
"1 13.893867 \n",
"2 22.024896 \n",
"3 6.253032 \n",
"4 25.160176 \n",
"... ... \n",
"9995 9.965975 \n",
"9996 8.452899 \n",
"9997 5.366551 \n",
"9998 20.121092 \n",
"9999 10.156217 \n",
"9995 -2.947694 \n",
"9996 18.983531 \n",
"9997 4.754810 \n",
"9998 15.567185 \n",
"9999 6.544583 \n",
"\n",
"[10000 rows x 9 columns]"
]
},
"execution_count": 26,
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
@ -290,7 +290,7 @@
},
{
"cell_type": "code",
"execution_count": 27,
"execution_count": 4,
"metadata": {},
"outputs": [
{
@ -315,7 +315,7 @@
},
{
"cell_type": "code",
"execution_count": 28,
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
@ -324,7 +324,7 @@
},
{
"cell_type": "code",
"execution_count": 29,
"execution_count": 6,
"metadata": {},
"outputs": [
{
@ -352,14 +352,14 @@
},
{
"cell_type": "code",
"execution_count": 30,
"execution_count": 7,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"INFO:dowhy.causal_identifier:Common causes of treatment and outcome:['W3', 'W1', 'W4', 'Unobserved Confounders', 'W0', 'W2']\n",
"INFO:dowhy.causal_identifier:Common causes of treatment and outcome:['W2', 'W1', 'W3', 'W0', 'W4', 'Unobserved Confounders']\n",
"WARNING:dowhy.causal_identifier:If this is observed data (not from a randomized experiment), there might always be missing confounders. Causal effect cannot be identified perfectly.\n"
]
},
@ -374,27 +374,27 @@
"name": "stderr",
"output_type": "stream",
"text": [
"INFO:dowhy.causal_identifier:Instrumental variables for treatment and outcome:['Z1', 'Z0']\n"
"INFO:dowhy.causal_identifier:Instrumental variables for treatment and outcome:['Z0', 'Z1']\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Estimand type: ate\n",
"Estimand type: nonparametric-ate\n",
"### Estimand : 1\n",
"Estimand name: backdoor\n",
"Estimand expression:\n",
" d \n",
"───(Expectation(y|W3,W1,W4,W0,W2))\n",
"dv₀ \n",
"Estimand assumption 1, Unconfoundedness: If U→v0 and U→y then P(y|v0,W3,W1,W4,W0,W2,U) = P(y|v0,W3,W1,W4,W0,W2)\n",
" d \n",
"─────(Expectation(y|W2,W1,W3,W0,W4))\n",
"d[v₀] \n",
"Estimand assumption 1, Unconfoundedness: If U→{v0} and U→y then P(y|v0,W2,W1,W3,W0,W4,U) = P(y|v0,W2,W1,W3,W0,W4)\n",
"### Estimand : 2\n",
"Estimand name: iv\n",
"Estimand expression:\n",
"Expectation(Derivative(y, Z1)/Derivative(v0, Z1))\n",
"Estimand assumption 1, As-if-random: If U→→y then ¬(U →→Z1,Z0)\n",
"Estimand assumption 2, Exclusion: If we remove {Z1,Z0}→v0, then ¬(Z1,Z0→y)\n",
"Expectation(Derivative(y, Z0)*Derivative([v0], Z0)**(-1))\n",
"Estimand assumption 1, As-if-random: If U→→y then ¬(U →→Z0,Z1)\n",
"Estimand assumption 2, Exclusion: If we remove {Z0,Z1}→{v0}, then ¬({Z0,Z1}→y)\n",
"\n"
]
}
@ -415,7 +415,7 @@
},
{
"cell_type": "code",
"execution_count": 31,
"execution_count": 8,
"metadata": {},
"outputs": [
{
@ -423,7 +423,7 @@
"output_type": "stream",
"text": [
"INFO:dowhy.causal_estimator:INFO: Using Linear Regression Estimator\n",
"INFO:dowhy.causal_estimator:b: y~v0+W3+W1+W4+W0+W2\n"
"INFO:dowhy.causal_estimator:b: y~v0+W2+W1+W3+W0+W4\n"
]
},
{
@ -433,30 +433,30 @@
"*** Causal Estimate ***\n",
"\n",
"## Target estimand\n",
"Estimand type: ate\n",
"Estimand type: nonparametric-ate\n",
"### Estimand : 1\n",
"Estimand name: backdoor\n",
"Estimand expression:\n",
" d \n",
"───(Expectation(y|W3,W1,W4,W0,W2))\n",
"dv₀ \n",
"Estimand assumption 1, Unconfoundedness: If U→v0 and U→y then P(y|v0,W3,W1,W4,W0,W2,U) = P(y|v0,W3,W1,W4,W0,W2)\n",
" d \n",
"─────(Expectation(y|W2,W1,W3,W0,W4))\n",
"d[v₀] \n",
"Estimand assumption 1, Unconfoundedness: If U→{v0} and U→y then P(y|v0,W2,W1,W3,W0,W4,U) = P(y|v0,W2,W1,W3,W0,W4)\n",
"### Estimand : 2\n",
"Estimand name: iv\n",
"Estimand expression:\n",
"Expectation(Derivative(y, Z1)/Derivative(v0, Z1))\n",
"Estimand assumption 1, As-if-random: If U→→y then ¬(U →→Z1,Z0)\n",
"Estimand assumption 2, Exclusion: If we remove {Z1,Z0}→v0, then ¬(Z1,Z0→y)\n",
"Expectation(Derivative(y, Z0)*Derivative([v0], Z0)**(-1))\n",
"Estimand assumption 1, As-if-random: If U→→y then ¬(U →→Z0,Z1)\n",
"Estimand assumption 2, Exclusion: If we remove {Z0,Z1}→{v0}, then ¬({Z0,Z1}→y)\n",
"\n",
"## Realized estimand\n",
"b: y~v0+W3+W1+W4+W0+W2\n",
"b: y~v0+W2+W1+W3+W0+W4\n",
"## Estimate\n",
"Value: 10.000000000000504\n",
"Value: 9.999999999999938\n",
"\n",
"## Statistical Significance\n",
"p-value: <0.001\n",
"\n",
"Causal Estimate is 10.000000000000504\n"
"Causal Estimate is 9.999999999999938\n"
]
}
],
@ -479,7 +479,7 @@
},
{
"cell_type": "code",
"execution_count": 32,
"execution_count": 9,
"metadata": {},
"outputs": [
{
@ -487,7 +487,7 @@
"output_type": "stream",
"text": [
"INFO:dowhy.causal_estimator:INFO: Using Propensity Score Stratification Estimator\n",
"INFO:dowhy.causal_estimator:b: y~v0+W3+W1+W4+W0+W2\n",
"INFO:dowhy.causal_estimator:b: y~v0+W2+W1+W3+W0+W4\n",
"/home/amit/.local/lib/python3.6/site-packages/sklearn/utils/validation.py:744: 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",
" y = column_or_1d(y, warn=True)\n"
]
@ -499,27 +499,27 @@
"*** Causal Estimate ***\n",
"\n",
"## Target estimand\n",
"Estimand type: ate\n",
"Estimand type: nonparametric-ate\n",
"### Estimand : 1\n",
"Estimand name: backdoor\n",
"Estimand expression:\n",
" d \n",
"───(Expectation(y|W3,W1,W4,W0,W2))\n",
"dv₀ \n",
"Estimand assumption 1, Unconfoundedness: If U→v0 and U→y then P(y|v0,W3,W1,W4,W0,W2,U) = P(y|v0,W3,W1,W4,W0,W2)\n",
" d \n",
"─────(Expectation(y|W2,W1,W3,W0,W4))\n",
"d[v₀] \n",
"Estimand assumption 1, Unconfoundedness: If U→{v0} and U→y then P(y|v0,W2,W1,W3,W0,W4,U) = P(y|v0,W2,W1,W3,W0,W4)\n",
"### Estimand : 2\n",
"Estimand name: iv\n",
"Estimand expression:\n",
"Expectation(Derivative(y, Z1)/Derivative(v0, Z1))\n",
"Estimand assumption 1, As-if-random: If U→→y then ¬(U →→Z1,Z0)\n",
"Estimand assumption 2, Exclusion: If we remove {Z1,Z0}→v0, then ¬(Z1,Z0→y)\n",
"Expectation(Derivative(y, Z0)*Derivative([v0], Z0)**(-1))\n",
"Estimand assumption 1, As-if-random: If U→→y then ¬(U →→Z0,Z1)\n",
"Estimand assumption 2, Exclusion: If we remove {Z0,Z1}→{v0}, then ¬({Z0,Z1}→y)\n",
"\n",
"## Realized estimand\n",
"b: y~v0+W3+W1+W4+W0+W2\n",
"b: y~v0+W2+W1+W3+W0+W4\n",
"## Estimate\n",
"Value: 9.945007020597561\n",
"Value: 9.93104016350243\n",
"\n",
"Causal Estimate is 9.945007020597561\n"
"Causal Estimate is 9.93104016350243\n"
]
}
],
@ -542,7 +542,7 @@
},
{
"cell_type": "code",
"execution_count": 33,
"execution_count": null,
"metadata": {},
"outputs": [
{
@ -550,7 +550,7 @@
"output_type": "stream",
"text": [
"INFO:dowhy.causal_estimator:INFO: Using Propensity Score Matching Estimator\n",
"INFO:dowhy.causal_estimator:b: y~v0+W3+W1+W4+W0+W2\n",
"INFO:dowhy.causal_estimator:b: y~v0+W2+W1+W3+W0+W4\n",
"/home/amit/.local/lib/python3.6/site-packages/sklearn/utils/validation.py:744: 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",
" y = column_or_1d(y, warn=True)\n",
"/mnt/c/Users/amshar/code/dowhy/dowhy/causal_estimators/propensity_score_matching_estimator.py:62: FutureWarning: `item` has been deprecated and will be removed in a future version\n",
@ -558,36 +558,6 @@
"/mnt/c/Users/amshar/code/dowhy/dowhy/causal_estimators/propensity_score_matching_estimator.py:77: FutureWarning: `item` has been deprecated and will be removed in a future version\n",
" treated_outcome = treated.iloc[indices[i]][self._outcome_name].item()\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"*** Causal Estimate ***\n",
"\n",
"## Target estimand\n",
"Estimand type: ate\n",
"### Estimand : 1\n",
"Estimand name: backdoor\n",
"Estimand expression:\n",
" d \n",
"───(Expectation(y|W3,W1,W4,W0,W2))\n",
"dv₀ \n",
"Estimand assumption 1, Unconfoundedness: If U→v0 and U→y then P(y|v0,W3,W1,W4,W0,W2,U) = P(y|v0,W3,W1,W4,W0,W2)\n",
"### Estimand : 2\n",
"Estimand name: iv\n",
"Estimand expression:\n",
"Expectation(Derivative(y, Z1)/Derivative(v0, Z1))\n",
"Estimand assumption 1, As-if-random: If U→→y then ¬(U →→Z1,Z0)\n",
"Estimand assumption 2, Exclusion: If we remove {Z1,Z0}→v0, then ¬(Z1,Z0→y)\n",
"\n",
"## Realized estimand\n",
"b: y~v0+W3+W1+W4+W0+W2\n",
"## Estimate\n",
"Value: 10.106764870393203\n",
"\n",
"Causal Estimate is 10.106764870393203\n"
]
}
],
"source": [
@ -612,56 +582,9 @@
},
{
"cell_type": "code",
"execution_count": 38,
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"INFO:dowhy.causal_estimator:INFO: Using Propensity Score Weighting Estimator\n",
"INFO:dowhy.causal_estimator:b: y~v0+W3+W1+W4+W0+W2\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"*** Causal Estimate ***\n",
"\n",
"## Target estimand\n",
"Estimand type: ate\n",
"### Estimand : 1\n",
"Estimand name: backdoor\n",
"Estimand expression:\n",
" d \n",
"───(Expectation(y|W3,W1,W4,W0,W2))\n",
"dv₀ \n",
"Estimand assumption 1, Unconfoundedness: If U→v0 and U→y then P(y|v0,W3,W1,W4,W0,W2,U) = P(y|v0,W3,W1,W4,W0,W2)\n",
"### Estimand : 2\n",
"Estimand name: iv\n",
"Estimand expression:\n",
"Expectation(Derivative(y, Z1)/Derivative(v0, Z1))\n",
"Estimand assumption 1, As-if-random: If U→→y then ¬(U →→Z1,Z0)\n",
"Estimand assumption 2, Exclusion: If we remove {Z1,Z0}→v0, then ¬(Z1,Z0→y)\n",
"\n",
"## Realized estimand\n",
"b: y~v0+W3+W1+W4+W0+W2\n",
"## Estimate\n",
"Value: 11.152230663995484\n",
"\n",
"Causal Estimate is 11.152230663995484\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"/home/amit/.local/lib/python3.6/site-packages/sklearn/utils/validation.py:744: 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",
" y = column_or_1d(y, warn=True)\n"
]
}
],
"outputs": [],
"source": [
"causal_estimate_ipw = model.estimate_effect(identified_estimand,\n",
" method_name=\"backdoor.propensity_score_weighting\",\n",
@ -682,68 +605,11 @@
},
{
"cell_type": "code",
"execution_count": 35,
"execution_count": null,
"metadata": {
"scrolled": true
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"INFO:dowhy.causal_estimator:INFO: Using Instrumental Variable Estimator\n",
"INFO:dowhy.causal_estimator:Realized estimand: Wald Estimator\n",
"Realized estimand type: ate\n",
"Estimand expression:\n",
" -1\n",
"Expectation(Derivative(y, Z1))⋅Expectation(Derivative(v0, Z1)) \n",
"Estimand assumption 1, As-if-random: If U→→y then ¬(U →→Z1,Z0)\n",
"Estimand assumption 2, Exclusion: If we remove {Z1,Z0}→v0, then ¬(Z1,Z0→y)\n",
"Estimand assumption 3, treatment_effect_homogeneity: Each unit's treatment ['v0'] isaffected in the same way by common causes of ['v0'] and y\n",
"Estimand assumption 4, outcome_effect_homogeneity: Each unit's outcome y isaffected in the same way by common causes of ['v0'] and y\n",
"\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"*** Causal Estimate ***\n",
"\n",
"## Target estimand\n",
"Estimand type: ate\n",
"### Estimand : 1\n",
"Estimand name: backdoor\n",
"Estimand expression:\n",
" d \n",
"───(Expectation(y|W3,W1,W4,W0,W2))\n",
"dv₀ \n",
"Estimand assumption 1, Unconfoundedness: If U→v0 and U→y then P(y|v0,W3,W1,W4,W0,W2,U) = P(y|v0,W3,W1,W4,W0,W2)\n",
"### Estimand : 2\n",
"Estimand name: iv\n",
"Estimand expression:\n",
"Expectation(Derivative(y, Z1)/Derivative(v0, Z1))\n",
"Estimand assumption 1, As-if-random: If U→→y then ¬(U →→Z1,Z0)\n",
"Estimand assumption 2, Exclusion: If we remove {Z1,Z0}→v0, then ¬(Z1,Z0→y)\n",
"\n",
"## Realized estimand\n",
"Realized estimand: Wald Estimator\n",
"Realized estimand type: ate\n",
"Estimand expression:\n",
" -1\n",
"Expectation(Derivative(y, Z1))⋅Expectation(Derivative(v0, Z1)) \n",
"Estimand assumption 1, As-if-random: If U→→y then ¬(U →→Z1,Z0)\n",
"Estimand assumption 2, Exclusion: If we remove {Z1,Z0}→v0, then ¬(Z1,Z0→y)\n",
"Estimand assumption 3, treatment_effect_homogeneity: Each unit's treatment ['v0'] isaffected in the same way by common causes of ['v0'] and y\n",
"Estimand assumption 4, outcome_effect_homogeneity: Each unit's outcome y isaffected in the same way by common causes of ['v0'] and y\n",
"\n",
"## Estimate\n",
"Value: 9.082237126676432\n",
"\n",
"Causal Estimate is 9.082237126676432\n"
]
}
],
"outputs": [],
"source": [
"causal_estimate_iv = model.estimate_effect(identified_estimand,\n",
" method_name=\"iv.instrumental_variable\", method_params = {'iv_instrument_name': 'Z0'})\n",
@ -762,82 +628,9 @@
},
{
"cell_type": "code",
"execution_count": 36,
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"INFO:dowhy.causal_estimator:Using Regression Discontinuity Estimator\n",
"INFO:dowhy.causal_estimator:\n",
"INFO:dowhy.causal_estimator:INFO: Using Instrumental Variable Estimator\n",
"INFO:dowhy.causal_estimator:Realized estimand: Wald Estimator\n",
"Realized estimand type: ate\n",
"Estimand expression:\n",
" -1\n",
"Expectation(Derivative(y, Z1))⋅Expectation(Derivative(v0, Z1)) \n",
"Estimand assumption 1, As-if-random: If U→→y then ¬(U →→Z1,Z0)\n",
"Estimand assumption 2, Exclusion: If we remove {Z1,Z0}→v0, then ¬(Z1,Z0→y)\n",
"Estimand assumption 3, treatment_effect_homogeneity: Each unit's treatment ['local_treatment'] isaffected in the same way by common causes of ['local_treatment'] and local_outcome\n",
"Estimand assumption 4, outcome_effect_homogeneity: Each unit's outcome local_outcome isaffected in the same way by common causes of ['local_treatment'] and local_outcome\n",
"\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
" local_rd_variable local_treatment local_outcome\n",
"22 0.413325 True 1.597864\n",
"31 0.567281 True 11.847969\n",
"33 0.558196 False -1.704836\n",
"35 0.589582 True 15.232575\n",
"37 0.415546 True 12.738279\n",
"... ... ... ...\n",
"9981 0.503160 True 10.459732\n",
"9986 0.405848 True 10.421814\n",
"9989 0.404516 True 14.520292\n",
"9990 0.551019 True 19.378382\n",
"9998 0.485403 True 20.121092\n",
"\n",
"[1970 rows x 3 columns]\n",
"*** Causal Estimate ***\n",
"\n",
"## Target estimand\n",
"Estimand type: ate\n",
"### Estimand : 1\n",
"Estimand name: backdoor\n",
"Estimand expression:\n",
" d \n",
"───(Expectation(y|W3,W1,W4,W0,W2))\n",
"dv₀ \n",
"Estimand assumption 1, Unconfoundedness: If U→v0 and U→y then P(y|v0,W3,W1,W4,W0,W2,U) = P(y|v0,W3,W1,W4,W0,W2)\n",
"### Estimand : 2\n",
"Estimand name: iv\n",
"Estimand expression:\n",
"Expectation(Derivative(y, Z1)/Derivative(v0, Z1))\n",
"Estimand assumption 1, As-if-random: If U→→y then ¬(U →→Z1,Z0)\n",
"Estimand assumption 2, Exclusion: If we remove {Z1,Z0}→v0, then ¬(Z1,Z0→y)\n",
"\n",
"## Realized estimand\n",
"Realized estimand: Wald Estimator\n",
"Realized estimand type: ate\n",
"Estimand expression:\n",
" -1\n",
"Expectation(Derivative(y, Z1))⋅Expectation(Derivative(v0, Z1)) \n",
"Estimand assumption 1, As-if-random: If U→→y then ¬(U →→Z1,Z0)\n",
"Estimand assumption 2, Exclusion: If we remove {Z1,Z0}→v0, then ¬(Z1,Z0→y)\n",
"Estimand assumption 3, treatment_effect_homogeneity: Each unit's treatment ['local_treatment'] isaffected in the same way by common causes of ['local_treatment'] and local_outcome\n",
"Estimand assumption 4, outcome_effect_homogeneity: Each unit's outcome local_outcome isaffected in the same way by common causes of ['local_treatment'] and local_outcome\n",
"\n",
"## Estimate\n",
"Value: 10.354383271697392\n",
"\n",
"Causal Estimate is 10.354383271697392\n"
]
}
],
"outputs": [],
"source": [
"causal_estimate_regdist = model.estimate_effect(identified_estimand,\n",
" method_name=\"iv.regression_discontinuity\", \n",

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

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

@ -71,6 +71,7 @@ class CausalGraph:
if missing_nodes_as_confounders:
self._graph = self.add_missing_nodes_as_common_causes(observed_node_names)
self._graph = self.add_node_attributes(observed_node_names)
#TODO do not add it here. CausalIdentifier should call causal_graph to add an unobserved common cause if needed. This also ensures that we do not need get_common_causes in this class.
self._graph = self.add_unobserved_common_cause(observed_node_names)
def view_graph(self, layout="dot"):
@ -220,6 +221,7 @@ class CausalGraph:
"""
Assume that nodes1 causes nodes2 (e.g., nodes1 are the treatments and nodes2 are the outcomes)
"""
# TODO Refactor to remove this from here and only implement this logic in causalIdentifier. Unnecessary assumption of nodes1 to be causing nodes2.
nodes1 = parse_state(nodes1)
nodes2 = parse_state(nodes2)
causes_1 = set()

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

@ -79,29 +79,32 @@ class CausalIdentifier:
outcome_name, common_causes):
# TODO: outputs string for now, but ideally should do symbolic
# expressions Mon 19 Feb 2018 04:54:17 PM DST
# TODO Better support for multivariate treatments
expr = None
if estimand_type == "ate":
# [TODO: support multivariate states]
if estimand_type == "nonparametric-ate":
outcome_name = outcome_name[0]
treatment_name = treatment_name[0]
num_expr_str = outcome_name
if len(common_causes)>0:
num_expr_str += "|" + ",".join(common_causes)
expr = "d(" + num_expr_str + ")/d" + treatment_name
expr = "d(" + num_expr_str + ")/d" + ",".join(treatment_name)
sym_mu = sp.Symbol("mu")
sym_sigma = sp.Symbol("sigma", positive=True)
sym_outcome = spstats.Normal(num_expr_str, sym_mu, sym_sigma)
# sym_common_causes = [sp.stats.Normal(common_cause, sym_mu, sym_sigma) for common_cause in common_causes]
sym_treatment = sp.Symbol(treatment_name)
sym_treatment_symbols = [sp.Symbol(t) for t in treatment_name]
sym_treatment = sp.Array(sym_treatment_symbols)
sym_conditional_outcome = spstats.Expectation(sym_outcome)
sym_effect = sp.Derivative(sym_conditional_outcome, sym_treatment)
sym_assumptions = {
'Unconfoundedness': (
u"If U\N{RIGHTWARDS ARROW}{0} and U\N{RIGHTWARDS ARROW}{1}"
u"If U\N{RIGHTWARDS ARROW}{{{0}}} and U\N{RIGHTWARDS ARROW}{1}"
" then P({1}|{0},{2},U) = P({1}|{0},{2})"
).format(treatment_name, outcome_name, ",".join(common_causes))
).format(",".join(treatment_name), outcome_name, ",".join(common_causes))
}
else:
raise ValueError("Estimand type not supported. Supported estimand types are 'non-parametric-ate'.")
estimand = {
'estimand': sym_effect,
@ -111,13 +114,14 @@ class CausalIdentifier:
def construct_iv_estimand(self, estimand_type, treatment_name,
outcome_name, instrument_names):
# TODO: support multivariate treatments better.
expr = None
if estimand_type == "ate":
# [TODO: support multivariate states]
if estimand_type == "nonparametric-ate":
outcome_name = outcome_name[0]
treatment_name = treatment_name[0]
sym_outcome = spstats.Normal(outcome_name, 0, 1)
sym_treatment = spstats.Normal(treatment_name, 0, 1)
sym_treatment_symbols = [spstats.Normal(t, 0, 1) for t in treatment_name]
sym_treatment = sp.Array(sym_treatment_symbols)
#sym_treatment = spstats.Normal(treatment_name, 0, 1)
sym_instrument = sp.Symbol(instrument_names[0]) # ",".join(instrument_names))
sym_outcome_derivative = sp.Derivative(sym_outcome, sym_instrument)
sym_treatment_derivative = sp.Derivative(sym_treatment, sym_instrument)
@ -128,11 +132,13 @@ class CausalIdentifier:
"\N{NOT SIGN}(U \N{RIGHTWARDS ARROW}\N{RIGHTWARDS ARROW}{1})"
).format(outcome_name, ",".join(instrument_names)),
"Exclusion": (
u"If we remove {{{0}}}\N{RIGHTWARDS ARROW}{1}, then "
u"\N{NOT SIGN}({0}\N{RIGHTWARDS ARROW}{2})"
).format(",".join(instrument_names), treatment_name,
u"If we remove {{{0}}}\N{RIGHTWARDS ARROW}{{{1}}}, then "
u"\N{NOT SIGN}({{{0}}}\N{RIGHTWARDS ARROW}{2})"
).format(",".join(instrument_names), ",".join(treatment_name),
outcome_name)
}
else:
raise ValueError("Estimand type not supported. Supported estimand types are 'non-parametric-ate'.")
estimand = {
'estimand': sym_effect,

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

@ -27,7 +27,7 @@ class CausalModel:
def __init__(self, data, treatment, outcome, graph=None,
common_causes=None, instruments=None,
effect_modifiers=None,
estimand_type="ate",
estimand_type="nonparametric-ate",
proceed_when_unidentifiable=False,
missing_nodes_as_confounders=False,
**kwargs):
@ -49,7 +49,7 @@ class CausalModel:
:param instruments: names of instrumental variables for the effect of
treatment on outcome
:param effect_modifiers: names of variables that can modify the treatment effect (useful for heterogeneous treatment effect estimation)
:param estimand_type: the type of estimand requested (can be "ate" for average treatment effect, "att" for average treatment effect on the treated", and "atc", for average treatment effect on the control population.
:param estimand_type: the type of estimand requested (currently only "nonparametric-ate" is supported). In the future, may support other specific parametric forms of identification.
:proceed_when_unidentifiable: does the identification proceed by ignoring potential unobserved confounders. Binary flag.
:missing_nodes_as_confounders: Binary flag indicating whether variables in the dataframe that are not included in the causal graph, should be automatically included as confounder nodes.