Helicopters

Example data file for helicopter flying time exercise. See Chapter 1 in Regression and Other Stories.

Source: Helicopters/helicopters.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.

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_path

Data

helicopters = pd.read_csv(ros_path('Helicopters/data', 'helicopters.txt'), sep=r'\s+')
helicopters.head()
Helicopter_ID width_cm length_cm time_sec
0 1 4.6 8.2 1.64
1 1 4.6 8.2 1.74
2 1 4.6 8.2 1.68
3 1 4.6 8.2 1.62
4 1 4.6 8.2 1.68

Notes

  • Source computation blocks represented: 3.
  • 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.