Skip to content

Split "Observed Distributions" out of prob_dist and develop it - #811

Merged
jstac merged 4 commits into
mainfrom
observed-distributions
Aug 3, 2026
Merged

Split "Observed Distributions" out of prob_dist and develop it#811
jstac merged 4 commits into
mainfrom
observed-distributions

Conversation

@jstac

@jstac jstac commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Closes #791.

prob_dist.md was doing two jobs: introducing probability distributions and their families, and working with observed data. This splits the second into its own lecture — Observed Distributions, immediately after prob_dist in the TOC — and develops it well past the compressed treatment it had.

Keeps the name "Observed Distributions" rather than the "Samples vs Distributions" title floated in the issue.

New material in prob_dist

  • Standard deviation. The lecture used it in its opening height example without ever defining it. Defined now, with the units argument for why we prefer it to the variance.
  • Moments. Raw, central and standardized — which retro-fits meaning onto the "first moment" and "second central moment" language already in the text — then skewness and excess kurtosis as the third and fourth standardized moments.
  • Quantiles, the median, quartiles and the interquartile range, after the continuous CDF.
  • Worked values via stats(moments='sk') and ppf, using the lognormal as the contrast against the normal.

On the kurtosis convention: the text defines the fourth standardized moment (normal = 3), then works with excess kurtosis (normal = 0), which matches scipy.stats.kurtosis's default so the printed numbers agree with the prose. A note records that some authors do not subtract the 3.

The new lecture

Sample moments and sample quantiles, then histograms, empirical distribution functions, kernel density estimates, box-and-whisker plots and violin plots. EDFs and box plots are both new to the series.

Three data sets carry it, one per distributional shape:

data skewness mean vs median
US adult heights 0.07 equal
Ames house prices +1.74 (≈0 in logs) mean 13% above
Japanese deaths by age −1.60 mean 82.5, median 85

That gives the moment machinery something to do: the skewness of log house prices is almost exactly zero, which demonstrates the lognormal on real data; and the mean sits above the median in one case and below it in the other, which motivates quantiles as the robust alternative.

Two honest notes rather than tidy stories: the box plot by bedroom count shows a non-monotonic relationship (one-bedroom houses have a higher median than two-bedroom, correlation 0.14), so the text says so and the clean floor-area version becomes an exercise; and Japan's "100 and over" category is 3.3% of all deaths and 5.7% of female deaths, so the spike at the right edge of the histograms is flagged as a recording artifact.

Data hosting

All three data sets come from QuantEcon/data-lectures per that repo's routing rule — including us_adult_heights.csv, which moves out of _static/ here (QuantEcon/data-lectures#27). Its builder was recovered in that PR and reproduces the file byte for byte, so the repoint cannot change lecture output.

The violin-plot link in lln_clt.md is repointed to the new lecture and made a proper {ref} cross-reference rather than a hard-coded intro.quantecon.org URL.

Verification

Both lectures execute end to end against the live data URLs (jupytext → nbconvert), and every reported figure in the prose was read off the actual output.

Convergence and independence

The lecture closes with the convergence material the issue asks for. Larger samples plots ECDFs for n = 10, 100, 1000 against the CDF that generated them, plus sample means against the population mean — the ECDF is the natural vehicle here, since it estimates the CDF with no bin width or bandwidth to choose.

The role of independence then shows the convergence is not automatic, via the degenerate sample: draw X once and set X_i = X for all i. Every X_i has the correct distribution, so each observation is individually valid, but the ECDF is a single step at X and the three curves lie exactly on top of one another — increasing n changes nothing.

A note keeps this honest: independence is sufficient, not necessary, and this same lecture histograms monthly returns that are plainly dependent. What matters is that new observations keep bringing new information. The general question is left to lln_clt.

🤖 Generated with Claude Code

Closes #791. `prob_dist.md` was doing two jobs: introducing probability
distributions, and working with observed data. This splits the second into
its own lecture, sitting immediately after prob_dist in the TOC, and
develops the material well past what was there before.

Retains the name "Observed Distributions" rather than the "Samples vs
Distributions" title floated in the issue.

New material in prob_dist:

- The standard deviation, which the lecture used in its opening height
  example without ever defining.
- Moments generally — raw, central and standardized — which gives meaning
  to the "first moment" and "second central moment" language already in the
  text, then skewness and excess kurtosis as the third and fourth
  standardized moments. Excess kurtosis (normal = 0) is the headline
  convention, matching SciPy's default, with a note that some authors do not
  subtract the 3.
- Quantiles, the median, quartiles and the interquartile range.
- Worked values via `stats(moments='sk')` and `ppf`, with the lognormal as
  the contrast case against the normal.

The new lecture covers sample moments and sample quantiles, then histograms,
empirical distribution functions, kernel density estimates, box-and-whisker
plots and violin plots. Three data sets carry it, one per shape: US adult
heights (skewness 0.07), Ames house prices (1.74, and about zero in logs),
and Japanese deaths by age (-1.60). The mean sits above the median for house
prices and below it for age at death, which motivates the quantiles as
robust alternatives.

Data now comes from QuantEcon/data-lectures per the routing rule in that
repo — including us_adult_heights.csv, which moves out of _static/ here
(QuantEcon/data-lectures#27). Its builder was recovered in that PR and
reproduces the file byte for byte, so the repoint cannot change output.

The violin plot link in lln_clt.md is repointed to the new lecture and made
a proper cross-reference rather than a hard-coded URL.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@netlify

netlify Bot commented Aug 3, 2026

Copy link
Copy Markdown

Deploy Preview for taupe-gaufre-c4e660 ready!

Name Link
🔨 Latest commit 5285edc
🔍 Latest deploy log https://app.netlify.com/projects/taupe-gaufre-c4e660/deploys/6a704481b2996f00082b9f2b
😎 Deploy Preview https://deploy-preview-811--taupe-gaufre-c4e660.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@github-actions

github-actions Bot commented Aug 3, 2026

Copy link
Copy Markdown

@github-actions
github-actions Bot temporarily deployed to pull request August 3, 2026 05:57 Inactive
@github-actions
github-actions Bot temporarily deployed to pull request August 3, 2026 05:57 Inactive
Four fixes from review of the previous commit.

Expectations of functions were used but never defined: the moment
expressions all take the form E[f(X)] for some f, so that form is now
defined explicitly — as a sum in the discrete section and as an integral in
the continuous one — and the variance is written first in E notation and
then as the sum it stands for.

Kurtosis and excess kurtosis are two distinct quantities and are now defined
as such: kurtosis as the fourth standardized moment (normal = 3), and excess
kurtosis as that minus 3 (normal = 0). Previously the lecture defined only
the excess version and treated the other name as a caveat. The note is now
about software rather than authors, since the real trap is that
scipy.stats.kurtosis returns the excess version despite its name.

The lecture had only two top-level sections, one of which held everything.
"Common distributions" is dropped as a wrapper, promoting "Discrete
distributions" and "Continuous distributions" to top level and the
individual families to sections within them.

Scalar outputs printed as np.float64(0.0) under NumPy 2. Setting
np.set_printoptions(legacy='1.25') in both lectures restores plain scalar
output without affecting how arrays print.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@github-actions
github-actions Bot temporarily deployed to pull request August 3, 2026 06:39 Inactive
@github-actions
github-actions Bot temporarily deployed to pull request August 3, 2026 06:39 Inactive
Uses ECDF throughout rather than EDF, including the section heading, the
helper function name and the axis labels.

Drops the claim that the normal fit to the log prices misses "in the tails",
which is not visible in the figure — it just says the fit is close but not
perfect.

Adds a KDE of the log sale prices drawn over a faded histogram of the same
data, closing the KDE section by showing what "a smoothed histogram" means
against the histogram it smooths.

Adds a violin plot of age at death by sex, which shows what the box plot
reduces away: both distributions are strongly left-skewed with a thin tail
running down to young ages, and the female distribution is both shifted up
and more concentrated at the top. Medians are shown, at 82 and 88.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@github-actions
github-actions Bot temporarily deployed to pull request August 3, 2026 06:49 Inactive
@github-actions
github-actions Bot temporarily deployed to pull request August 3, 2026 06:51 Inactive
Closes out the lecture with the material the issue asks for.

"Larger samples" shows ECDFs of samples of size 10, 100 and 1000 against the
CDF that generated them — the ECDF is the natural vehicle, since it estimates
the CDF without a bin width or a bandwidth to choose. Sample means for the
same sizes are printed against the population mean. The trailing two
sentences of the previous section, which asserted this convergence and
pointed at the law of large numbers, are absorbed here.

"The role of independence" makes the point that the convergence is not
automatic, using the degenerate sample: draw X once and set X_i = X for all
i. Every X_i then has the correct distribution, so each observation is
individually valid, but the ECDF is a single step at X and increasing n
changes nothing — the three curves lie exactly on top of one another.

A note guards against overclaiming: independence is sufficient, not
necessary, and this lecture histograms monthly returns that are plainly
dependent. What matters is that new observations keep bringing new
information. The general question is left to lln_clt.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@github-actions
github-actions Bot temporarily deployed to pull request August 3, 2026 07:42 Inactive
@github-actions
github-actions Bot temporarily deployed to pull request August 3, 2026 07:43 Inactive
@jstac
jstac merged commit fd3241e into main Aug 3, 2026
7 checks passed
@jstac
jstac deleted the observed-distributions branch August 3, 2026 07:58
jstac added a commit that referenced this pull request Aug 3, 2026
The manual asks every code-generated figure to carry a caption via mystnb
metadata. prob_dist had 3 of 20 and observed_distributions none of 20, the
latter being an oversight in #811.

Adds 35 captions with fig: names for numref, following the manual: sentence
case, six words or fewer, descriptive names.

Two figures are deliberately left bare, one in each lecture. Both sit inside
solution directives, where a caption wraps the image in a LaTeX float and
breaks the PDF build with "Not in outer par mode".

Also fixes a bug found while captioning. The CDF figure in the lognormal
section was built from scipy.stats.norm rather than scipy.stats.lognorm, so
it had been drawing normal CDFs under a lognormal heading, and it looped over
sigma alone with mu pinned to 1 while the density figure above it varied
both. It now uses lognorm over the same (mu, sigma) pairs as that figure, so
the two are a matched pair and the curves start at zero as a distribution on
the positive half-line should.

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

New lecture: split out "Samples vs Distributions" from prob_dist

1 participant