3b: Code-Generated Tables, Figures, and Results
The next step is making the paper generate its own numbers, tables, figures, and model results.
This is an elegant form of reproducible research: the paper is a recipe for the results.
Copying results by hand creates quiet failure points:
Reviewers notice this, and you really don’t want that at the margin.
Some useful examples:
Inline values
Sample size, coefficient estimates, p values, and other single numbers in the text.
Tables
Descriptives, correlations, model summaries, and robustness checks.
Figures
Scatter matrices, distributions, diagnostics, and coefficient plots.
The n value in the sentence comes from Python. If the data changes and we render again, the sentence updates.
Some code is part of the paper’s machinery rather than part of the visible paper. These settings turn off code, warnings, and messages in the rendered paper, but the code still runs.
For this segment, the project needs a few more packages:
maketables for descriptive, correlation, and regression tables;matplotlib for static figures that work well in Word and PDF;statsmodels for regression models and model summaries.We add them to pyproject.toml because they are now part of the project recipe.
The table objects are built in code, then displayed in the paper.
Whenever we use some of the more interesting interactive visualizations, we need to make a static version for the paper.
This is the same fitted model used for the regression table.
Open the 3b activity page.