Death penalty poll

Death penalty poll - Proportion of American adults supporting the death penalty. See Chapter 4 in Regression and Other Stories.

Source: Death/polls.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

dataforandy = pd.read_csv(ros_path('Death/data', 'dataforandy.txt'), sep=r'\s+')
dataforandy.head()

polls = pd.read_csv(ros_path('Death/data', 'polls.dat'), sep=r'\s+')
polls.head()
2002 10
0 70 NaN
1 25 NaN
2 5 NaN
3 2002 5.0
4 72 NaN

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.