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_pathHealth Expenditure
Health Expenditure - Discovery through graphs of data and models. See Chapter 2 in Regression and Other Stories.
Source: HealthExpenditure/healthexpenditure.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
healthdata = pd.read_csv(ros_path('HealthExpenditure/data', 'healthdata.txt'), sep=r'\s+')
healthdata.head()| country | spending | lifespan | |
|---|---|---|---|
| 0 | Australia | 3357 | 81.4 |
| 1 | Austria | 3763 | 80.1 |
| 2 | Belgium | 3595 | 79.8 |
| 3 | Canada | 3895 | 80.7 |
| 4 | Czech | 1626 | 77.0 |
Notes
- Source computation blocks represented: 14.
- 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.