Portable Routines for Preparing CCES and ACS data for MRP


Cite as:

Purpose and Contribution

Multilevel Regression and Poststratification (MRP) is an increasingly popular method for analyzing surveys, and can be implemented on public datasets such as the CES/CCES and ACS. Several helpful tutorials give introductions with sample R code (Kastellec, Lax, and Phillips, 2019; Hanretty, 2019),

But despite its increasingly popularity, doing one’s own MRP entails considerable upfront costs: downloading the appropriate survey and contextual data, recoding survey values to match with their Census counterparts, and generating population frames to post-stratify on, potentially by merging different datasets. While there already exist some packages for MRP (e.g. gelman/mrp, stan-dev/rstanarm, kuriwaki/sparseregMRP), these often define generic functions and leave users to prepare the cleaned data to use those functions with specific requirements.

The ccesMRPprep package instead provides data loading, processing, and formatting functions for a particular task: using CES/CCES data (Cooperative Election Study, formerly the Cooperative Congressional Election Study) for MRP. Limiting its usage to a fixed set of survey data has several benefits. Its key contributions are functions that are calibrated to a consistent syntax, pre-built lookup tables and value-key pairs of data that are based upon a careful reading of data sources, and data loading functions that use APIs (IQSS/dataverse-client-r and walkerke/tidycensus) to reduce the dependency on downloading large files.

Model fitting and visualization of MRP itself is handled in the companion package, kuriwaki/ccesMRPrun. This package is focused on the preparation to get there.


# remotes::install_github("kuriwaki/ccesMRPprep")

Getting Started

See vignette("overview") for a overview of the steps involved.

For documentation of the data sources, see vignette("acs") for the Census and vignette("derived") for CCES variables.

A related package also covers more advanced techniques to expand population tables. See kuriwaki/synthjoint for an overview and demonstration.

Each function and built-in data provides documentation as well.


See the overview vignette (vignette("overview")) from a illustrative workflow.

Data Sources

Function-specific pages will detail the documentation used in each function. Here is a manual compilaiton:

| Information | Source | Citation and URL (if public) | |:--------------------------------------------|:-------------------------------|:--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | CCES Covariates | Cumulative CCES | Shiro Kuriwaki, “Cumulative CCES Common Content”. | | CCES Outcomes | Each Year’s CCES | Stephen Ansolabehere, Sam Luks, and Brian Schaffner. “CCES Common Content” (varies by year). | | Poststratification | Census Bureau ACS | American Community Survey. Extracted via tidycensus package. See ACS vignette | | District-level Contestedness and Incumbency | Collected mainly by Jim Snyder | | | CD-level Presidential Voteshare | Daily Kos | Daily Kos, The ultimate Daily Kos Elections guide to all of our data sets | | State-level Presidential Voteshare | MEDSL | MIT Election Data and Science Lab, 2017, “U.S. President 1976–2016”. |

Related Packages


This package is a part of the CCES MRP project, supported by NSF Grant 1926424: Bayesian analytical tools to improve survey estimates for subpopulations and small areas. The contents are based on collaborations and discussions with Ben Bales, Lauren Kennedy, and Mitzi Morris.

kuriwaki/ccesMRPprep documentation built on July 27, 2023, 3:34 a.m.