French Election

French Election data.

Source: FrenchElection/ps_primaire.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

ps_primaire = pd.read_csv(ros_path('FrenchElection/data', 'ps_primaire.txt'), sep=r'\s+')
ps_primaire.head()
nom resultats 00h45 resultats 10h00 rapport
0 Benoit Hamon 454041 582014 0.7801
1 Manuel Valls 388603 498114 0.7801
2 Arnaud Montebourg 218885 280519 0.7803
3 Vincent Peillon 85575 109678 0.7802
4 Francois de Rugy 48521 62124 0.7801

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.