Giter VIP home page Giter VIP logo

dgo's Introduction

dgo: Dynamic Estimation of Group-Level Opinion

Build Status Build status codecov

Introduction

dgo is an R package for the dynamic estimation of group-level public opinion. You can use the package to estimate latent trait means in subpopulations from survey data. For example, dgo can estimate the average policy liberalism in each American state over time among Democrats, Independents, and Republicans, given their answers to survey questions about policy proposals.

dgo accomplishes this using a Bayesian group-level IRT approach developed by Caughey and Warshaw 2015. It models latent traits at the level of demographic and geographic groups rather than individuals. It uses a hierarchical model to borrow strength cross-sectionally and dynamic linear models to do so across time.

The package can also be used to estimate smoothed estimates of subpopulations' average responses to single survey items, using a dynamic multi-level regression and poststratification (MRP) model (Park, Gelman, and Bafumi 2004). For instance, you can use dgo 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 allows scholars of comparative politics to estimate dynamic cross-national models of public opinion.

Installation

dgo can be installed from CRAN:

install.packages("dgo")

Or get the latest version from GitHub using devtools:

if (!require(devtools, quietly = TRUE)) install.packages("devtools")
devtools::install_github("jamesdunham/dgo")

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

Usage

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

library(dgo)
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.

Troubleshooting

Please report issues that you encounter.

  • OS X only: RStan creates temporary files during estimation in a location given by tempdir(), typically an arbitrary location in /var/folders. If a model runs for days, these files can be cleaned up while still needed, which induces an error. A good solution is to set a safer path for temporary files, using an environment variable checked at session startup. For help setting environment variables, see the Stack Overflow question here. Confirm the new path before starting your model run by restarting R and checking the output from tempdir().

  • Models fitted before October 2016 (specifically < #8e6a2cf) using dgirt are not fully compatible with dgo. Their contents can be extracted without using dgo, however, with the $ indexing operator. For example: as.data.frame(dgirtfit_object$stan.cmb).

  • Calling dgirt() or dgmrp() can generate warnings during model compilation. These are safe to ignore, or can be suppressed by following the linked instructions.

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. https://jdunham.io/dgo/.

dgo's People

Contributors

jamesdunham avatar cwarshaw avatar devincaughey avatar

Watchers

James Cloos avatar

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.