Busabase
Busabase is an open-source (MIT) database and workspace for AI agents — data, docs, skills, and apps in one place. Run it locally, self-host it inside your network, or use Busabase Cloud, and turn age
翻訳待ち
No updates detected yet. GitHub releases will appear here.
Election modeling based on historical data
翻訳待ち
Loading the full README.
Read the full README ↗Election modeling based on historical data
Model Democratic/Republican vote margins in Massachusetts State Senate and State Representative races.
bwbensonjr/ma-election-db - District-level elections and fine-grained census databwbensonjr/ocpf-cli - OCPF command-line toolbwbensonjr/mapoli - Scripts for gathering precinct-level election resultsThe current mapoli legislative model uses a Bayesian regression model with this structure:
dem_margin ~ PVI_N + incumbent_status + pres_elec
dem_margin = (dem_percent - gop_percent) * 100PVI_N = Partisan Voter Index (PVI) which is Democratic/Republican point margin averaged over the last two presidential elections and normalized by the US-wide point margin.incumbent_status
1 if there is a Democratic incumbent in the race0 if there is no incumbent in the race-1 if there is a GOP incumbent in the racepres_elec
1 - The legislative election coincides with a U.S. presidential general election0 - The legislative election does not coincide with a U.S. presidential general electionEvery training row needs two things at the same granularity: the
Democratic/Republican margin for a legislative race, and the PVI_N
built from the two presidential elections preceding that race. State
Senate and State Representative districts split municipalities, so PVI
has to be aggregated to the district from precinct-level
presidential results. Town-level presidential returns cannot be
allocated to a district that contains only part of a town. Precinct
availability for presidential results is therefore the binding
constraint on how far back the data set can reach.
The download/{election_id}/precincts_include:1/ endpoint returns
town-level rows with empty Ward/Pct columns for elections before
precinct reporting begins. It does not error, so the cutoff has to be
detected by inspecting the returned rows.
| Office | First year with precinct results |
|---|---|
| President, Governor, U.S. Senate, U.S. House, State Senate, Governor's Council | 2002 |
| State Representative | 1980 |
State Representative is the exception because rep districts are built out of precincts, so results were always broken out that way. Every other office reports one row per municipality (351 rows) through 2000 and roughly 2,170 precinct rows from the 2002 general onward.
Presidential elections with precinct-level results: 2004, 2008, 2012, 2016, 2020, 2024.
The earliest PVI computable from two precinct-level presidential
elections is the 2008 PVI (2004 + 2008). A race in year Y uses the
PVI from the two most recent presidential elections completed before
Y, which puts the floor at the 2010 legislative elections.
| Race year | PVI year | Source presidentials | District map |
|---|---|---|---|
| 2010 | 2008 | 2004 + 2008 | 2001 |
| 2012 | 2008 | 2004 + 2008 | 2011 (remap required) |
| 2014, 2016 | 2012 | 2008 + 2012 | 2011 |
| 2018, 2020 | 2016 | 2012 + 2016 | 2011 |
| 2022, 2024 | 2022 | 2016 + 2020 | 2021 (remap required) |
| 2026 | 2024 | 2020 + 2024 | 2021 |
pvi_year in mapoli/pvi/ma_state_leg_pvi_2008_2024.csv names the
later of the two presidential elections, except for 2022, which is
the 2020 PVI reallocated to the 2021 district map.
Usable range: the 2010 through 2024 legislative elections, eight cycles, plus 2026 as the forward prediction target. 2008 and earlier are out of reach at any useful granularity: they would require 2000 precinct-level presidential results, which do not exist.
2012 and 2022 are the first elections under new maps, so the prior
presidential votes must be reallocated from old precinct geography to
new districts. This is what mapoli's ma_precincts_districts_*.csv
files do via areal interpolation, and it is why post-2021 vote totals
are fractional rather than integers. Rows on either side of a
redistricting boundary are not strictly comparable and the remapped
PVI values carry interpolation error that the natively-mapped years do
not.
mapoli/pvi holds precinct presidential results
for 2012, 2016, 2020, and 2024, normalized into ma-election-db
as precinct_presidential_vote. This covers races from 2018
onward.District-level legislative results run back to 1990 in
ma-election-db, State Representative precinct results back to 1980,
and State Senate precinct results back to 2002. In every case the
presidential precinct data runs out first.
This is the beginning of the README. Read the rest at the original. Read the full README ↗