Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve estimation table #379

Merged
merged 29 commits into from
Apr 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
ebfc129
start implementing that strings are wrapped by multicolumns
ChristianZimpelmann Aug 1, 2022
8ae9515
add a comment to estimation_table.
ChristianZimpelmann Aug 1, 2022
70dfb1e
make sure that integers are not formatted.
ChristianZimpelmann Aug 22, 2022
dbf71d3
Merge branch 'main' into improve_estimation_table
ChristianZimpelmann Aug 23, 2022
797c1fe
minor adjustments.
ChristianZimpelmann Aug 23, 2022
da83005
adjust tests to changes. Some cosmetic changes.
ChristianZimpelmann Aug 23, 2022
a3a2f7f
Merge branch 'main' into improve_estimation_table
segsell Aug 26, 2022
bb8a06b
small fixes in number formatting functions
mpetrosian Aug 27, 2022
675187a
small code imp
mpetrosian Aug 27, 2022
246b033
small code improvement
mpetrosian Aug 27, 2022
1337c19
Improve formatting functions in estimation table
mpetrosian Aug 29, 2022
16ff5ad
update tests
mpetrosian Aug 29, 2022
d491507
fix bug in _center_align_integers_and_non_numeric_strings
mpetrosian Aug 31, 2022
8c785bb
fix bug in center align integers in footer.
ChristianZimpelmann Nov 25, 2022
f15f46a
fix typo in docstring.
ChristianZimpelmann Mar 29, 2023
076b3a0
fix another typo in docstring.
ChristianZimpelmann Mar 29, 2023
fce26ed
change name of test.
ChristianZimpelmann Mar 30, 2023
2b7c853
merge main and solve merge conflict.
ChristianZimpelmann Mar 30, 2023
cf22e38
Merge branch 'main' into improve_estimation_table
ChristianZimpelmann Mar 31, 2023
1fc15f1
Merge branch 'main' into improve_estimation_table
ChristianZimpelmann Apr 6, 2023
9ec6870
add documentation of how to add additional information to the footer.
ChristianZimpelmann Apr 6, 2023
e8e5aca
let notebook run through completely.
ChristianZimpelmann Apr 6, 2023
5a1c44b
add one sentence proposed by HM.
ChristianZimpelmann Apr 6, 2023
05ef572
merge main.
ChristianZimpelmann Apr 9, 2023
57756fc
ignore PerformanceWarnings in estimation_table.
ChristianZimpelmann Apr 9, 2023
c2a8aef
adjust how PerformanceWarnings in estimation_table is ignored.
ChristianZimpelmann Apr 9, 2023
6311d58
move ignoring of performance warnings to new outer function.
ChristianZimpelmann Apr 10, 2023
c937907
fix typo.
ChristianZimpelmann Apr 10, 2023
a32f69c
implement ignoring PerformanceWarning with decorator.
ChristianZimpelmann Apr 10, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,22 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"Estimagic can create publication quality tables of parameter estimates in LaTeX or HTML. It works with the results from `estimate_ml` and `estimate_msm` but also supports statsmodels results out of the box. \n",
"\n",
"You can get almost limitless flexibility if you split the table generation into two steps. The fist generates a DataFrame which you can customize to your liking, the second renders that DataFrame in LaTeX or HTML."
"You can get almost limitless flexibility if you split the table generation into two steps. The fist generates a DataFrame which you can customize to your liking, the second renders that DataFrame in LaTeX or HTML. If you are interested in this feature, search for \"render_inputs\" below."
]
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 24,
"metadata": {},
"outputs": [],
"source": [
"# Make necessary imports\n",
"import estimagic as em\n",
"import pandas as pd\n",
"import statsmodels.formula.api as sm\n",
Expand All @@ -38,7 +40,7 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 25,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -50,7 +52,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 26,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -156,7 +158,7 @@
"<IPython.core.display.HTML object>"
]
},
"execution_count": 3,
"execution_count": 26,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -181,7 +183,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 27,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -240,7 +242,7 @@
"Sex -33.789 1.61800 1.000000e-08"
]
},
"execution_count": 4,
"execution_count": 27,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -266,7 +268,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 28,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -276,7 +278,7 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 29,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -398,7 +400,7 @@
"<IPython.core.display.HTML object>"
]
},
"execution_count": 6,
"execution_count": 29,
"metadata": {},
"output_type": "execute_result"
}
Expand Down Expand Up @@ -436,7 +438,7 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 30,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -514,7 +516,7 @@
"F Statistic 8.06$^{***}$ 72.90$^{***}$ "
]
},
"execution_count": 7,
"execution_count": 30,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -534,7 +536,7 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 31,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -638,7 +640,7 @@
"<IPython.core.display.HTML object>"
]
},
"execution_count": 8,
"execution_count": 31,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -648,6 +650,140 @@
"HTML(em.render_html(**render_inputs))"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"Using this 2-step-procedure, we can also easily add additional rows to the footer.\n",
"\n",
"Note that we add the row using `.loc[(\"Statsmodels\", )]` since the index of `render_inputs[\"footer\"]` is a MultiIndex.\n",
"\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 32,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<table>\n",
" <thead>\n",
" <tr>\n",
" <th >&nbsp;</th>\n",
" <th colspan=\"3\">target</th>\n",
" </tr>\n",
" <tr>\n",
" <th >&nbsp;</th>\n",
" <th >(1)</th>\n",
" <th >(2)</th>\n",
" <th >(3)</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th >Intercept</th>\n",
" <td >152.00$^{*** }$</td>\n",
" <td >152.00$^{*** }$</td>\n",
" <td >142.00$^{*** }$</td>\n",
" </tr>\n",
" <tr>\n",
" <th ></th>\n",
" <td >(3.61)</td>\n",
" <td >(2.85)</td>\n",
" <td >(3.14)</td>\n",
" </tr>\n",
" <tr>\n",
" <th >Age</th>\n",
" <td >301.00$^{*** }$</td>\n",
" <td >37.20$^{ }$</td>\n",
" <td >51.50$^{*** }$</td>\n",
" </tr>\n",
" <tr>\n",
" <th ></th>\n",
" <td >(77.10)</td>\n",
" <td >(64.10)</td>\n",
" <td >(2.72)</td>\n",
" </tr>\n",
" <tr>\n",
" <th >Sex</th>\n",
" <td >17.40$^{ }$</td>\n",
" <td >-107.00$^{* }$</td>\n",
" <td >-33.80$^{*** }$</td>\n",
" </tr>\n",
" <tr>\n",
" <th ></th>\n",
" <td >(77.10)</td>\n",
" <td >(62.10)</td>\n",
" <td >(1.62)</td>\n",
" </tr>\n",
" <tr>\n",
" <th >BMI</th>\n",
" <td ></td>\n",
" <td >787.00$^{*** }$</td>\n",
" <td ></td>\n",
" </tr>\n",
" <tr>\n",
" <th ></th>\n",
" <td ></td>\n",
" <td >(65.40)</td>\n",
" <td ></td>\n",
" </tr>\n",
" <tr>\n",
" <th >ABP</th>\n",
" <td ></td>\n",
" <td >417.00$^{*** }$</td>\n",
" <td ></td>\n",
" </tr>\n",
" <tr>\n",
" <th ></th>\n",
" <td ></td>\n",
" <td >(69.50)</td>\n",
" <td ></td>\n",
" </tr>\n",
" <tr><td colspan=\"4\" style=\"border-bottom: 1px solid black\">\n",
" </td></tr> <tbody>\n",
" <tr>\n",
" <th >R$^2$</th>\n",
" <td >0.04</td>\n",
" <td >0.40</td>\n",
" <td ></td>\n",
" </tr>\n",
" <tr>\n",
" <th >Observations</th>\n",
" <td >442</td>\n",
" <td >442</td>\n",
" <td >445</td>\n",
" </tr>\n",
" <tr>\n",
" <th >Statsmodels</th>\n",
" <td >Yes</td>\n",
" <td >Yes</td>\n",
" <td >No</td>\n",
" </tr>\n",
" <tr><td colspan=\"4\" style=\"border-bottom: 1px solid black\">\n",
" </td></tr>\n",
" <tr><td style=\"text-align: left\">Note:</td><td colspan=\"3\"\n",
" style=\"text-align: right\"><sup>***</sup>p&lt;0.01; <sup>**</sup>p&lt;0.05; <sup>*</sup>p&lt;0.1 </td></tbody>\n",
"</table>"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"execution_count": 32,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"render_inputs[\"footer\"].loc[(\"Statsmodels\",)] = [\"Yes\"] * 2 + [\"No\"]\n",
"HTML(em.render_html(**render_inputs))"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand All @@ -659,7 +795,7 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 33,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -675,7 +811,7 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": 34,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -798,7 +934,7 @@
"<IPython.core.display.HTML object>"
]
},
"execution_count": 10,
"execution_count": 34,
"metadata": {},
"output_type": "execute_result"
}
Expand Down Expand Up @@ -937,6 +1073,11 @@
"\\end{tabular}\n",
"```"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": []
}
],
"metadata": {
Expand All @@ -962,7 +1103,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.8"
"version": "3.10.10"
}
},
"nbformat": 4,
Expand Down
4 changes: 2 additions & 2 deletions src/estimagic/differentiation/derivatives.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def first_derivative(
error_handling (str): One of "continue" (catch errors and continue to calculate
derivative estimates. In this case, some derivative estimates can be
missing but no errors are raised), "raise" (catch errors and continue
to calculate derivative estimates at fist but raise an error if all
to calculate derivative estimates at first but raise an error if all
evaluations for one parameter failed) and "raise_strict" (raise an error
as soon as a function evaluation fails).
batch_evaluator (str or callable): Name of a pre-implemented batch evaluator
Expand Down Expand Up @@ -360,7 +360,7 @@ def second_derivative(
error_handling (str): One of "continue" (catch errors and continue to calculate
derivative estimates. In this case, some derivative estimates can be
missing but no errors are raised), "raise" (catch errors and continue
to calculate derivative estimates at fist but raise an error if all
to calculate derivative estimates at first but raise an error if all
evaluations for one parameter failed) and "raise_strict" (raise an error
as soon as a function evaluation fails).
batch_evaluator (str or callable): Name of a pre-implemented batch evaluator
Expand Down
2 changes: 1 addition & 1 deletion src/estimagic/optimization/internal_criterion_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def internal_criterion_and_derivative_template(
derivative.
criterion_and_derivative (callable): Function that returns criterion
and derivative as a tuple. This can be used to exploit synergies in the
evaluation of both functions. The fist element of the tuple has to be
evaluation of both functions. The first element of the tuple has to be
exactly the same as the output of criterion. The second has to be exactly
the same as the output of derivative.
numdiff_options (dict): Keyword arguments for the calculation of numerical
Expand Down
4 changes: 2 additions & 2 deletions src/estimagic/optimization/optimize.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def maximize(
derivative_kwargs (dict): Additional keyword arguments for derivative.
criterion_and_derivative (callable): Function that returns criterion
and derivative as a tuple. This can be used to exploit synergies in the
evaluation of both functions. The fist element of the tuple has to be
evaluation of both functions. The first element of the tuple has to be
exactly the same as the output of criterion. The second has to be exactly
the same as the output of derivative.
criterion_and_derivative_kwargs (dict): Additional keyword arguments for
Expand Down Expand Up @@ -300,7 +300,7 @@ def minimize(
derivative_kwargs (dict): Additional keyword arguments for derivative.
criterion_and_derivative (callable): Function that returns criterion
and derivative as a tuple. This can be used to exploit synergies in the
evaluation of both functions. The fist element of the tuple has to be
evaluation of both functions. The first element of the tuple has to be
exactly the same as the output of criterion. The second has to be exactly
the same as the output of derivative.
criterion_and_derivative_kwargs (dict): Additional keyword arguments for
Expand Down
Loading