Giter VIP home page Giter VIP logo

2024-potus's Introduction

2024 Presidential Forecast

This repository contains the code for running a dynamic and hierarchical Bayesian model that forecasts election outcomes in states, the nation, and the electoral college. The model is written in Stan and the supporting pipeline is written in R.

The model improves upon the Economist’s 2020 model (which, in turn, improved upon Pierre Kemp’s implementation of Drew Linzer’s model) by estimating the parameters used to generate state covariance matrices, rather than being passed the matrices as data. I intend to write a formal explanation of the model, likely after the election has concluded. In the interim, you can view a brief overview of the model definition in the README in the stan/ folder.

A more general overview of the model methodology can be found here, and the full output can be explored here.

Version history

2.2

2024-08-12
  • Added a model review/diagnostic display under out/REVIEW.md

2.1

2024-08-11
  • Added conditional probability plot functions for the National page.

2.0

2024-08-03

Harris Model

  • Modified the prior/polling stan models and supporting R pipelines to support Kamala Harris as the democratic candidate. More details can be found in the stan/ directory README.
  • Updated site functions’ internal variable naming and public facing candidate names to refer to Kamala Harris.
  • Updated time-series plots on site to only display projections from 8/1 onwards.
  • Updated function documentation and READMEs based on new output.
  • Fully re-ran the entire model from 5/1 onwards. An archived version of the final run with Biden as the democratic candidate can be found in the archive-biden branch in this repository.

Other Fixes

  • Corrected the need to run the polling model with the prior_check flag for run dates before 5/7. (#10)
  • render_interactive_map() now correctly renders the ggobj passed as an argument, rather than looking for a specific object in the global environment.
  • Fixed a small bug causing the prior stan model to underestimate uncertainty in the combination of the estimated national voteshare and state partisan lean.

1.2

2024-07-16

1.1

2024-07-14
  • Modified header text to include the article “the” on D.C.’s state page.

1.0

2024-07-04
  • Initial release

Other forecasts

2024-potus's People

Contributors

markjrieke avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

animesh

2024-potus's Issues

1.0 LAUNCH CHECKLIST

Backend

  • update to multivariate normal rng in generated quantities
  • update to 10,000 iterations (1,250 per chain, 8 chains)
  • re-run from 5/1 onwards
  • Add all missing function documentation
  • Update repository README
  • Add sub-dir level READMEs
    • R (add a README with a section for each of the sub-dirs of this folder, i.e., ## data, ## model ...)
    • data
    • out
    • stan

Frontend Support

  • Finalize text
    • Heading
    • EVS blurb
    • Probability blurb
    • Electoral map blurb
    • Voteshare blurb
    • Similarity blurb
  • Formatting
    • Manually set tooltip font in CSS
    • Fix footer (remove attribution for me / D)
    • Add final linebreak
    • Set font color for text (maybe headings?)
    • Adjust manual margin to match {.column-margin} formatting
  • Functionality
    • update generate_links() function to perform internal site linking
    • Add link to model code and output to footer

Site

Tracking in this repository just to keep checklists in one place

  • Write How this works blog
  • National Page
    • Finish qmd body content
    • Add execute param for pulling from main branch
  • State Pages
    • Write qmd body content using workable format
    • Add execute params for pulling from main and specifying state
  • Site-level support
    • Add rendering script
  • Publicize
    • test test test test on dev
    • launch on main
    • draft comms for
      • email
      • linkedin
      • twitter (thread)
      • tr slack wins
      • dsh discord

Bugs

  • Fix issue of missing state-similarity plots on deployed pages with spaces (e.g., New Hampshire, Nebraska CD-1, etc.)

Add conditional probability plots

i.e., "if biden/trump win in x state, the conditional probability of them winning the electoral college increases from a -> b"

not sure if this should be for all states & plopped into the state pages, or just for competitive states and plopped onto the national page

Fix DC header text

Currently says "as of ... Joe biden is all but guaranteed to beat donald trump in District of Columbia." Should instead read as the District of Columbia

Coalesce poll modes

Need to investigate if the difference in ordering is intentional, but if not, need to coalesce poll modes that are just rearrangements of each other. For example:

Live Phone/Online Panel/Text
Live Phone/Text/Online Panel

This is the only example, so even if they do need to be collapsed, only 4/294 polls use either of these patterns, and only 1 uses Live Phone/Text/Online Panel. Would warrant a minor version update only but not a full historical update.

Remove need for running in prior mode pre-5/7

Part of 2.0, but currently the model runs in prior mode from 5/1 -> 5/7. This is just because the fixed effect variables only have one factor for a bit (e.g., only LV polls). The solution is to change the fixed effect variables to not have variable lengths & just map the ids in directly.

Add tracking to output README

render a daily quarto doc that shows:

  • top-level probability change over the past week
  • any states that have changed ratings
  • runtime plot
  • diagnostics plot
  • count of polls plot
  • state probability of winning vs. number of polls (will need to add the state abbr here)
  • biden's forecasted approval
  • the nifty ratings over time plot
  • others (?)

2.0 contingency changes if Biden steps down

  • update model to accommodate 2 democratic candidates
  • model still uses biden v trump polls to inform poll biases, but only gq for harris is used for democratic ticket forecast
  • update pipeline to use a poll aggregation function based on candidate name
  • (possibly) update model to estimate aggregates on the outcome scale
    • see, for example, the dc page. The voteshare credible intervals are a little wonky mostly due to how aggregation works.
    • This is a low priority issue
  • add reference point to time series plots indicating date of switch (i.e., a copy of the 'annotate end date')
  • rerun from 5/1 onwards (?)

filter by created at

possibly filter out polls by the created_at column. Using end_date in the model, but polls that end on a given day aren't necessarily available on that day (would be available by the created_at date, so swap out the filter for end_date with created_at)

Add ability to conduct election night conditional probability updating

Basically just need to write the draws somewhere.

On election night, when any competitive states are called, filter to the subset of draws that match reality. Only needs to be run interactively during election night, so should be a separate script. Likely will want to amp up the number of draws for that run specifically. Will also want to communicate uncertainty around the probability.

This can be a 1.2 level effort that gets done after #4

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.