# Wolfram Function Repository

Instant-use add-on functions for the Wolfram Language

Function Repository Resource:

Import polling data on presidential elections from the website FiveThirtyEight

Contributed by:
Bob Sandheinrich

ResourceFunction["FiveThirtyEightPresidentialPollingAverages"][ imports presidential polling data from fivethirtyeight.com for the for the specified election year | |

ResourceFunction["FiveThirtyEightPresidentialPollingAverages"][{ combines data from several election years. |

The result is a Dataset containing polling averages over time for several US presidential elections.

The "State" field can be a state, congressional district, the District of Columbia or the whole United States.

Each row in the dataset contains the support for one candidate in one area at one moment in time. The support is computed by fivethirtyeight.com by combining polls using their model.

The data is imported from FiveThirtyEight's GitHub repository on each evaluation. This requires an internet connection and takes several seconds. The data is not updated frequently, so it is recommended to store the data locally for repeated usage.

The year can be given as an integer or DateObject.

ResourceFunction["FiveThirtyEightPresidentialPollingAverages"][All] combines all years in a single Dataset.

ResourceFunction["FiveThirtyEightPresidentialPollingAverages"]["Historic"] combines all years except the current election cycle in a single Dataset.

Get polling data for the 1976 US presidential election from fivethirtyeight.com:

In[1]:= |

Out[1]= |

Retrieve polling data for the 2020 election cycle:

In[2]:= |

Out[2]= |

Get all polling data:

In[3]:= |

Out[3]= |

See the included elections dates:

In[4]:= |

Out[4]= |

See the number of statewide averages for each state or region:

In[5]:= |

Out[5]= |

Use a DateObject to specify the date:

In[6]:= |

Out[6]= |

Get data for two elections:

In[7]:= |

Out[7]= |

In[8]:= |

Out[8]= |

Get all polling data without the current election cycle using "Historic":

In[9]:= |

Out[9]= |

Get current polling for the 2024 election and group all the polls by pollster and population, then split by polling date:

In[10]:= |

Out[12]= |

For each date, find a single value for each candidate. The Min will use many-candidate results over two-candidate results:

In[13]:= |

Out[14]= |

Create time series from the data, eliminating pollsters without recent or many polls:

In[15]:= |

Out[16]= |

Plot all the series:

In[17]:= |

Out[17]= |

Take a simple average over the pollsters at regular intervals and plot the result:

In[18]:= |

Out[18]= |

Select data from just one election:

In[19]:= |

Out[19]= |

See the candidates:

In[20]:= |

Out[20]= |

Get the last result for each state:

In[21]:= |

Out[21]= |

Calculate the estimated difference in support between the two candidates:

In[22]:= |

Out[22]= |

Calculate timeline plots for each state:

In[23]:= |

Out[24]= |

Create a map of the support difference which shows the timelines when hovered:

In[25]:= |

Out[25]= |

Get data for another election:

In[26]:= |

Out[26]= |

Create time series data for each state:

In[27]:= |

Out[28]= |

Get the difference in support between the top two candidates over time for each state with over two hundred estimates:

In[29]:= |

Out[29]= |

Create a list of TimeSeries with samples over the smallest common range:

In[30]:= |

Out[30]= |

Calculate the correlations between states:

In[31]:= |

Out[32]= |

See the results:

In[33]:= |

Out[34]= |

Visualize it:

In[35]:= |

Out[78]= |

The 2020 data includes numbers adjusted for convention bounces:

In[79]:= |

Out[80]= |

The bounce-adjusted numbers differ considerably from the standard average:

In[81]:= |

Out[81]= |

Use only non-bounce-adjusted values instead:

In[82]:= |

Out[82]= |

- 3.1.1 – 17 April 2024
- 3.1.0 – 10 April 2024
- 3.0.0 – 09 October 2020
- 2.0.0 – 16 September 2020
- 1.0.0 – 07 July 2020

This work is licensed under a Creative Commons Attribution 4.0 International License