Build Status Build status codecov


dgo is an R package for the dynamic estimation of group-level opinion. The package can be used to estimate subpopulation groups’ average latent conservatism (or other latent trait) from individuals’ responses to dichotomous questions using a Bayesian group-level IRT approach developed by Caughey and Warshaw 2015 that models latent traits at the level of demographic and/or geographic groups rather than individuals. This approach uses a hierarchical model to borrow strength cross-sectionally and dynamic linear models to do so across time. The group-level estimates can be weighted to generate estimates for geographic units, such as states.

dgo can also be used to estimate smoothed estimates of subpopulation groups’ average responses on individual survey questions using a dynamic multi-level regression and poststratification (MRP) model (Park, Gelman, and Bafumi 2004). For instance, it could be used to estimate public opinion in each state on same-sex marriage or the Affordable Care Act.

This model opens up new areas of research on historical public opinion in the United States at the subnational level. It also enables scholars of comparative politics to estimate dynamic models of public opinion opinion at the country or subnational level.


dgo can be installed from CRAN:


Or get the latest version from GitHub using devtools:

if (!require(devtools, quietly = TRUE)) install.packages("devtools")

dgo requires a working installation of RStan. If you don’t have already have RStan, follow its “Getting Started” guide.


Load the package and set RStan’s recommended options for a local, multicore machine with excess RAM:

rstan_options(auto_write = TRUE)
options(mc.cores = parallel::detectCores())

The minimal workflow from raw data to estimation is:

  1. shape input data using the shape() function; and
  2. pass the result to the dgirt() function to estimate a latent trait (e.g., conservatism) or dgmrp() function to estimate opinion on a single survey question.

See the package site for worked examples.


Please report issues that you encounter.

Contributing and citing

dgo is under development and we welcome suggestions. The package citation is

Dunham, James, Devin Caughey, and Christopher Warshaw. 2017. dgo: Dynamic Estimation of Group-level Opinion. R package.