-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7b7d5a6
commit 0fe24a6
Showing
3 changed files
with
2,752 additions
and
502 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,92 +22,11 @@ | |
"cell_type": "code", | ||
"execution_count": 1, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/html": [ | ||
"\n", | ||
" <div id=\"f2Mw6R\"></div>\n", | ||
" <script type=\"text/javascript\" data-lets-plot-script=\"library\">\n", | ||
" if(!window.letsPlotCallQueue) {\n", | ||
" window.letsPlotCallQueue = [];\n", | ||
" }; \n", | ||
" window.letsPlotCall = function(f) {\n", | ||
" window.letsPlotCallQueue.push(f);\n", | ||
" };\n", | ||
" (function() {\n", | ||
" var script = document.createElement(\"script\");\n", | ||
" script.type = \"text/javascript\";\n", | ||
" script.src = \"https://cdn.jsdelivr.net/gh/JetBrains/[email protected]/js-package/distr/lets-plot.min.js\";\n", | ||
" script.onload = function() {\n", | ||
" window.letsPlotCall = function(f) {f();};\n", | ||
" window.letsPlotCallQueue.forEach(function(f) {f();});\n", | ||
" window.letsPlotCallQueue = [];\n", | ||
" \n", | ||
" };\n", | ||
" script.onerror = function(event) {\n", | ||
" window.letsPlotCall = function(f) {}; // noop\n", | ||
" window.letsPlotCallQueue = [];\n", | ||
" var div = document.createElement(\"div\");\n", | ||
" div.style.color = 'darkred';\n", | ||
" div.textContent = 'Error loading Lets-Plot JS';\n", | ||
" document.getElementById(\"f2Mw6R\").appendChild(div);\n", | ||
" };\n", | ||
" var e = document.getElementById(\"f2Mw6R\");\n", | ||
" e.appendChild(script);\n", | ||
" })()\n", | ||
" </script>\n", | ||
" " | ||
] | ||
}, | ||
"metadata": {}, | ||
"output_type": "display_data" | ||
}, | ||
{ | ||
"data": { | ||
"text/html": [ | ||
"\n", | ||
" <div id=\"iEmQSv\"></div>\n", | ||
" <script type=\"text/javascript\" data-lets-plot-script=\"library\">\n", | ||
" if(!window.letsPlotCallQueue) {\n", | ||
" window.letsPlotCallQueue = [];\n", | ||
" }; \n", | ||
" window.letsPlotCall = function(f) {\n", | ||
" window.letsPlotCallQueue.push(f);\n", | ||
" };\n", | ||
" (function() {\n", | ||
" var script = document.createElement(\"script\");\n", | ||
" script.type = \"text/javascript\";\n", | ||
" script.src = \"https://cdn.jsdelivr.net/gh/JetBrains/[email protected]/js-package/distr/lets-plot.min.js\";\n", | ||
" script.onload = function() {\n", | ||
" window.letsPlotCall = function(f) {f();};\n", | ||
" window.letsPlotCallQueue.forEach(function(f) {f();});\n", | ||
" window.letsPlotCallQueue = [];\n", | ||
" \n", | ||
" };\n", | ||
" script.onerror = function(event) {\n", | ||
" window.letsPlotCall = function(f) {}; // noop\n", | ||
" window.letsPlotCallQueue = [];\n", | ||
" var div = document.createElement(\"div\");\n", | ||
" div.style.color = 'darkred';\n", | ||
" div.textContent = 'Error loading Lets-Plot JS';\n", | ||
" document.getElementById(\"iEmQSv\").appendChild(div);\n", | ||
" };\n", | ||
" var e = document.getElementById(\"iEmQSv\");\n", | ||
" e.appendChild(script);\n", | ||
" })()\n", | ||
" </script>\n", | ||
" " | ||
] | ||
}, | ||
"metadata": {}, | ||
"output_type": "display_data" | ||
} | ||
], | ||
"outputs": [], | ||
"source": [ | ||
"import pandas as pd\n", | ||
"import numpy as np\n", | ||
"import pyfixest as pf" | ||
"import statsmodels.formula.api as smf" | ||
] | ||
}, | ||
{ | ||
|
@@ -180,7 +99,7 @@ | |
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Linear Regression (`pyfixest`)" | ||
"## Linear Regression " | ||
] | ||
}, | ||
{ | ||
|
@@ -189,21 +108,20 @@ | |
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"[1.62494388 0.0468862 ]\n" | ||
] | ||
"data": { | ||
"text/plain": [ | ||
"(1.624943884109307, 0.04532725031682251)" | ||
] | ||
}, | ||
"execution_count": 3, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"print(\n", | ||
" naive_est := pf.feols(f\"{outcome_column} ~ {treatment_column}\", df)\n", | ||
" .tidy()\n", | ||
" .query(\"Coefficient == 'W'\")\n", | ||
" .iloc[0, :2]\n", | ||
" .values\n", | ||
")" | ||
"naive_lm = smf.ols(f\"{outcome_column} ~ {treatment_column}\", df) .fit(cov_type=\"HC1\")\n", | ||
"naive_est = naive_lm.params.iloc[1], naive_lm.bse.iloc[1]\n", | ||
"naive_est" | ||
] | ||
}, | ||
{ | ||
|
@@ -212,22 +130,21 @@ | |
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"[1.132635 0.02973861]\n" | ||
] | ||
"data": { | ||
"text/plain": [ | ||
"(1.1326349969274776, 0.02972906033475406)" | ||
] | ||
}, | ||
"execution_count": 4, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"print(\n", | ||
" linreg_est := pf.feols(\n", | ||
" f\"{outcome_column} ~ {treatment_column}+{'+'.join(feature_columns)}\", df\n", | ||
" )\n", | ||
" .tidy()\n", | ||
" .query(\"Coefficient == 'W'\")\n", | ||
" .iloc[0, :2].values\n", | ||
")" | ||
"covaradjust_lm = smf.ols(f\"{outcome_column} ~ {treatment_column}+{'+'.join(feature_columns)}\",\n", | ||
" df) .fit(cov_type=\"HC1\")\n", | ||
"linreg_est = covaradjust_lm.params.iloc[1], covaradjust_lm.bse.iloc[1]\n", | ||
"linreg_est" | ||
] | ||
}, | ||
{ | ||
|
@@ -250,7 +167,40 @@ | |
"cell_type": "code", | ||
"execution_count": 5, | ||
"metadata": {}, | ||
"outputs": [], | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/html": [ | ||
"<style type='text/css'>\n", | ||
".datatable table.frame { margin-bottom: 0; }\n", | ||
".datatable table.frame thead { border-bottom: none; }\n", | ||
".datatable table.frame tr.coltypes td { color: #FFFFFF; line-height: 6px; padding: 0 0.5em;}\n", | ||
".datatable .bool { background: #DDDD99; }\n", | ||
".datatable .object { background: #565656; }\n", | ||
".datatable .int { background: #5D9E5D; }\n", | ||
".datatable .float { background: #4040CC; }\n", | ||
".datatable .str { background: #CC4040; }\n", | ||
".datatable .time { background: #40CC40; }\n", | ||
".datatable .row_index { background: var(--jp-border-color3); border-right: 1px solid var(--jp-border-color0); color: var(--jp-ui-font-color3); font-size: 9px;}\n", | ||
".datatable .frame tbody td { text-align: left; }\n", | ||
".datatable .frame tr.coltypes .row_index { background: var(--jp-border-color0);}\n", | ||
".datatable th:nth-child(2) { padding-left: 12px; }\n", | ||
".datatable .hellipsis { color: var(--jp-cell-editor-border-color);}\n", | ||
".datatable .vellipsis { background: var(--jp-layout-color0); color: var(--jp-cell-editor-border-color);}\n", | ||
".datatable .na { color: var(--jp-cell-editor-border-color); font-size: 80%;}\n", | ||
".datatable .sp { opacity: 0.25;}\n", | ||
".datatable .footer { font-size: 9px; }\n", | ||
".datatable .frame_dimensions { background: var(--jp-border-color3); border-top: 1px solid var(--jp-border-color0); color: var(--jp-ui-font-color3); display: inline-block; opacity: 0.6; padding: 1px 10px 1px 5px;}\n", | ||
"</style>\n" | ||
], | ||
"text/plain": [ | ||
"<IPython.core.display.HTML object>" | ||
] | ||
}, | ||
"metadata": {}, | ||
"output_type": "display_data" | ||
} | ||
], | ||
"source": [ | ||
"from metalearners import DRLearner\n", | ||
"from lightgbm import LGBMRegressor, LGBMClassifier\n", | ||
|
@@ -499,8 +449,8 @@ | |
" </tr>\n", | ||
" <tr>\n", | ||
" <th>0.036994</th>\n", | ||
" <td>0.046886</td>\n", | ||
" <td>0.029739</td>\n", | ||
" <td>0.045327</td>\n", | ||
" <td>0.029729</td>\n", | ||
" <td>0.036992</td>\n", | ||
" <td>0.038809</td>\n", | ||
" <td>0.059</td>\n", | ||
|
@@ -512,7 +462,7 @@ | |
"text/plain": [ | ||
" naive linreg metalearners doubleml econml\n", | ||
"est 1.624944 1.132635 1.014673 1.013663 1.069\n", | ||
"0.036994 0.046886 0.029739 0.036992 0.038809 0.059" | ||
"0.036994 0.045327 0.029729 0.036992 0.038809 0.059" | ||
] | ||
}, | ||
"execution_count": 14, | ||
|
@@ -550,7 +500,7 @@ | |
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.10.13" | ||
"version": "3.11.7" | ||
} | ||
}, | ||
"nbformat": 4, | ||
|
Oops, something went wrong.