SPIr provides tools to compute and analyse the Segment Pivotality Index (SPI) for hierarchical electoral systems, such as Assembly Constituencies (ACs) nested within Parliamentary Constituencies (PCs). SPI measures how pivotal each sub-unit is to determining the final outcome when only meso-level data are available.
Although motivated by the Indian electoral context, SPIr is fully generalisable to any hierarchical dataset (e.g., branches within firms, districts within regions).
You can install the development version of SPIr from GitHub with:
install.packages("remotes")
remotes::install_github("PawasPratikshit/SPIr")
library(SPIr)
On some systems, package-level help does not appear
via ?SPIr.
The correct and reliable way to see all documentation is:
help(package = "SPIr")
Function-level help works normally:
?compute_spi
?add_spi
?summary_spi
?plot_spi_distribution
Here is a minimal working example:
library(SPIr)
library(dplyr)
df <- tibble(
pc = c(1,1,1,1),
ac = c(1,1,2,2),
cand = c("A","B","A","B"),
votes = c(60,40,55,45)
)
spi_df <- compute_spi(
df,
pc_id = pc,
ac_id = ac,
candidate = cand,
votes = votes
)
spi_df
help(package = "SPIr") # browse documentation
spi_help() # quick overview
spi_df <- compute_spi(...)
full_df <- add_spi(...)
summary_spi(spi_df)
plot_spi_distribution(spi_df)
If you use SPIr in your research, please cite:
Pratikshit, Pawas. (2025). SPIr: Tools for Computing the Segment Pivotality Index.
Issues, feature requests, and pull requests are welcome: