Learn R Programming

pref

Preference voting with explanatory graphics

There is a full manual pref_pkg_manual.pdf

Installation

You can install pref from CRAN with:

# install.packages("pref")

You can install the development version of pref from GitHub with:

# install.packages("devtools")
devtools::install_github("denismollison/pref")

Usage

The main functions count votes from a Single Transferable Vote (STV) election, and illustrate the count with clear explanatory graphics. The core option is Meek STV, which is the purest expression of the simple principles of STV (see Section 7 of the manual), but requires electronic counting. It can handle votes expressing equal preferences for subsets of the candidates. The function stv.wig implements the Weighted Inclusive Gregory method, as used in Scottish council elections, with the same options as stv, as described below. The functions stv and stv.wig require vote data input as an R list, whose essential component is a vote data matrix, but which can contain details such as an election title, and candidates’ parties and party colours. The function pref.data can translate various standard data formats into the required R list format.

Graphical output includes expository web pages; the function stv.result prints a summary of the election count and result.

Six examples are provided, drawn from real elections, hc12, p17, nws17, cnc17, yale and j02. The first four are from Scottish Council elections, the first a very simple case and the second a more usual one. The third example (nws17) is one where using the official counting method (WIG) no candidate achieves the fixed quota. The fourth is one where Meek and WIG STV produce different outcomes. The fifth, from a Yale faculty election, is an example with a large number of candidates (44 for 4 places). A simplified version, showing just the later stages of this election is provided as y12.

The final example, j02, is from a charity’s trustees election in which equal preferences were allowed.

To run, for example, the first of these: r # library(pref) hc12c=stv(hc12)

This code produces a list of variables summarising the count and final outcome. For details and options, see the manual.

Copy Link

Version

Install

install.packages('pref')

Monthly Downloads

158

Version

0.4.0

License

MIT + file LICENSE

Issues

Pull Requests

Stars

Forks

Maintainer

Denis Mollison

Last Published

February 2nd, 2024

Functions in pref (0.4.0)

hc12

Unusually simple example of a political STV election - Helensburgh Central 2012
stv.plots

Makes webpage plots of result of an STV election
stv.wig

STV election count using WIG as for Scottish Council elections calculated to 5 places of decimals as used for those elections
pref.data

put election data in an R file (.rda)
stv

STV election count - uses Meek STV, allows equal preferences
nws17

Example of a political STV election - North West and Central Sutherland 2017 Unusual in that under WIG no candidate reaches the (fixed) quota
cnc17

Example of a political STV election - Cumnock and New Cumnock 2017
y12

Example of an STV election - Yale faculty election (last 12)
c99

Example of an election of an academic organisation using STV allowing equal preferences frelection om an
j02

Example of an STV election allowing equal preferences - John Muir Trust 2002
p17

Example of a political STV election - Partick 2017