-
Notifications
You must be signed in to change notification settings - Fork 2
/
README.Rmd
225 lines (149 loc) · 7.36 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
---
output: github_document
---
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "80%"
)
```
## The `esaps` package <img src="man/figures/logo.png" style="margin-left:10px;margin-bottom:5px;" width="160" align="right"></a>
<!-- badges: start -->
[![CRAN_Status_Badge](https://www.r-pkg.org/badges/version-ago/esaps)](https://cran.r-project.org/package=esaps)
`r badger::badge_devel("Nicolas-Schmidt/esaps", "blue")`
[![R build status](https://github.com/Nicolas-Schmidt/esaps/workflows/R-CMD-check/badge.svg)](https://github.com/Nicolas-Schmidt/esaps/actions)
[![Project Status: Active – The project has reached a stable, usable state and is being actively
developed.](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/#active)
[![CRAN RStudio mirrordownloads](https://cranlogs.r-pkg.org/badges/grand-total/esaps?color=blue)](https://www.r-pkg.org/pkg/esaps)
<!-- badges: end -->
### 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
```{r eval=FALSE}
# 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)](http://bit.ly/2p4cyZQ) | `election` `unit` `party` `votes` | `evolat(., method=1)` |
| | [Powell and Tucker (2014)](http://bit.ly/2FpoeBm) | `election` `unit` `party` `votes` | `evolat(., method=2)` |
| | [Torcal and Lago (2015)](http://bit.ly/2FD83zE) | `election` `unit` `party` `votes` `M` | `evolat(., method=3)` |
| Effective Number of Parties | [Laakso and Taagepera (1979)](http://bit.ly/2oYU4dV) | `election` `unit` `party` `votes` or `seats` | `enp()` |
| Party System Nationalization | [Mainwaring and Jones (2003)](https://bit.ly/2w9QgtO)| `election` `unit` `party` `votes` `votes_nac` | `psns(., method=1)` |
| | [Chhibber and Kollman (2004)](https://bit.ly/2oj76SY)| `election` `unit` `party` `votes` `votes_nac` | `psns(., method=2)` |
| Party Nationalization | [Mainwaring and Jones (2003)](https://bit.ly/2w9QgtO)| `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)](https://bit.ly/2B1mIDH) | `election` `unit` `party` `votes` `seats` | `dispro(., method=2)` |
| | Lijphart_1 (1986) | `election` `unit` `party` `votes` `seats` | `dispro(., method=3)` |
| | [Lijphart_2 (1994)](https://bit.ly/2McLshB) | `election` `unit` `party` `votes` `seats` | `dispro(., method=4)` |
| | [Gallagher (1991)](https://bit.ly/2M6CPoy) | `election` `unit` `party` `votes` `seats` | `dispro(., method=5)` |
| | [Cox and Shugart (1991)](https://bit.ly/2M9Bttr) | `election` `unit` `party` `votes` `seats` | `dispro(., method=6)` |
### Indicators and Variables
<img src="man/figures/net.png" style="margin-center:30px;margin-bottom:5px;" width="1160" align="center"></a>
### Examples
#### Load data
```{r}
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
```{r}
evolat(votes, 1)
evolat(tidy_data = votes, method = 1, summary = TRUE)
```
Effective Number of Parties
```{r}
enp(votes)
```
Electoral Disproportionality
```{r}
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
```{r}
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
```{r, message=FALSE, fig.width = 6, fig.height = 3}
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
```{r f1, message = FALSE, fig.width = 6, fig.height = 3, warning=FALSE}
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:
```{r eval=FALSE}
citation("esaps")
```
### Author
Nicolas Schmidt (<[email protected]>)