R/effective_number_of_parties.R

Defines functions enp

Documented in enp

#  Party System Indicators - Effective Number of Parties (ENP)----

enp <- function(votes, method = 'Laakso-Taagepera') {
  if (class(votes) != 'numeric') {
    stop('Votes input vector must be numeric')
  }
  if (!method %in%  c('Laakso-Taagepera', 'Golosov')) {
    stop('Not a valid method')
  }
  if (method == 'Laakso-Taagepera') {
    enp <- 1/sum((votes/sum(votes))^2)
  } else if (method == 'Golosov') {
    shares <- votes / sum(votes)
    enp <- sum(shares/(shares + (max(shares))^2 - shares^2))
  } 
  enp
}

Try the electoral package in your browser

Any scripts or data that you put into this service are public.

electoral documentation built on April 1, 2022, 1:06 a.m.