Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

https://github.com/adibender/coalitions

Coalition probabilities in multi-party democracies
https://github.com/adibender/coalitions

coalition-probabilities election-analysis elections r rstats

Last synced: about 1 month ago
JSON representation

Coalition probabilities in multi-party democracies

Lists

README

        

---
output: github_document
---

```{r options, echo=FALSE}
library(knitr)
opts_chunk$set(warning=FALSE)
```

# coalitions
[![Travis-CI Build Status](https://travis-ci.org/adibender/coalitions.svg?branch=master)](https://travis-ci.org/adibender/coalitions)
[![AppVeyor Build Status](https://ci.appveyor.com/api/projects/status/github/adibender/coalitions?branch=master&svg=true)](https://ci.appveyor.com/project/adibender/coalitions)
[![Coverage Status](https://codecov.io/github/adibender/coalitions/master.svg)](https://codecov.io/github/adibender/coalitions?branch=master)
[![CRAN_Status_Badge](https://www.r-pkg.org/badges/version-ago/coalitions)](https://cran.r-project.org/package=coalitions)
[![](https://cranlogs.r-pkg.org/badges/grand-total/coalitions)](https://cran.r-project.org/package=coalitions)
[![MIT license](https://img.shields.io/badge/license-MIT-brightgreen.svg)](https://opensource.org/licenses/MIT)

## Overview

The `coalitions` package implements a Bayesian framework for the estimation of
event probabilities in multi-party electoral systems (Bauer et al., 2019) like Germany, Austria etc.
To support estimation, the package also implements scrappers that
obtain data for German federal and general elections as well as Austrian
general election. The implementation can be extended to support other elections.

- To get started, see our [workflow vignette](https://adibender.github.io/coalitions/articles/workflow.html)

- Check out our [interactive shiny app](https://koala.stat.uni-muenchen.de/) on
German (state and federal) elections/surveys

- Updates are available from our [KOALA_LMU twitter account](https://twitter.com/KOALA_LMU)!

## Installation

```{r, eval=FALSE}
# To install from CRAN use:
install.packages("coalitions")

# To install the most current version from GitHub use:
devtools::install_github("adibender/coalitions")
```

## Usage

Detailed workflow is outlined in the
[workflow](https://adibender.github.io/coalitions/articles/workflow.html)
vignette.

A short overview is presented below.

### Scrape surveys

The wrapper `get_surveys()` which takes no arguments, downloads all surveys
currently available at [wahlrecht](https://www.wahlrecht.de/umfragen) and
stores them in a nested `tibble`:

```{r, message = FALSE}
library(coalitions)
library(dplyr)
library(tidyr)
surveys <- get_surveys()
surveys
```

Each row represents a polling agency and each row in the `surveys` column again
contains a nested `tibble` with survey results from different time-points:

```{r}
surveys %>%
filter(pollster == "allensbach") %>%
unnest()

survey <- surveys %>% unnest() %>% slice(1)
survey %>% unnest()
```

### Calculate coalition probabilities
For each survey (row) we can calculate the coalition probabilities

```{r}
survey %>% get_probabilities(nsim=1e4) %>% unnest()
```

## References
Bauer, Alexander, Andreas Bender, André Klima, and Helmut Küchenhoff. 2019. “KOALA: A New Paradigm for Election Coverage.” AStA Advances in Statistical Analysis, June. https://doi.org/10.1007/s10182-019-00352-6.

Bender, Andreas, and Alexander Bauer. 2018. “Coalitions: Coalition Probabilities in Multi-Party Democracies,” March. https://doi.org/10.21105/joss.00606.