Gay

Nonlinear models (loess, spline, GP, and BART) and political attitudes as a function of age. See Chapter 22 in Regression and Other Stories.

Source: Gay/gay.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

naes04 = pd.read_csv(ros_path('Gay/data', 'naes04.csv'))
naes04.head()
Unnamed: 0 age gender race gayFavorFederalMarriage gayFavorStateMarriage gayKnowSomeone
0 1 70.0 Female Hispanic No NaN NaN
1 2 54.0 Female White No NaN NaN
2 3 74.0 Male White No NaN NaN
3 4 73.0 Female Other Yes No No
4 5 48.0 Female White No Yes Yes

Notes

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