R/compute_competitiveness.R
    compute_competitiveness.RdFuncion que describe el grado de competencia de una eleccion
(Function that describes the degree of competition of an election)
compute_competitiveness(data, level = "provincia")
| data | un tibble guardado como objeto en el Enviroment luego de consultar  (A tibble saved as an object in the Enviroment after querying   | 
    
|---|---|
| level | un character que establece el nivel de agregacion sobre el que se quiere calcular la competitividad:
por defualt es  (Establishes the level of aggregation on which you want to compute competitiveness: by definition it is   | 
    
devuelve un tibble con class "tbl_df","tbl", "data.frame" con el computo de competitividad de una elccion. El resultado puede
ser un valor entre 0 y 1,
los cuales representan falta de competencia y competitivdad maxima, respectivamente
(returns a tibble with class "tbl_df", "tbl", "data.frame" with the computation of the level of competitiveness of an elction.
The result can be a value between 0 and 1, which represent a lack of competition and maximum competitiveness, respectively).
\(Competitividad\) mide la diferencia porcentual de votos válidos obtenidos por los dos partidos más votados \(a\) y \(b\). Puede tomar valores entre \([0,1]\) donde \(1\) es lo más comeptitivo (\(a = 50\%\) y \(b = 50\%\) de los votos). La fórmula utilizada es: $$Competitividad = 1 - (a - b)$$
REQUISITO:
Para datos obtenidos con get_election_data el formato de data debe ser long para calcular compute_competitiveness.
Si data es wide se puede transformar con make_long
(For data obtained with get_election_data long format of data is required for compute_competitiveness. If data is in wide format
you can transform it with make_long).
tucuman_dip_gral_2017#> # A tibble: 6 x 8 #> category round year codprov name_prov electores listas votos #> <chr> <chr> <dbl> <chr> <chr> <dbl> <chr> <dbl> #> 1 dip gral 2017 23 TUCUMAN 1217274 0180 154930 #> 2 dip gral 2017 23 TUCUMAN 1217274 0503 46609 #> 3 dip gral 2017 23 TUCUMAN 1217274 0521 319221 #> 4 dip gral 2017 23 TUCUMAN 1217274 0548 459257 #> 5 dip gral 2017 23 TUCUMAN 1217274 blancos 5920 #> 6 dip gral 2017 23 TUCUMAN 1217274 nulos 12947tucuman_dip_gral_2017 %>% compute_competitiveness()#> # A tibble: 1 x 5 #> codprov competitividad year category round #> <chr> <dbl> <dbl> <chr> <chr> #> 1 23 0.860 2017 dip gral