Title: | Electoral Analysis |
---|---|
Description: | Functions to obtain an important number of electoral indicators described in the package, which can be divided into two large sections: The first would be the one containing the indicators of electoral disproportionality, such as, Rae index, Loosemore–Hanby index, etc. The second group is intended to study the dimensions of the party system vote, through the indicators of electoral fragmentation, polarization, volatility, etc. Moreover, multiple seat allocation simulations can also be performed based on different allocation systems, such as the D'Hondt method, Sainte-Laguë, etc. Finally, some of these functions have been built so that, if the user wishes, the data provided by the Spanish Ministry of Home Office for different electoral processes held in Spain can be obtained automatically. All the above will allow the users to carry out deep studies on the results obtained in any type of electoral process. The methods are described in: Oñate, Pablo and Ocaña, Francisco A. (1999, ISBN:9788474762815); Ruiz Rodríguez, Leticia M. and Otero Felipe, Patricia (2011, ISBN:9788474766226). |
Authors: | Miguel Rodríguez Asensio |
Maintainer: | Miguel Rodríguez Asensio <[email protected]> |
License: | GPL-2 |
Version: | 0.1.0 |
Built: | 2024-11-13 04:28:59 UTC |
Source: | https://github.com/cran/Relectoral |
This function serves to download the data in Excel format at the municipal level and creates a data.frame in your R environment with that information. Note: The fields returned are all of character type, so if you need to perform operations with them, you will have to convert the necessary fields to numeric.
Agregado_Mun_MIR(Ano, Mes, Tipo, Ruta, Borrar = TRUE)
Agregado_Mun_MIR(Ano, Mes, Tipo, Ruta, Borrar = TRUE)
Ano |
The election year in four-digit format (YYYY). Can be numeric or text. |
Mes |
The election month. It has to be of character format. For example "06", corresponding to June. |
Tipo |
The type of elections to which the data to be downloaded correspond: Congress (you must pass to the function the word "Congreso") or European (you must pass to the function the word "Europeas"). |
Ruta |
It is the local path from your computer where the zip files from the Spanish Ministry of Home Office (MIR) will be dowloaded. |
Borrar |
It is a Boolean variable that indicates whether or not the downloaded files are deleted after creating the data.frame in R. |
Object of type 'tbl_df' with the data at municipal level.
c<-Agregado_Mun_MIR(1989,"06",Tipo = "Europeas","F:/")
c<-Agregado_Mun_MIR(1989,"06",Tipo = "Europeas","F:/")
This function is used to download the data in Excel format at the provincial level and upload a data.frame with that information into R. Note: The returned fields are all of character format, so if you need to perform operations, you will have to convert the required fields to numeric.
Agregado_Prov_MIR(Ano, Mes, Tipo, Ruta, Borrar = TRUE)
Agregado_Prov_MIR(Ano, Mes, Tipo, Ruta, Borrar = TRUE)
Ano |
The election year in four-digit format (YYYY). Can be numeric or text. |
Mes |
The election month. It has to be of character format. For example "06", corresponding to June. |
Tipo |
The type of elections to which the data to be downloaded correspond: Congress (you must pass to the function the word "Congreso") or European (you must pass to the function the word "Europeas"). |
Ruta |
It is the local path from your computer where the zip files from the Spanish Ministry of Home Office (MIR) will be dowloaded. |
Borrar |
It is a Boolean variable that indicates whether or not the downloaded files are deleted after creating the data.frame in R. |
Object of type 'tbl_df' with the data at provincial level.
c<-Agregado_Prov_MIR(2019,"05",Tipo = "Europeas","F:/")
c<-Agregado_Prov_MIR(2019,"05",Tipo = "Europeas","F:/")
With this function, the following indicators of electoral disproportionality can be obtained for aggregated data:
Sainte Lagüe (SL)
RAE (R)
RAE Corrected (Rco)
Loosemore & Hanby (LH)
Gallagher's Minimum Squares index (Gcm)
Maximum deviation index (Lmax)
Cox & Shugart index (Cs)
Corrected Cox & Shugart index (CS_correg)
Tukey's line (LT)
All the values of these indicators are in an output data.frame where the names of the columns coincide with the identification of these indicators which appear between brackets above.
Likewise the following voting size indicators are also obtained:
Electoral and Parliamentary fragmentation (F)
Effective number of political parties (N)
Hyperfractionality index (Hiper)
Molinar's effective number of political parties (NP)
Concentration of vote (Con)
Competitiveness between parties (Comp)
The electoral and parliamentary versions are calculated for these voting size indicators. Their values are stored in the output of this function within a data.frame with the name of the columns indicated with the initials shown above in parentheses and the suffix '_electoral' is added to indicate that it is the electoral version or the suffix '_parliamentary' to indicate that it is the parliamentary version.
Important note. With this function you can get the results automatically or manually. With the automatic form, the data are downloaded from the Spanish Ministry of Home Office. With the manual form, you have to provide the data using a data.frame with the structure that will be indicated later.
AgregadosIndi(Ano = 0, Mes = "", RutaDescarga = "", Auto = TRUE, datos = "")
AgregadosIndi(Ano = 0, Mes = "", RutaDescarga = "", Auto = TRUE, datos = "")
Ano |
Required only for automatic procedure. It is the year of the electoral process that the user wants to study. It must be a four-digit numerical value. |
Mes |
Required only for automatic procedure.is the month of the electoral process, it must be a string composed of two characters, associated with the month in which the elections were held. |
RutaDescarga |
Required only for automatic procedure. must be a string indicating the local path of the user's computer where to download the file from the Spanish Ministry of Home Office (MIR). This file is then automatically deleted once the process is completed. The user has to bear in mind that this path must indicate a place where R has read and write permission, otherwise the process will not be completed. |
Auto |
It can take the logical values TRUE or FALSE. By default it has the value TRUE to indicate that the user wants the automatic procedure. In the case of wanting a manual procedure, this parameter will take the FALSE value. |
datos |
Required only for manual procedure. It must be a data.frame with three columns: The first column containing the name of the parties, the second column the number of votes and the third column the number of seats that the political party in question obtains. |
Returns a data.frame with four elements:
1.- Its name is 'dat' and it is a data.frame containing the votes and seats of each candidate party, in absolute terms and in percentages, also the accumulated distribution of these values and a last column containing an indicator of electoral disproportionality that is calculated as the difference between the percentage of votes and the percentage of seats obtained.
2.- Its name is 'grafico' and it is a ggpplot object where the difference between the percentage of votes and seats is represented in a bar chart.
3.- Its name is 'In_despro' and it is a data.fame containing the values of the disproportionality indices indicated above.
4.- Its name is 'In_dimen' and it is a dataframe with the values of the voting dimension indicators indicated above. Both the electoral and parliamentary versions are provided.
d<-AgregadosIndi(2019,"04",RutaDescarga = "F:/")
d<-AgregadosIndi(2019,"04",RutaDescarga = "F:/")
With this graph two parliamentary arcs will be obtained with the purpose of being able to compare the structure of them, that is to say, the results obtained in two different electoral processes.
Arc_Comparacion( Partidos1, Partidos2, Escanos1, Escanos2, cols = NULL, repr = c("absolute", "proportion"), titu1 = "Election1", titu2 = "Election2", titulo = "Poner un titulo" )
Arc_Comparacion( Partidos1, Partidos2, Escanos1, Escanos2, cols = NULL, repr = c("absolute", "proportion"), titu1 = "Election1", titu2 = "Election2", titulo = "Poner un titulo" )
Partidos1 |
It is a character vector with the names of the parties of the first process. |
Partidos2 |
It is a character vector with the names of the parties of the second process. |
Escanos1 |
It is an integer vector with the results of the first process. |
Escanos2 |
It is an integer vector with the results of the second process. |
cols |
It is a vector containing the colors to be used in the elaboration of the graph |
repr |
To indicate if you want a graph in absolute terms ("absolute") or to use relative terms ("proportion"). |
titu1 |
Title to be used for the first process |
titu2 |
Title to be used for the second process |
titulo |
Global title for the whole chart. |
A ggplot object is obtained containing two graphs representing the two parliamentary arcs to be compared.
bt1 <- data.frame(parties = c("PP", "CSU", "SPD","IU"), seats = c(200, 46, 153,58), cols = c("black", "blue", "red","jjj"), stringsAsFactors = FALSE) bt2 <- data.frame(parties = c("PP", "CSU","UP1"), seats = c(100, 146,200), cols = c("green", "blue","GGG"), stringsAsFactors = FALSE) Arc_Comparacion(bt1$parties,bt2$parties, bt1$seats, bt2$seats, cols=c("PP"="blue", "CSU"="red","SPD"="green", "IU"="pink","UP1"="antiquewhite" ), titu1 = "Abril-2019",titu2 = "Noviembre-2019", titu = " Comparación de elecciones")
bt1 <- data.frame(parties = c("PP", "CSU", "SPD","IU"), seats = c(200, 46, 153,58), cols = c("black", "blue", "red","jjj"), stringsAsFactors = FALSE) bt2 <- data.frame(parties = c("PP", "CSU","UP1"), seats = c(100, 146,200), cols = c("green", "blue","GGG"), stringsAsFactors = FALSE) Arc_Comparacion(bt1$parties,bt2$parties, bt1$seats, bt2$seats, cols=c("PP"="blue", "CSU"="red","SPD"="green", "IU"="pink","UP1"="antiquewhite" ), titu1 = "Abril-2019",titu2 = "Noviembre-2019", titu = " Comparación de elecciones")
This function facilitates the representation of the distribution of seats obtained by each of the parties that have some parliamentary representation. It can be introduced a title for the graph, the colors to be used for each party, as well as to choose whether to make a distribution of seats in absolute or relative terms.
Arc_Parlamentario( Partidos, Escanos, cols = NULL, repr = c("absolute", "proportion"), titulo = "Enter a title here" )
Arc_Parlamentario( Partidos, Escanos, cols = NULL, repr = c("absolute", "proportion"), titulo = "Enter a title here" )
Partidos |
It is a string vector containing the name of the parties. |
Escanos |
It is a vector of natural numbers containing the seats that have been allocated to each party. |
cols |
(Optional) It is a vector containing the colors to be used to draw each zone of the parliamentary arc. |
repr |
It must contain the expression "absolute" or "Proportion" to perform the representation based on absolute or relative terms respectively. |
titulo |
To provide the title to be placed on the chart |
Returns a ggplot object, containing the representation of the obtained parliamentary arc.
bt <- data.frame(parties = c("PP", "CSU", "SPD", "AfD", "FDP", "UPyD", "CC", "Verdes"), seats = c(200, 46, 153, 92, 80, 69, 67, 2), cols = c("black", "blue", "red", "lightblue", "yellow", "purple", "lavenderblush", "grey"), stringsAsFactors = FALSE) Arc_Parlamentario(bt$parties, bt$seats, cols = bt$cols)
bt <- data.frame(parties = c("PP", "CSU", "SPD", "AfD", "FDP", "UPyD", "CC", "Verdes"), seats = c(200, 46, 153, 92, 80, 69, 67, 2), cols = c("black", "blue", "red", "lightblue", "yellow", "purple", "lavenderblush", "grey"), stringsAsFactors = FALSE) Arc_Parlamentario(bt$parties, bt$seats, cols = bt$cols)
BAZI is a freely available Java program that implements various methods of distributing seats for proportional representation systems. It offers the possibility of using divisor methods as well as quota methods. The program can be downloaded from https://www.math.uni-augsburg.de/htdocs/emeriti/pukelsheim/bazi/ Instructions on its use can be found at the following webpage: https://opus.bibliothek.uni-augsburg.de/opus4/frontdoor/index/index/docId/601. With this function you obtain flat ASCII files, with extension '.bazi' that structures the data in the form that can be understood by BAZI program and obtain the results that can be accessed with this application. This function has been designed so that it can be used both automatically or manually, that is to say, it will work autonomously if after giving the corresponding parameters it connects to the databases of the Spanish Ministry of the Interior, downloads the results and generates the file with extension ".bazi". The manual procedure, is designed to be provided with the appropriate data and that this function is responsible for transforming them to the format that BAZI understands to generate the results for which it is programmed. Let's see below how to proceed in each case.
First of all, it should be pointed out that the "camino" parameter must be provided both with the manual and the automatic procedure, and it should indicate the path to be used to store the file with the ".bazi" extension that is generated as a result of this process. It must also be taken into account that a path with writing permission for R must be provided.
The manual or automatic procedure is indicated by the "Auto" parameter of the Bazi() function, so that if "TRUE" (default value) is valid, the automatic procedure will be executed and otherwise the manual one.
Bazi( Ano = 0, Mes, camino = "", cota = 3, Auto = TRUE, votes, seats, Titulo = "" )
Bazi( Ano = 0, Mes, camino = "", cota = 3, Auto = TRUE, votes, seats, Titulo = "" )
Ano |
. For automatic procedure only. This value indicates the year of the data you want to download. This data can be numerical or of character type (better numeric) |
Mes |
. For automatic procedure only. This value refers to the month in which the election was held. It must be of character type with two digits always i.e. "04" is valid but "4" is not. |
camino |
. For manual and automatic procedure. You must indicate a local hard disk path where you download the file from the Ministry of Interior (once the process is finished it will be deleted automatically), and then the file will be written with the extension '.bazi' ready to be used by BAZI. Please note that this path must indicate a disk space with write permission so that the R program can save the results into it. |
cota |
. Only for automatic procedure. It will be the electoral threshold that the user wants to use. In the case of the Congress of Deputies in Spain it is 3 per cent (parties with less than 3 per cent of the valid votes do not take part in the distribution), and it is the value that has been assigned by default. |
Auto |
. To choose whether to use manual and automatic procedure. If it is equal to TRUE, the automatic procedure is executed, otherwise the manual procedure is carried out. |
votes |
. Only needed for manual procedure. It must be a dataframe type object with the following column structure: The first column must contain the name of the electoral districts to be considered. And then there will be a column for each political party to be taken into account, in such a way that one column will be identified by the acronym of the corresponding party, and will contain the votes of that formation in each of the districts where it has been presented as an electoral option. In those places where it has not been elegible, or it has not overcome the electoral threshold that is to be taken into account, a value of zero is added, in such a way that the Bazi() function takes this into account so as not to count these cases in the generation of the final file (the file with the extension ".bazi"). |
seats |
. Only needed for manual procedure. It is a two-column dataframe. The first column contains the names of the electoral districts (which must have the same name and be in the same order as those provided in the "votes" dataframe) and the second column indicates the number of Members of Parliament to be elected in each electoral district. |
Titulo |
. Only needed for manual procedure. It must be a string of characters that are the ones that head the file with extension ".bazi" that is generated. |
The result is a flat ASCII file with its own information structure to be read by BAZI Java program and which has the following generic name 'Congreso_AAAA_MM.bazi', where YYYY is the year of the electoral process and MM is the two-digit month. In the case of using a manual procedure the file will have the name 'Congreso.bazi'.
Bazi(Ano = 2019,"04","F:/") # Manual example vo <- data.frame( circu=c("c1","c2","c3","c4","c5","c6","c7","c8","c9"), p1=c(200,300,0,0,250,360,145,0,0), p2=c(0,0,450,467,576,346,234,0,437), p3=c(243,567,0,0,345,634,456,634,0), p4=c(0,367,384,134,267,0,0,364,146), p5=c(345,123,234,254,123,543,342,45,0), p6=c(23,45,234,0,0,354,254,56,123) ) se <- data.frame( circu=c("c1","c2","c3","c4","c5","c6","c7","c8","c9"), dip=c(3,4,5,3,2,6,2,4,3) ) Bazi(camino="F:/",Auto=FALSE, votes=vo,seats=se, Titulo="Fichero_prueba")
Bazi(Ano = 2019,"04","F:/") # Manual example vo <- data.frame( circu=c("c1","c2","c3","c4","c5","c6","c7","c8","c9"), p1=c(200,300,0,0,250,360,145,0,0), p2=c(0,0,450,467,576,346,234,0,437), p3=c(243,567,0,0,345,634,456,634,0), p4=c(0,367,384,134,267,0,0,364,146), p5=c(345,123,234,254,123,543,342,45,0), p6=c(23,45,234,0,0,354,254,56,123) ) se <- data.frame( circu=c("c1","c2","c3","c4","c5","c6","c7","c8","c9"), dip=c(3,4,5,3,2,6,2,4,3) ) Bazi(camino="F:/",Auto=FALSE, votes=vo,seats=se, Titulo="Fichero_prueba")
The standardised party nationalisation index developed by Bochsler (2010) can be calculated using an excel spreadsheet, which can be downloaded from the following website: https://www.bochsler.eu/pns/. This Excel file contains a macro to calculate the match nationalisation index, which is widely used nowadays. The aim of this function is to create an Excel sheet that is directly loaded with the data provided by the Spanish Ministry of the Interior (MIR), http://www.infoelectoral.mir.es/. This data is arranged in such a way that it is only necessary to copy and paste it into the macro created by Bochsler. This makes it much easier to load the macro function with data. In the Excel sheet that is created, the last row contains the totals that are the ones to be placed in row 8 of Daniel Bochsler's macro function.
Bochsler(Ano, Mes, RutaDescarga, RutaSalida)
Bochsler(Ano, Mes, RutaDescarga, RutaSalida)
Ano |
This value corresponds to the year of the data that the user wants to download. This data can be numerical or character (numerical is preferred). |
Mes |
This is the month in which the election was held. It must be a character with two digits, i.e. "04" is valid but "4" is not. |
RutaDescarga |
A path to the local hard disk where the Ministry of the Interior's Excel file will be downloaded must be indicated. Once the download is completed the downloaded file will be automatically deleted. |
RutaSalida |
It is a path of the local hard disk where the Excel sheet generated with the data will be deposited to feed Daniel Bochsler's macro. The resulting Excel workbook is called 'Bochsler.xlsx'. |
With this function you obtain an Excel sheet called 'Bochsler.xlsx' placed in the route that has been indicated with the parameter 'RutaSalida'.
NA
Bochsler(2019,"04","F:/","F:/") Bochsler(2016,"06","F:/","F:/")
Bochsler(2019,"04","F:/","F:/") Bochsler(2016,"06","F:/","F:/")
This index will measure the level of electoral competition that exists in a given party system between the first and second party that have obtained more votes in an specific election. This indicator will therefore show how much rivalry there is between the two parties that have received the most votes. To measure this phenomenon, the proximity or remoteness of the results of these two political formations are used. This indicator is calculated using the following formula:
Where p1 and p2 are the percentages of votes (or seats), as parts per unit, of the two most voted political formations. A value close to 1 (p1=p2) indicates strong competitiveness, while a value of zero (p1=1 p2=0) will indicate there is no competitiveness.
competitividad(votes, seats)
competitividad(votes, seats)
votes |
It is a vector of integers, containing the votes of all the candidates. |
seats |
It is a vector of integers, containing the seats obtained by each of the candidates. |
Returns a dataframe, with the columns "electoral" and "parliamentary" to store the value of the index of the competitiveness index in the electoral or the parliamentary way respectively.
competitividad(c(3947,3189,1971,466,345,82),c(184,99,44,10,1,0))
competitividad(c(3947,3189,1971,466,345,82),c(184,99,44,10,1,0))
Another very important indicator of the party system is the concentration of votes, which indicates what percentage of votes or seats are taken by the two parties that have the largest number of votes. The formula used to calculate this indicator is as follows:
The maximum value that this indicator takes is 1, so the closer it is to 1, the more concentrated the vote is.
concentracion(votes, seats)
concentracion(votes, seats)
votes |
It is a vector of integers, containing the votes of all the candidates. |
seats |
It is a vector of integers, containing the seats obtained by each of the candidates. |
Returns a dataframe, with the columns "electoral" and "parliamentary" to store the value of the index of the concentration of votes in the electoral or the parliamentary way respectively.
concentracion(c(3947,3189,1971,466,345,82),c(184,99,44,10,1,0))
concentracion(c(3947,3189,1971,466,345,82),c(184,99,44,10,1,0))
Cox_Shugart's (1991) disproportionality index measures the disproportion in the distribution of seats by means of a regression line between the percentage of seats and the percentage of votes. If the distribution were approximately proportional, the slope of the regression line would be one. If it moves away from that value there will be disproportionality in the distribution of seats.
Cox_Shugart(votes, seats)
Cox_Shugart(votes, seats)
votes |
It is a vector of integers, containing the votes of all the candidates. |
seats |
It is a vector of integers, containing the seats obtained by each of the candidates. |
Returns the value obtained for the index
Cox_Shugart(c(3947,3189,1971,466,345,82),c(184,99,44,10,0,0))
Cox_Shugart(c(3947,3189,1971,466,345,82),c(184,99,44,10,0,0))
This index tries to rectify the defect in the Cox_Shugart index, since the latter is very sensitive to the presence of small political parties. To correct this deficiency, this indicator is calculated by not taking into account parties that do not obtain parliamentary representation. In fact, when its value is calculated the only thing that is done is to eliminate the votes for parties that do not have obtained any seats and those results are passed to the "Cox_Shugart()" function.
Cox_Shugart_correg(votes, seats)
Cox_Shugart_correg(votes, seats)
votes |
It is a vector of integers, containing the votes of all the candidates. |
seats |
It is a vector of integers, containing the seats obtained by each of the candidates. |
Returns the value obtained for the index
Cox_Shugart_correg(c(3947,3189,1971,466,345,82),c(184,99,44,10,0,0))
Cox_Shugart_correg(c(3947,3189,1971,466,345,82),c(184,99,44,10,0,0))
This function serves to download the data in Excel format at polling station level and then uploads a data.frame with that information into R. Note: The returned fields are all of character format, so if you need to perform numeric operations, you will have to convert the required fields to numeric.
Desagregados_Mesa_Mir(Ano, Mes, Tipo, Ruta, Borrar = TRUE)
Desagregados_Mesa_Mir(Ano, Mes, Tipo, Ruta, Borrar = TRUE)
Ano |
The election year in four-digit format (YYYY). Can be numeric or text. |
Mes |
The election month. It has to be of character format. For example "06", corresponding to June. |
Tipo |
The type of elections to which the data to be downloaded correspond: Congress (you must pass to the function the word "Congreso") or European (you must pass to the function the word "Europeas"). |
Ruta |
It is the local path from your computer where the zip files from the Spanish Ministry of Home Office (MIR) will be dowloaded. |
Borrar |
It is a Boolean variable that indicates whether or not the downloaded files are deleted after creating the data.frame in R. |
Object of type 'tbl_df' with the data at polling station level.
c2<-Desagregados_Mesa_Mir(2019,"04",Tipo = "Congreso", Ruta = "F:/",Borrar = TRUE)
c2<-Desagregados_Mesa_Mir(2019,"04",Tipo = "Congreso", Ruta = "F:/",Borrar = TRUE)
With this function, the same results will be obtained as with the 'AgregadosIndi()' function, but for each of the regions listed in the data provided. Specifically, when downloading data from the Spanish Ministry of Home Office, the indicated data will be obtained both for each Autonomous Community and for each province. The format of the output resulting from this function is indicated below.
IMPORTANT NOTE: Again, data can be obtained automatically or provided manually.
DesAgregadosIndi( Ano = 0, Mes = "", RutaDescarga = "", Auto = TRUE, datos_v = "", datos_d = "" )
DesAgregadosIndi( Ano = 0, Mes = "", RutaDescarga = "", Auto = TRUE, datos_v = "", datos_d = "" )
Ano |
Required only for automatic procedure. It is the year of the electoral process that the user wants to study. It must be a four-digit numerical value. |
Mes |
Required only for automatic procedure.is the month of the electoral process, it must be a string composed of two characters, associated with the month in which the elections were held. |
RutaDescarga |
Required only for automatic procedure. must be a string indicating the local path of the user's computer where to download the file from the Spanish Ministry of Home Office (MIR). This file is then automatically deleted once the process is completed. The user has to bear in mind that this path must indicate a place where R has read and write permission, otherwise the process will not be completed. |
Auto |
It can take the logical values TRUE or FALSE. By default it has the value TRUE to indicate that the user wants the automatic procedure. In the case of wanting a manual procedure, this parameter will take the FALSE value. |
datos_v |
Required only for manual procedure. is a data.frame with at least three columns. The first column contains the name of the geographical unit that groups the elements of the third column, which in the case of Spain can initially be the name of the Autonomous Community. The second column is alphabetical and contains the code of the geographical unit appearing in the third column. In the case of Spain, normally the province code will be the one of the Spanish National Statistics Institute (INE). The third column is also of character format and contains the name of the electoral disctric, in the case of Spain this will normally be the name of the province. The fourth and following columns will refer to a specific political party, and the name of the column is recommended to coincide with the acronym of the political party in question. |
datos_d |
Required only for manual procedure. It is a data.frame with the same structure as 'datos_v', the only thing that from the fourth column onwards will contain the seats obtained by each political party for each of the territorial units included in the rows. The order of these columns must be the same as that of 'datos_v' to include the votes. |
The output consists of a list that contains two lists:
The fisrt list contains the layer of Autonomous Communities or geographical grouping units. There is a list for each Autonomous Community or grouping unit. The order of this list corresponds to the order in which the Autonomous Communities or grouping units appear in the input data.frame. After selecting an Autonomous Community or grouping unit, another list is obtained with the same four elements that contained the output of the function 'AgregadosIndi()' but for that specific geographical grouping unit.
The second list contains the layer of provinces or disaggregated electoral districts. In this case, a list is also obtained for each province or disaggregated unit, with the identifier equal to that shown for the province or disaggregated unit in the input files. Finally, for each province, a list is obtained with the four elements that were available with the output of the function 'AgergadosIndi()'.
d2<-DesAgregadosIndi(2019,"04",RutaDescarga = "F:/")
d2<-DesAgregadosIndi(2019,"04",RutaDescarga = "F:/")
This indicator seeks to summarize in one value the level of dispersion or concentration of political power, that is to say, whether or not the seats or votes received are concentrated in a reduced number of political parties. The values of the index vary between 0 and 1, so that a value of zero indicates no fragmentation (all the votes go to a single party), while a value close to one indicates strong electoral fragmentation
Este indicador pretende resumir en un valor el nivel de dispersión o concentración del poder político, es decir y de forma resumida si se encuentra concentrado o no los escaños o votos recibidos en una serie de partidos polítcos. Los valores del índice varían entre 0 y 1, de forma que un valor cero indica no hay ninguna fragmentación ( todos los votos van a un sólo partido), mientras que un valor dercano a uno indica fuerte fragmentación electoral
The formula used for its calculation is as follows:
for
Where q_i are the proportions (as parts per unit) of the number of seats or votes (electoral or parliamentary indicator), of the votes obtained by each candidate.
fragmentacion_rae(votes, seats)
fragmentacion_rae(votes, seats)
votes |
It is a vector of integers, containing the votes of all the candidates. |
seats |
It is a vector of integers, containing the seats obtained by each of the candidates. |
Returns a dataframe, with the columns "electoral" and "parliamentary" to store respectively the value of the electoral or parliamentary fragmentation index.
fragmentacion_rae(c(3947,3189,1971,466,345,82),c(184,99,44,10,1,0))
fragmentacion_rae(c(3947,3189,1971,466,345,82),c(184,99,44,10,1,0))
The Gallagher's electoral disproportionality index of minimum squares uses a somewhat more elaborate formula than the previous indices (R, LH), for which it calculates the differences squared between the votes and seats, adds them up and divides the result by two and then calculates its square root. It therefore gives appropriate weight to the distortions of disproportionality. Its mathematical formula is as follows:
for
Gallagher(votes, seats)
Gallagher(votes, seats)
votes |
It is a vector of integers, containing the votes of all the candidates. |
seats |
It is a vector of integers, containing the seats obtained by each of the candidates. |
Returns the value obtained for the index
Rae(c(3947,3189,1971,466,345,82),c(184,99,44,10,1,0)) Gallagher(c(3947,3189,1971,466,345,82),c(184,99,44,10,1,0))
Rae(c(3947,3189,1971,466,345,82),c(184,99,44,10,1,0)) Gallagher(c(3947,3189,1971,466,345,82),c(184,99,44,10,1,0))
With this function you can obtain the ID codes of the Autonomous Communities of Spain used by the Ministry of Home Affairs to code their data. This codification can also be seen in this link. It should be noted that this coding system does not fully coincide with the Autonomous Community codes of Spanish National Institute of Statistics. This function does not take any parameters.
get_CCAA(...)
get_CCAA(...)
... |
No parameters are required for this function. |
Return a data.frame with two columns. The first column contains the ID code of the Autonomous Community and the second field contains the name of that region.
get_CCAA()
get_CCAA()
With this function, the name of all the Spanish provinces is obtained, along with their ID codes, which are the same as those provided by the Spanish National Institute of Statistics on this website. This function does not take any parameters.
get_Provincias(...)
get_Provincias(...)
... |
No parameters are required for this function. |
It returns a data.frame with two columns. The first column contains the ID code of the province and the second column contains the name of the province.
get_Provincias()
get_Provincias()
The hyperfractionality index, proposed by Kesselman (1996) and Wilden (1991), is another indicator used to measure the number of parties that are relevant in any type of election. This index is very sensitive to the presence of small parties since it gives them more relevance than they really have. The mathematical formula used to calculate the value of this index is as follows:
for and p_i>0 the percentages (as parts per unit) of votes or seats of the party i
hiper(votes, seats)
hiper(votes, seats)
votes |
It is a vector of integers, containing the votes of all the candidates. |
seats |
It is a vector of integers, containing the seats obtained by each of the candidates. |
Returns a dataframe, with the columns "electoral" and "parliamentary" to store the value of the hyperfractionality index in the electoral or parliamentary way respectively
hiper(c(3947,3189,1971,466,345,82),c(184,99,44,10,1,0))
hiper(c(3947,3189,1971,466,345,82),c(184,99,44,10,1,0))
This nationalisation index, whose value ranges between 0 and 1, was proposed by Lago and Montero (2010) and is based on the decision of the parties to take part in the electoral process in all or only some districts. It is calculated by taking into account the electoral results of the parties, as well as the number of seats in the districts where they are elegible. The formula that is used is as follows:
Where: p_j is the number of votes obtained in all the territories over the total expressed as parts per unit. q_j is the number of seats (out of the total number of seats) in the districts where political formation j is presented, expressed as parts per unit.
Two procedures have been enabled for the calculation of this index, one will be called 'automatic' and the other one 'manual'. With the automatic procedure it will use the data of the Spanish Ministry of Home Office and, without further intervention, the indicator for the elections to the General Courts that has been indicated with the parameters of the function will be calculated. For the manual procedure, the data to be processed must be passed as an input of the function, as indicated below in the section concerning the parameters.
IN_LAGO_MONTERO( Ano, Mes, Ruta, n_escanos = 350, Auto = TRUE, d_votos, d_escanos )
IN_LAGO_MONTERO( Ano, Mes, Ruta, n_escanos = 350, Auto = TRUE, d_votos, d_escanos )
Ano |
(Only for automatic case) It represents the year of the data you want to download. This data can be numeric or character (preferably numeric). |
Mes |
(For automatic case only) This is the month in which the election was made. It must be of the character type and two digits, i.e. "04" is valid but "4" is not. |
Ruta |
(Only for automatic case) A path of the local hard disk where the file is downloaded from the Ministry of Home Office must be indicated. Once the download is finished the downloaded file is deleted automatically. |
n_escanos |
(Only for automatic case) This is the total number of seats to be covered. By default, it has a value of 350 which are the deputies who are elected to the Congress of Deputies in Spain. |
Auto |
It contains a logical value that by default is TRUE, indicating that the automatic procedure is done. If you pass to the function the FALSE value then the procedure would be manual. |
d_votos |
(Sólo para procedimiento manual). Es un data.frame, conteniendo en la primera columna la denominación de las regiones o circunscripciones. El resto de las columnas se debe haber una por cada partido político que contenga los votos que ese partido ha tenido en cada una de las circunscripciones, y la denominación de esa columna, serán las siglas de ese partido. |
d_escanos |
(For manual procedure only). It is a data.frame, containing in the first column the name of the regions or districts. The rest of the columns must be one for each political party containing the votes that each party has obtained in each of the districts, and the name of that column will be the acronym of that party. |
The returned value is a list object, with three positions. The first position contains the value of the index (it is called 'V_indice'), the second one the vector containing the votes with respect to the national total expressed as part per unit (it is called 'Porcentaje_votos'), and the third component are the disputed seats (expressed as part per unit) of the districts where the political party under study is presented. Its name is 'Porcentaje_escanos'.
#Procedimiento automático s<-IN_LAGO_MONTERO(2019,"04","F:/",n_escanos = 350) if(!(is.null(s) || is.na(s))){ print(s$V_indice) print(s$Porcentaje_votos) print(s$Porcentaje_escanos) } #Procedimiento manual da1 <- data.frame( # Contains the votes Reg=c("Alava","Albacete","Madrid","Barcelona","Valladolid"), PSOE=c(400,300,0,50,25), PP=c(300,200,10,150,2), Cs=c(400,0,3,300,45), Uno=c(465,23,341,263,0)) da2 <- data.frame( # Contains the total seats of each province Reg=c("Alava","Albacete","Madrid","Barcelona","Valladolid"), escanos=c(2,3,6,5,4)) s2<-IN_LAGO_MONTERO(Auto = FALSE,d_votos = da1,d_escanos = da2)
#Procedimiento automático s<-IN_LAGO_MONTERO(2019,"04","F:/",n_escanos = 350) if(!(is.null(s) || is.na(s))){ print(s$V_indice) print(s$Porcentaje_votos) print(s$Porcentaje_escanos) } #Procedimiento manual da1 <- data.frame( # Contains the votes Reg=c("Alava","Albacete","Madrid","Barcelona","Valladolid"), PSOE=c(400,300,0,50,25), PP=c(300,200,10,150,2), Cs=c(400,0,3,300,45), Uno=c(465,23,341,263,0)) da2 <- data.frame( # Contains the total seats of each province Reg=c("Alava","Albacete","Madrid","Barcelona","Valladolid"), escanos=c(2,3,6,5,4)) s2<-IN_LAGO_MONTERO(Auto = FALSE,d_votos = da1,d_escanos = da2)
This indicator was proposed by Edward V. Huntington and measures the degree of "injustice" in an electoral system by translating the votes obtained by political parties into seats. In this sense, Edward V.Huntington defined this mathematical injustice between two parties competing in an electoral process as the difference in absolute value between the ratios of seats and votes obtained by those two political parties. That is, for each political party the ratio between seats and votes is obtained, and the mathematical injustice will be the difference in absolute value of those ratios.
If we express the above in a mathematical formula we get the following:
for and vi the votes of the party i and ei its seats
InjusticiaM(dates)
InjusticiaM(dates)
dates |
It is a data.frame object that contains the information as follows: The first column is reserved for the name of the political parties. The second column contains the votes obtained, and the third column is used for the seats obtained by that political party. |
The result is a matrix object, of dimension n x n, with n equal to the number of parties provided in the input data.frame. The names of the rows and columns coincide with the names of the parties provided in the input data.frame in the first column.
a<- data.frame(par=c('A','B','C','D'), vot=c(200,300,100,24),sea=c(3,4,1,0), stringsAsFactors = FALSE) InjusticiaM(a)
a<- data.frame(par=c('A','B','C','D'), vot=c(200,300,100,24),sea=c(3,4,1,0), stringsAsFactors = FALSE) InjusticiaM(a)
The function of this same package called 'InjusticeM()', allows to obtain the mathematical injustice for the dataset that is going going to be used for the study. However, if we want to obtain the mathematical injustice for different geographical areas, a significant effort and time is required to prepare and execute the data. With this function, this process is greatly expedited, if what we want to evaluate are results to the Congress of Deputies in Spain (or its counterpart in other countries), since thanks to this function, the information from the Ministry of Interior can be automatically extracted and processed directly for each province and national data, and the result is returned in a list() type object, where each element corresponds to the result obtained for each province or the total for the whole nation under study.
Likewise, if you have another type of election, you can use the parameter Auto=FALSE, and two data.frame will be provided with the characteristics that will be indicated later. In this way the mathematical injustices will be calculated for each region that is indicated in those data.frames
InjusticiaM_desagregada(Ano, Mes, Ruta, Auto = TRUE, d_votos, d_escanos)
InjusticiaM_desagregada(Ano, Mes, Ruta, Auto = TRUE, d_votos, d_escanos)
Ano |
(Mandatory if Auto=TRUE) It is the value of the year of the data to be downloaded. This parameter can be numeric or character (better numeric). |
Mes |
(Mandatory if Auto=TRUE) This is the month in which the election was held. It must be a character with two digits, i.e. "04" is valid but "4" is not. |
Ruta |
(Mandatory if Auto=TRUE) A path to the local hard disk where the data from the Ministry of the Interior will be saved must be indicated. Once the download is completed, the downloaded file will be automatically deleted. |
Auto |
Its default value is TRUE and indicates that the procedure is automatic, with another value the non-automatic process will be executed. |
d_votos |
(Mandatory if Auto != TRUE). It is a data.frame with the first column containing the name of the region, and then a column for each party to be evaluated, which will contain the votes obtained in each region under study. |
d_escanos |
(Mandatory if Auto != TRUE).It is a data.frame with the first column containing the name of the region, and then a column for each party to be evaluated, which will contain the seats obtained in each region covered. |
The result is a list with 53 elements (for the automatic procedure), so that each element is a matrix containing the data of the calculated mathematical injustice. The 'names' in this list are those of Spanish provinces, or the expression 'Total' if they are the data of all Spain. When the procedure is not automatic, a list is also obtained containing a number of elements equal to the number of regions provided plus one, as there is an element called 'Total' which refers to all the territories provided as a whole.
NA
f<-InjusticiaM_desagregada(2019,"04","F:/") # Aggregated mode da1 <- data.frame( # Contains the votes Reg=c("Alava","Albacete","Madrid","Barcelona","Valladolid"), PSOE=c(400,300,0,50,25), PP=c(300,200,10,150,2), Cs=c(400,0,3,300,45), Uno=c(465,23,341,263,0)) da2 <- data.frame( # Contains the seats Reg=c("Alava","Albacete","Madrid","Barcelona","Valladolid"), PSOE=c(4,3,0,0,0), PP=c(2,3,0,1,0), Cs=c(4,0,0,2,1), Uno=c(3,0,3,2,0)) f2<- InjusticiaM_desagregada(Auto=FALSE,d_votos=da1,d_escanos = da2) #No agregegado
f<-InjusticiaM_desagregada(2019,"04","F:/") # Aggregated mode da1 <- data.frame( # Contains the votes Reg=c("Alava","Albacete","Madrid","Barcelona","Valladolid"), PSOE=c(400,300,0,50,25), PP=c(300,200,10,150,2), Cs=c(400,0,3,300,45), Uno=c(465,23,341,263,0)) da2 <- data.frame( # Contains the seats Reg=c("Alava","Albacete","Madrid","Barcelona","Valladolid"), PSOE=c(4,3,0,0,0), PP=c(2,3,0,1,0), Cs=c(4,0,0,2,1), Uno=c(3,0,3,2,0)) f2<- InjusticiaM_desagregada(Auto=FALSE,d_votos=da1,d_escanos = da2) #No agregegado
Jones and Mainwaring (2003), proposed the calculation of this index based on the Gini income concentration index. This index will take values between 0 and 1. A value close to 1 indicates that the party is highly nationalized, and a value close to zero will indicate the opposite.
This index measures the degree of homogeneity of the votes a party receives in all the electoral districts where it competes. In a very brief way, the calculation formula for this indicator is as follows:
INP(dat)
INP(dat)
dat |
Vector containing the proportions (as parts per unit) of the party's vote in each district |
A real number containing the value of the indicator.
INP(c(0.15,0.22,0.24,0.26,0.27,0.27,0.27,0.32,0.33,0.34)) INP(c(0.3,0.1,0.2))
INP(c(0.15,0.22,0.24,0.26,0.27,0.27,0.27,0.32,0.33,0.34)) INP(c(0.3,0.1,0.2))
This indicator is based on the nationalization index of each party. Its calculation is computed using the aggregation of party nationalisation scores weighted with the value of electoral weight, that is, the number of votes obtained. As with the Party Nationalisation Index (INP), values close to 1 will indicate strong nationalisation and values close to zero will indicate the opposite. The formula used for this indicator is as follows:
Where INPi is the nationalization index of party i, and pi is the number of votes obtained by party i.
INSP(datos)
INSP(datos)
datos |
It is a data.frame with the first column containing the name of the electoral district, the rest of the columns correspond to the parties presented and each column will contain the number of votes that each party has obtained in the corresponding electoral district. |
A real number containing the value of the indicator.
a <- data.frame(prov=c("Alava","Albacete","Valladolid"), PP=c(20,30,10),PSOE=c(34,12,45), stringsAsFactors = FALSE) INSP(a) b<-data.frame(prov=c("1","2"),A=c(400,190),B=c(200,1000),stringsAsFactors = FALSE) INSP(b)
a <- data.frame(prov=c("Alava","Albacete","Valladolid"), PP=c(20,30,10),PSOE=c(34,12,45), stringsAsFactors = FALSE) INSP(a) b<-data.frame(prov=c("1","2"),A=c(400,190),B=c(200,1000),stringsAsFactors = FALSE) INSP(b)
An indicator of disproportionality that is appropriate for those systems that use the D'Hondt Law for seats distribution, as is the case in Spain (except in the Senate elections), presents the disadvantage that it only takes into account the difference between seats and votes for the most voted political force. The formula used for its calculation is as follows:
for
L_max(votes, seats)
L_max(votes, seats)
votes |
It is a vector of integers, containing the votes of all the candidates. |
seats |
It is a vector of integers, containing the seats obtained by each of the candidates. |
Returns the value obtained for the index
L_max(c(3947,3189,1971,466,345,82),c(184,99,44,10,1,0))
L_max(c(3947,3189,1971,466,345,82),c(184,99,44,10,1,0))
This indicator is also known as the robust bias index. Its value is obtained by using the slope of the well-known "Tuckey Line" and its use is recommended when there is a "small" group of parties that behave significantly differently from the rest. This procedure is qualified as "robust" because the presence of behaviors of certain parties different from the rest does not substantially alter the line obtained, unlike what happened when it was used in the least squares criteria to make the regression adjustment.#'
L_Tukey(votes, seats)
L_Tukey(votes, seats)
votes |
It is a vector of integers, containing the votes of all the candidates. |
seats |
It is a vector of integers, containing the seats obtained by each of the candidates. |
Returns the value obtained for the index
L_Tukey(c(3947,3189,1971,466,345,82),c(184,99,44,10,0,0))
L_Tukey(c(3947,3189,1971,466,345,82),c(184,99,44,10,0,0))
Loosemore and Hanby disproportionality index ( 1971 ) aims to address the difficulties encountered with the Rae index. To calculate this disproportionality index, the absolute values of the differences between votes and seats are added together and the result is divided by two. The specific formula used is as follows: '
for
Loos_Hanby(votes, seats)
Loos_Hanby(votes, seats)
votes |
It is a vector of integers, containing the votes of all the candidates. |
seats |
It is a vector of integers, containing the seats obtained by each of the candidates. |
Returns the value obtained for the index
Loos_Hanby(c(1200, 30, 4000),c(10,6,8))
Loos_Hanby(c(1200, 30, 4000),c(10,6,8))
With this function you can make choropleth maps, to carry out representations of the data on a map. By default, the map used is that of Spain, but any map of another country could be used too, as long as it is of shapefile type. NOTE: The shapefile to be used can be downloaded from the following web page https://github.com/Miguelro/Electoral/tree/master/Mapa and all the files will be placed in a folder, which will serve to point out the path to be indicated in the 'camino' parameter.
mapa( dat, camino, titulo, size_letra = 3, color_text = "brown", ver_text = TRUE )
mapa( dat, camino, titulo, size_letra = 3, color_text = "brown", ver_text = TRUE )
dat |
It's a data.frame with two columns. The first contains, in the case of Spain, the INE (Spanish National Institute of Statistics) code of the provinces, and the second the value of the variable to be represented. IMPORTANT NOTE: It must be taken special care with the fact that the first column is not of the factor type. It is recommended to be character type, never use a factor. |
camino |
It will be a character value to indicate where are located the files downloaded from github containing the map data. The path must end with the character "/". |
titulo |
The title to be displayed on the map will be specified here. |
size_letra |
This is the font size that will be used to display the numerical values on the map. |
color_text |
It serves to indicate the color of the text that will be used to display the data on the map. |
ver_text |
It must be a Boolean value. By default it is TRUE, to indicate that the data will be shown on the map. On the other hand, if this parameter is set to FALSE the data values will not be displayed. |
Returns a ggplot2 object, containing the map to be represented
d <-data.frame( cod=c(1,2,5,9,15,23,43,50), da = c(3,5,7,10,1,3,80,4) ) suppressWarnings(mapa(d,system.file("maps/", package="Relectoral"), titulo="An example map and some NA values",ver_text = TRUE))
d <-data.frame( cod=c(1,2,5,9,15,23,43,50), da = c(3,5,7,10,1,3,80,4) ) suppressWarnings(mapa(d,system.file("maps/", package="Relectoral"), titulo="An example map and some NA values",ver_text = TRUE))
This indicator (Laakso and Taagepera 1979) is complementary to the electoral fragmentation indicator, and its objective is to measure the number of parties that actually compete in an electoral process. The mathematical formula used to calculate this indicator is as follows:
for and p_i the percentages (as parts per unit) of votes or seats of the party i
nep(votes, seats)
nep(votes, seats)
votes |
It is a vector of integers, containing the votes of all the candidates. |
seats |
It is a vector of integers, containing the seats obtained by each of the candidates. |
Returns a dataframe, with the columns "electoral" and "parliamentary" to store the value of the index of the effective number of parties in the electoral or parliamentary way respectively
nep(c(3947,3189,1971,466,345,82),c(184,99,44,10,1,0))
nep(c(3947,3189,1971,466,345,82),c(184,99,44,10,1,0))
This indicator proposed by Molinar (1991), attempts to evaluate the relevant number of parties that actually exist in an electoral process. It can be said that this index shows a better performance than the indexes of the number of parties and hyperfractionality, both in the weighting it gives to the winning party and in the difference between the first and second parties, as well as in the degree of concentration of the minority parties. The formula used for the calculation of this index is the following:
for and p_i the percentages (as parts per unit) of votes or seats of the party i
nepMolinar(votes, seats)
nepMolinar(votes, seats)
votes |
It is a vector of integers, containing the votes of all the candidates. |
seats |
It is a vector of integers, containing the seats obtained by each of the candidates. |
Returns a dataframe, with the columns "electoral" and "parliamentary" to store the value of the index of the Number of parties of Molinar in the electoral or the parliamentary way respectively.
nepMolinar(c(3947,3189,1971,466,345,82),c(184,99,44,10,1,0))
nepMolinar(c(3947,3189,1971,466,345,82),c(184,99,44,10,1,0))
This dimension is one of the most important in democratic systems, as it explains part of the stability and bankruptcy problems of democracies. The index that is calculated with this function needs the data of the ideological location of the parties, which are difficult to obtain, and that is something as simple as a scale of values between 1 and 10, in such a way that the closer to 1 the valuation of a political party is, it will be more classified as left-wing ideology, and the opposite case will occur when a political formation has a rating at the other end of the scale. The value obtained for this ideological position will be placed in the second column of the data.frame called "data", which is the first parameter that is passed to the function and whose structure is explained later, in the parameters section. If the indicator takes a value close to zero, it means there will be no polarization, and the polarization will increase as the indicator takes higher values.
In this section the weighted polarization index is calculated. For its calculation the following formulas will be used:
for
for
polarizacion(datos, Tipo = 1)
polarizacion(datos, Tipo = 1)
datos |
It is a data.frame with three columns: the first one contains the name of the political parties. The second contains the value of the ideological thinking location (scale from 1 to 10), and the third the number of votes obtained (electoral polarization), or the number of seats obtained (parliamentary polarization). |
Tipo |
It can take either value 1 or 2. 1 To indicate that the weighted formula is obtained but by calculating the distance to the weighted mean squared. If this parameter takes the value of 2, the formula that gets the absolute value of the differences to the weighted average will be used instead. |
Returns a numeric value of this indicator.
d <- data.frame(partidos=c("RN","PDC","PS","PPD","UDI","PRSC","otros"), ubicacion=c(6.36,5.31,2.73,4.13,7.04,4.00,5.33), c(19,20,15,21,33,7,5)) polarizacion(d,Tipo = 2)
d <- data.frame(partidos=c("RN","PDC","PS","PPD","UDI","PRSC","otros"), ubicacion=c(6.36,5.31,2.73,4.13,7.04,4.00,5.33), c(19,20,15,21,33,7,5)) polarizacion(d,Tipo = 2)
With this function the slightly adapted version of the polarisation index from Dalton (2008) is computed to measure polarization. This index weights the ideological positions of the parties by their election results. This indicator ranges from 0 (in the hypothetical case that all parties occupy the same ideological position) to 10 if the parties are at the extremes of the scale position. The formula to compute it is as follows:
Pd = sqrt(sum(p_j*(x_j-mean(x_p))/4.5)^2)
for
polarizacion_Dalton(datos)
polarizacion_Dalton(datos)
datos |
It is a data.frame with three columns: the first one contains the name of the political parties. The second must have the value of the ideological location (scale from 1 to 10), and the third one the percentage of votes obtained with respect to all the parties presented, whether or not they are taken into account to calculate the formula. |
Returns the numerical value of this indicator
d2<- data.frame(partidos=c("RN","PDC","PS","PPD","UDI","PRSC"), ubicacion=c(6.36,5.31,2.73,4.13,7.04,4.00), c(14.12,20.76,10.05,15.42,22.36,3.54)) polarizacion_Dalton(d2)
d2<- data.frame(partidos=c("RN","PDC","PS","PPD","UDI","PRSC"), ubicacion=c(6.36,5.31,2.73,4.13,7.04,4.00), c(14.12,20.76,10.05,15.42,22.36,3.54)) polarizacion_Dalton(d2)
This index measures electoral disproportionality based on the result obtained in an election. It has the disadvantage that it is highly influenced by the number of small parties that compete in the elections. The formula used is as follows:
for
To compute its value, an integer vector corresponding to the votes obtained by each party and another with the corresponding seats must be provided as parameters of the formula. The R code will be in charge of calculating the corresponding percentages to obtain the index.
Rae(votes, seats)
Rae(votes, seats)
votes |
It is a vector of integers, containing the votes of all the candidates. |
seats |
It is a vector of integers, containing the seats obtained by each of the candidates. |
Returns the value obtained for the index
Rae
: indicators
NA
Rae(c(1200, 30, 4000),c(10,6,8))
Rae(c(1200, 30, 4000),c(10,6,8))
It was Rae himself who realised the problems in calculating the RAE index by taking all parties into account. For this reason he reviewed the basis of the index and decided to exclude from the calculation all parties that did not reach 0.5 percent of the votes. The function created to calculate this index takes this corrective value by default, although it is allowed to enter another value, as it can be seen in the example below.
To compute its value, the integer vectors corresponding to the votes obtained by each party and their seats must be provided as parameters of the formula. The R code will be in charge of calculating the corresponding percentages in order to obtain the index.
Rae_corregido(votes, seats, correc = 0.5)
Rae_corregido(votes, seats, correc = 0.5)
votes |
It is a vector of integers, containing ALL the votes of all the candidates. |
seats |
It is a vector of integers, containing ALL the seats obtained by each of the candidates. |
correc |
This is a decimal value that indicates the minimum percentage of votes needed in order to be taken into account for the formula. By default its value is 0.5. |
Returns the value obtained for the index
Rae_corregido(c(1200, 30, 4000),c(10,6,8), correc = 1) Rae_corregido(c(1200, 30, 4000),c(10,6,8))
Rae_corregido(c(1200, 30, 4000),c(10,6,8), correc = 1) Rae_corregido(c(1200, 30, 4000),c(10,6,8))
With this function we calculate the regionalism indexes described in the book "Analysis of electoral data" from Pablo Oñate y Francisco A. Ocaña (page 48). The reader is referred to this publication in order to understand the meaning of the indicators computed with this function. More precisely, the Regionalist Voting Index (VRta), the Differentiated Regionalist Voting Index (VRtaD), and the Differentiated Regional Voting Index (VRD) will be calculated.
Regionalismo( Ano = 0, Mes = "", RutaDescarga = "", Auto = TRUE, datos = "", PANES = "", Generate_PANES = FALSE )
Regionalismo( Ano = 0, Mes = "", RutaDescarga = "", Auto = TRUE, datos = "", PANES = "", Generate_PANES = FALSE )
Ano |
It is the year of the electoral process to be dealt with. It must be a four-digit numerical value. If a manual procedure is used, no value is needed for this parameter. |
Mes |
It is the month of the electoral process, it must be a string with two numerical characters, associated with the month in which the elections took place. If a manual procedure is used, no value is required for this parameter. |
RutaDescarga |
It should be a string indicating the way to download the file from the Spanish Ministry of Home Office. This file is automatically removed if the process finish successfully. The user has to be aware that the path provided must correspond to a computer location where the user has read and write permissions, otherwise the process will not be completed. If a manual procedure is used, no value is required for this parameter. |
Auto |
It can take the logical values TRUE or FALSE. By default, it has the value TRUE to indicate that the user wants the process to be automatic. In the case of wanting a manual process, this parameter will take the value FALSE. |
datos |
In this parameter you must enter the values that will be processed if manual processing is chosen, i.e. "Auto=FALSE". It must be a data.frame with the following structure: The first column must contain the name of the intermediate unit (in the case of Spain the autonomous regions), in the second column must include the name of the lower units (in the case of Spain the name of the provinces), and then there must be a column for each political party containing the votes obtained by that party in each lower unit (for Spain in each province). The value of the name for each of these columns must be the acronyms that identify each political party. |
PANES |
Here the user should provide the complete path of the csv-type file containing, for each party, the information on whether that party is regionalist or not. "1" will denote that the party is regionalist or nationalist and "0" that it is not. These values will appear in the second column of that csv file. The first column must have the acronym of each political party under study. |
Generate_PANES |
A boolean type parameter, by default its value is FALSE. In case it is TRUE, the csv file indicated in the "PANES" parameter will be generated. The first line of this file will be the following: "PARTIES,PANE", which will be the name of the variables with which the function will work internally. In this case, the csv file generated will contain a column with the acronyms of the political parties, and then, manually, "1" will be written down if the match is "PANE" (nationalist or regionalist party) and 0 if it is "NO PANE" (non-nationalist or non-regionalist party). That is to say, with the parameter Generate_PANES = TRUE, a help system is obtained to obtain the file that must be passed with the "PANES" parameter. But this csv file can also be generated in a completely manual way, if the user wishes. |
It returns a list of all the indicators obtained with this function. This initial list, in turn, contains two other lists:
VRtaD. It is composed of three other lists, each one containing a data.frame with the following information: $VRta_Provincias: contains the values of the VRta indicator at the lowest level (in the case of Spain, the provinces). $VRta_CCAA contains the VRta indicator at the intermediate level (in the case of Spain, at an autonomous region level). $VRtaD contains the indicator VRtaD at the lowest level.
VRD. Composed of three other lists, each one containing a data.frame with the following information: $inferior_medio contains the VRD value of the lower level (provinces in Spain) with respect to the intermediate level (autonomous regions in Spain). $inferior_superior contains the VRD value for the lower level with respect to the upper level (State level). $medio_superior contains the value of the VRD index at the intermediate level with respect to the upper one.
r <- Regionalismo(Ano=2019,Mes = "11",RutaDescarga = "F:/", PANES = system.file("regionalismo","Regionalismo.csv", package="Relectoral"))
r <- Regionalismo(Ano=2019,Mes = "11",RutaDescarga = "F:/", PANES = system.file("regionalismo","Regionalismo.csv", package="Relectoral"))
This option uses various methods whose main common feature is that the number of votes obtained by the political candidatures are divided by a series of numbers. The name of the method used depends on the numbers which compose that series. In this sense, the methods admitted are the following:
dhont. It is the so-called D'Hondt Law and is the procedure used in Spain to transform votes into seats in the Congress of Deputies. The series of numbers used as a quotient are the integer numbers: 1,2,...n , where n is the number of seats to be distributed.
saint_lague. This is the Sainte Lagüe method, Webster's method or odd-numbered divisors. The set of divisors is formed by the odd numbers, that is 1,3,..,2n+1.
saint_lague_Mod.It is the modified Sainte Lagüe method, a variant of the Sainte Lagüe method, according to which the initial quotient is v/1.4 and once each party has a seat the standard formula v/(2n+1) is used.
Danish. In this method the divisors go from three to three units, that is to say it is formed by the numbers: 1,4,7,10,13... and the n-th divisor would be 3*n-2.
Imperiali. The divisors are the positive integers but starting from number 2 onwards, that is: 2,3,4,...
Hill_Huntington. In this case the divisors are formed by the following sequence: sqrt(2),sqrt(6),sqrt(12),...., sqrt(n*(n+1))
Dean.The set of divisors consists of the following numbers: 4/3, 12/5, 24/7,40/0,....,(2n)(n+1)/(2n+1)
In all cases the value of q is rounded up to the nearest integer.
reparto_div(candidaturas, votos, escanos, metodo)
reparto_div(candidaturas, votos, escanos, metodo)
candidaturas |
A text vector containing the name of the parties. |
votos |
An integer vector with the votes of each party. |
escanos |
An integer number stating the total number of seats to be allocated. |
metodo |
It is the method to be used. The allowd values are: c("dhondt","saint_lague","saint_lague_Mod", "Danish","Imperiali","Hill_Huntington", "Dean") |
Returns a data.frame with the names of the political parties and the number of Members allocated with the chosen method.
Restos_Mayores
for allocation using the largest remainder method
https://en.wikipedia.org/wiki/D%27Hondt_method on Wikipedia
https://bit.ly/3aEidM9 on Wikipedia.
https://bit.ly/2Q0a0u0 on the internet.
reparto_div(c("A","B","C","D","E"),c(340000,280000,160000,60000,15000),7,metodo="dhondt") reparto_div(c("A","B","C","D"),c(340000,280000,160000,60000),7,metodo='saint_lague') reparto_div(c("A","B","C","D"),c(340000,280000,160000,60000),7,metodo='saint_lague_Mod') reparto_div(c("A","B","C","D"),c(340000,280000,160000,60000),7,metodo='Danish') reparto_div(c("A","B","C","D"),c(340000,280000,160000,60000),7,metodo='Imperiali') reparto_div(c("A","B","C","D"),c(340000,280000,160000,60000),7,metodo='Dean')
reparto_div(c("A","B","C","D","E"),c(340000,280000,160000,60000,15000),7,metodo="dhondt") reparto_div(c("A","B","C","D"),c(340000,280000,160000,60000),7,metodo='saint_lague') reparto_div(c("A","B","C","D"),c(340000,280000,160000,60000),7,metodo='saint_lague_Mod') reparto_div(c("A","B","C","D"),c(340000,280000,160000,60000),7,metodo='Danish') reparto_div(c("A","B","C","D"),c(340000,280000,160000,60000),7,metodo='Imperiali') reparto_div(c("A","B","C","D"),c(340000,280000,160000,60000),7,metodo='Dean')
This function is used to translate votes into seats, following the criterion called "Largest Remains". In summary, this method is calculated as follows: the total number of votes is divided by the total number of seats (cost of each seat). The votes of each party are then divided by the above ratio. The integer part of the above results are taken, which will be the initial seats for each party. The remaining seats to be distributed are allocated to the parties with the largest remainders (see https://en.wikipedia.org/wiki/Largest_remainder_method ).
The cost of each seat is what differentiates one method from another. Thus if n is the total number of seats and m the sum of all votes, the denomination of the methods is as follows, depending on the ratio that is taken:
Hare (Hare): q=m/n
Droop (Droop):q=1+(m/(1+n))
Imperiali (Imperiali): q=m/(n+2)
Imperiali modificado (Mod_Imperiali): q=m/(n+3)
Hangenbach Bischof (hangenbach-bischo): q=m/(n+1)
In all cases the value of q is rounded to the nearest integer.
Restos_Mayores(partidos, votos, escanos, metodo = "Hare")
Restos_Mayores(partidos, votos, escanos, metodo = "Hare")
partidos |
A character vector containing the name of the parties. |
votos |
An integer vector with the votes of each party. |
escanos |
An integer number containing the total number of seats to be allocated. |
metodo |
This is the method to be used. The allowed values are: "Hare", "Droop", "Imperiali", "Mod_Imperiali", "hangenbach-bischo". The default value is "Hare". |
A dataframe with the political parties and the votes assigned to each.
reparto_div
for the allocation using divisor method
https://en.wikipedia.org/wiki/Largest_remainder_method on Wikipedia.
Restos_Mayores(c("A","B","C","D","E","F","G"), c(391000,311000,184000,73000,27000,12000,2000), 21,metodo = "Imperiali")
Restos_Mayores(c("A","B","C","D","E","F","G"), c(391000,311000,184000,73000,27000,12000,2000), 21,metodo = "Imperiali")
This index is designed to study the disproportionality of those electoral systems that use the procedure of distribution of seats that has the same name (Sainte-Lague method). It should be noted that this indicator takes into account the relative difference between the seats-votes of each party, as well as that of the system as a whole. The formula used for its calculation is as follows:
for
Sainte_Lague(votes, seats)
Sainte_Lague(votes, seats)
votes |
It is a vector of integers, containing the votes of all the candidates. |
seats |
It is a vector of integers, containing the seats obtained by each of the candidates. |
Returns the value obtained for the index
Sainte_Lague(c(3947,3189,1971,466,345,82),c(184,99,44,10,1,0))
Sainte_Lague(c(3947,3189,1971,466,345,82),c(184,99,44,10,1,0))
This function calculates the total volatility of Pederson (1983:31 and 32), and the volatility between blocks. The formulas for calculating these values can be found in Oñate and Ocaña's book "Analysis of electoral data", page 45. This dimension compares the behaviour of the electorate in two different elections, so as to see the transfer of votes, either between blocks or between political parties.
volatilidad(dat1, dat2, enlace)
volatilidad(dat1, dat2, enlace)
dat1 |
It is a data.frame with two columns. The first column contains the acronym of the political party and the second the votes or seats obtained from the first period of time, depending on whether you want to calculate the electoral or parliamentary volatility respectively. |
dat2 |
It is a data.frame with two columns. The first column contains the acronym of the political party and the second the votes or seats obtained from the second period of time, depending on whether you want to calculate the electoral or parliamentary volatility respectively. |
enlace |
It is a data.frame that serves to link the parties, coalitions or groupings that you want to compare between the two periods under study. This data.frame contains a total of 22 columns. The first column contains the corresponding name of the political parties. The next 10 columns (called p1_i for i=1,2,...,10) are used to indicate the number of the row(s) of the party(ies) of the first electoral period to be grouped. The next 10 columns (called p2_i for i=1,2,...,10) are used to indicate the number of the row(s) of the party(ies) of the second electoral period to be grouped. When some of the 10 columns are not needed, the remaining columns are filled in with zeros. The data in each row is used with following purpose: For the first block of 10 columns, the votes/seats of the parties appearing in that block are added up. For the second block of 10 columns, the votes/seats in that second block are also added up. These two values will be used later on for comparison. The last column of this data.frame (called "block"), will contain the values "D" or "I" indicating "Right", "Left", respectively. To clarify all these concepts execute in R browseVignettes("Relectoral") or vignette("Volatility") |
It returns a list with two objects. The first is the total volatility, and the second is the inter-block volatility.