knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "man/figures/README-",
  out.width = "80%"
)

The esaps package

CRAN_Status_Badge r badger::badge_devel("Nicolas-Schmidt/esaps", "blue") R build status Project Status: Active – The project has reached a stable, usable state and is being actively
developed. CRAN RStudio mirrordownloads

Description

It allows structuring electoral data of different size and structure to calculate various indicators frequently used in the studies of electoral systems and party systems. Indicators of electoral volatility, electoral disproportionality, party nationalization and the effective number of parties are included.

Installation

# Install speech from CRAN
install.packages("esaps")

# The development version from GitHub:
if (!require("remotes")) install.packages("remotes")
remotes::install_github("Nicolas-Schmidt/esaps")

Functions

| Indicator | Method | Variables | Function | | -----------------------------| ------------------------------ | --------------- |-------------------------- | | Electoral Volatility | Pedersen (1979) | election unit party votes | evolat(., method=1) | | | Powell and Tucker (2014) | election unit party votes | evolat(., method=2) | | | Torcal and Lago (2015) | election unit party votes M | evolat(., method=3) | | Effective Number of Parties | Laakso and Taagepera (1979) | election unit party votes or seats | enp() | | Party System Nationalization | Mainwaring and Jones (2003)| election unit party votes votes_nac | psns(., method=1) | | | Chhibber and Kollman (2004)| election unit party votes votes_nac | psns(., method=2) | | Party Nationalization | Mainwaring and Jones (2003)| election unit party votes | psns(., method=1,pn=TRUE)| | Electoral Disproportionality | Rae (1971) | election unit party votes seats | dispro(., method=1) | | | Loosemore and Hanby (1971) | election unit party votes seats | dispro(., method=2) | | | Lijphart_1 (1986) | election unit party votes seats | dispro(., method=3) | | | Lijphart_2 (1994) | election unit party votes seats | dispro(., method=4) | | | Gallagher (1991) | election unit party votes seats | dispro(., method=5) | | | Cox and Shugart (1991) | election unit party votes seats | dispro(., method=6) |

Indicators and Variables

Examples

Load data

library(esaps)

votes <- list(data.frame(country = rep("ARG", 3),
                         year = c(1995, 2000, 2005),
                         party_A = c(40,10,20),
                         party_B = c(35,20,40),
                         party_C = c(25,70,40)),
              data.frame(country = rep("URY", 4),
                         year = c(1995, 2000, 2005, 2010),
                         party_A = c(30,30,20,20),
                         party_B = c(30,50,40, 30),
                         party_C = c(30,10,30, 25),
                         party_D = c(10,10,10,25)),
              data.frame(country = rep("BRA", 2),
                         year = c(1993, 1998),
                         party_A = c(30, 55),
                         party_B = c(70, 45)))

votes

votes <- convert_esaps(dataset = votes, unit.name = "country", election.name = "year")

votes

## VOTES AND SEATS

votes_2 <- data.frame(
        year = c(2000, 2005), 
        country = "URY", 
        votes_party1 = c(20, 30), 
        votes_party2 = c(30, 35),
        votes_party3 = c(40, 25),
        votes_party4 = c(10, 10), 
        seats_party1 = c(25, 35),
        seats_party2 = c(20, 30),
        seats_party3 = c(40, 30),   
        seats_party4 = c(15, 5)   
)

votes_2

votes_2c <- convert_esaps(dataset = votes_2, unit.name = "country", election.name = "year", seats = TRUE)

votes_2c

Functions

Electoral volatility

evolat(votes, 1)

evolat(tidy_data = votes, method = 1, summary = TRUE)

Effective Number of Parties

enp(votes)

Electoral Disproportionality

votes_2

v2 <- convert_esaps(dataset = votes_2, unit.name = "country", election.name = "year", seats = TRUE)
dispro(v2, 1:6, 1)

library(magrittr)

convert_esaps(dataset = votes_2, unit.name = "country", election.name = "year", seats = TRUE) %>%
        dispro(1:3)


dispro(tidy_data = v2, method = c("Rae", "Gallagher"))

Party System Nationalization Score and Party Nationalization Score

votes3 <- data.frame(election = rep(2000,4),
                    unit  = rep(c("District_1", "District_2"), each = 2),
                    party = rep(c("party_A", "party_B"), 2),
                    votes = c(0.60,0.40, 0.30, 0.70),
                    votes_nac = rep(c(0.55,0.45),2)
                    )

votes3

psns(tidy_data = votes3, method = 1)

psns(tidy_data = votes3, method = 1, pns = TRUE)

Electoral volatility in Uruguay

library(Boreluy) # https://nicolas-schmidt.github.io/Boreluy/
library(tidyverse)

map_df(c(1984, 1989, 1994, 1999, 2004), nacional_uy) %>% 
    as_esaps() %>% 
    evolat("Pedersen") %>% 
        ggplot(aes(x = election, y = eVolat)) +
        geom_line(aes(group = 1)) + 
        geom_point(size = 2, color = "red") +
        theme_minimal()

Linear Model

library(tidyverse)

dat <- inner_join(evolat(votes, 1), enp(votes))

dat

lm(formula(dat[,4:3]), data = dat)

ggplot(dat, aes(x = enp, y = eVolat )) +
    geom_point() + 
    geom_smooth(method = lm, se = TRUE) +
    theme_minimal()

Citation

To cite esaps in publications, please use:

citation("esaps")

Author

Nicolas Schmidt (nschmidt@cienciassociales.edu.uy)



Nicolas-Schmidt/esaps documentation built on Nov. 13, 2021, 7:38 a.m.