El número efectivo de partidos es el nombre de una página de la Wikipedia, que contiene la fórmula
$$ N = \frac{1}{\sum_i p_i^2}$$
y excipiente alrededor.
Aplicada a España (usando datos del CIS como proxy),
Como casi siempre, el código:
library(rvest) library(rvest) library(reshape2) library(plyr) library(zoo) url <- "http://www.cis.es/cis/export/sites/default/-Archivos/Indicadores/documentos_html/sB606050010.html" raw <- read_html(url) tmp <- html_nodes(raw, "table") tmp <- html_table(tmp[[2]], fill = TRUE) colnames(tmp)[1] <- "partido" tmp <- tmp[!is.na(tmp$partido),] tmp <- tmp[1:30,] tmp <- melt(tmp, id.vars = "partido") tmp <- tmp[tmp$value != ".",] tmp$value <- as.numeric(tmp$value) tmp$variable <- gsub("ene", "01-", tmp$variable) tmp$variable <- gsub("abr", "04-", tmp$variable) tmp$variable <- gsub("jul", "07-", tmp$variable) tmp$variable <- gsub("oct", "10-", tmp$variable) tmp$variable <- gsub("-0", "-200", tmp$variable) tmp$variable <- gsub("-1", "-201", tmp$variable) tmp$variable <- gsub("-9", "-199", tmp$variable) tmp$variable <- paste0("01-", tmp$variable) tmp$variable <- as.Date(tmp$variable, format = "%d-%m-%Y") dat <- tmp dat <- ddply(dat, .(variable), transform, total = value / sum(value)) res <- ddply(dat, .(variable), summarize, enp = 1 / (sum(total^2))) res <- zoo(res$enp, order.by = res$variable) plot(res, main = "Número efectivo de partidos\nen España(1996-2016)", xlab = "", ylab = "número efectivo de partidos")