from pathlib import Path
import sys
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import lapylace as lp
sys.path.append(str(Path.cwd().parent / 'python'))
from data import ros_pathPearson and Lee Heights
The heredity of height. Published in 1903 by Karl Pearson and Alice Lee. See Chapter 6 in Regression and Other Stories.
Source: PearsonLee/heights.Rmd.
The Python version keeps data handling explicit and uses lapylace for Stan-backed generalized linear models, so the statistical model can be read from a formula rather than from handwritten Stan.
Data
heights = pd.read_csv(ros_path('PearsonLee/data', 'Heights.txt'), sep=r'\s+')
heights.head()| daughter_height | mother_height | |
|---|---|---|
| 0 | 52.5 | 59.5 |
| 1 | 52.5 | 59.5 |
| 2 | 53.5 | 59.5 |
| 3 | 53.5 | 59.5 |
| 4 | 55.5 | 59.5 |
Models
The formulas below are the Python counterparts of the model formulas in the source example. Use lapylace for the Stan-backed Bayesian fit with the same formula interface.
# fit = lp.stan_glm('daughter_height ~ mother_height', data=heights, family=lp.gaussian(), chains=4, iter_sampling=1000)Notes
- Source computation blocks represented: 22.
- Data paths are expressed through the shared
ros_path()helper. - Formula-based Bayesian regressions are routed through
lapylace.stan_glm(). - Plotting and simulation work uses NumPy, pandas, matplotlib idioms.