knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "README-" )
esaps
package It allows to construct two types of indicators used in the study of Electoral Systems and Party Systems starting from electoral results data. The Effective Number of Parties (Laakso and Taagepera (1979)) and Electoral Volatility in its three versions (Pedersen (1979), Powell and Tucker (2014) and Torcal and Lago (2015)).
You can install the released version of esaps from CRAN with:
install.packages("esaps")
And the development version from GitHub with:
if (!require("devtools")) install.packages("devtools") devtools::install_github("Nicolas-Schmidt/esaps")
This is a typical database with electoral results by countries. Between countries, the number of parties varies as well as the number of elections. When calculating indicators from databases of different dimensions, the process becomes cumbersome.
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))) print(votes)
Once you have the data loaded in one or several electronic spreadsheets, the process of loading, assembly and conversion of the database to start calculating indicators is done with:
votes <- esaps_object(dataset = votes, name.country = "country", name.year = "year")
Then you can use any of the indicators:
volatility <- evolat(esapsObject = votes, method = "Pedersen", summary = FALSE) print(volatility)
You can also get a summary of the data by country:
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,30), party_D = c(NA, NA, 10)), 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 <- esaps_object(dataset = votes, name.country = "country", name.year = "year") volatility <- evolat(esapsObject = votes, method = "Powell and Tucker", summary = TRUE) print(volatility) 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,30), party_D = c(NA, NA, 10), magnitude = c(2,2,2)), 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), magnitude = c(2,2,2,3)), data.frame(country = rep("BRA", 2), year = c(1993, 1998), party_A = c(30, 55), party_B = c(70, 45), magnitude = c(2,2))) votes <- esaps_object(dataset = votes, name.country = "country", name.year = "year", name.M = "magnitude") volatility <- evolat(esapsObject = votes, method = "Torcal and Lago", summary = TRUE) print(volatility)
another way of loading data:
## 1 votes <- esaps_object(path = "...\data", extension = "xlsx", name.file = "votes.xlsx", nCountry = 3, name.country = "country", name.year = "year") ## 2 votes <- esaps_object(path = "...\data", extension = "xlsx", name.file = c("votes_ARG.xlsx","votes_URY.xlsx", "votes_BRA.xlsx"), nCountry = 3, name.country = "country", name.year = "year")
To cite esaps
in publications, please use:
citation("esaps")
Nicolas Schmidt (nschmidt@cienciassociales.edu.uy)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.