This is my personal R-Package containing various short functions I wrote for various projects, mostly concerning topics of political science. My main reasons for writing this package are a) to have written a R package once and b) to have an easy, transparent and reproducible way of reusing code between project. The idea for this small package was born after I read this great blog-post by Hilary Parker. This other post of hers was a great help.
Installation of rstfuns
requires devtools
. If devtools
is
installed rstfuns
can be installed using:
devtools::install_github("https://github.com/RStelzle/rstfuns", dependencies = T)
library(rstfuns)
Roll-Call-Data is one of the workhorse-data-sources of the sociology of
legaslatures, as it is -depending on the legislative body of interest-
relatively accessible. One topic of interest to be tackled with
Roll-Call-Data might be cohesion or discipline (for a distinction of the
two see Özbudun (1970)) of parliamentary groups. For questions of this
kind rstfuns
contains two functions calc_attina_index()
and
calc_rice_index()
. Both indices can be used to measure cohesion within
a set of legislators for a given vote.
That being said, Roll-Call-Data should not be analysed without a word of caution: As roll-call-votes are in most cases not staged randomly, any inferences taken from a sample of roll-call-votes on the population of all votes are built on shaky grounds. For a great overview see Carrubba et al. (2006).
calc_attina_index()
With M being the count of votes given for the option with the most votes and N being the total count of votes given, including votes to abstain.
calc_attina_index()
is used to calculate “Attina’s index of agreement”
(see Attina 1990, 564f.). Attina’s index of agreement can be used for
votes with the option to abstain from the vote, like in the European
Paraliament. calc_attina_index()
takes a vector (max. length()
= 3)
of the amount/share of votes for “yes”, “no” and “abstain”. When the
vector is shorter than length() = 3
it is assumed that no legislators
voted for the missing option(s).
Attina’s index of agreement results values from -33.333 to 100. A value of 100 represents a unanimous vote. Positive values result, if more than half of the votes were casted for one and the same option. -33.33 means, that equal shares of legislatures voted for “yes”, “no” and “abstain”.
calc_attina_index()
takes the optional argument rescale
(default =
FALSE
). If set to TRUE
, calc_attina_index()
’s results get rescaled
to a scale of 0-1 (for exaple used in Hix, Noury, and Roland (2005)). A
value of 0.25 now represents that 50% of the values were casted for one
of the options.
calc_rice_index()
With P being the count of “Yes”-, C the count of “No” and N the total count of votes.
calc_rice_index()
is used to calculate the “Rice Index” as defined in
Rice (1925, 62f.). It can be used for votes without an option to
abstain. Therefore calc_rice_index()
only takes a vector of max.
length()
= 2. The Rice Index varies between 1 (all votes where casted
for the same option) and 0 (votes where evenly split between “yes” and
“no”).
plot_turnout_parlgov()
rstfuns::plot_turnout_parlgov(c("Germany", "Poland", "France", "United Kingdom"), german = F)
plot_turnout_parlgov()
can be used for quick and dirty plotting of
election turnout in countries. Data from the ParlGov Database (Döring
and Manow 2019) is used. The function takes one optional argument. If
set to german = T
countrynames will be translated to German and “and”
will be replaced by “und”.
enumerate()
enumerate()
can be used to print all entries of a vector to one large
string enumerating all entries and adding “and” before the last entry.
The optional argument german = T
changes “and” to “und”. The optional
argument oxford = T
adds an additional (oxford-) comma before the
“and”.
rstfuns::enumerate(c("Germany", "Italy", "Poland"))
## [1] "Germany, Italy and Poland"
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.