Title: | Preference Voting with Explanatory Graphics |
---|---|
Description: | Implements the Single Transferable Vote (STV) electoral system, with clear explanatory graphics. The core function stv() uses Meek's method, the purest expression of the simple principles of STV, but which requires electronic counting. It can handle votes expressing equal preferences for subsets of the candidates. A function stv.wig() implementing the Weighted Inclusive Gregory method, as used in Scottish council elections, is also provided, and with the same options, as described in the manual. The required vote data format is as an R list: a function pref.data() is provided to transform some commonly used data formats into this format. References for methodology: Hill, Wichmann and Woodall (1987) <doi:10.1093/comjnl/30.3.277>, Hill, David (2006) <https://www.votingmatters.org.uk/ISSUE22/I22P2.pdf>, Mollison, Denis (2023) <arXiv:2303.15310>, (see also the package manual pref_pkg_manual.pdf). |
Authors: | Denis Mollison [aut, cre, cph]
|
Maintainer: | Denis Mollison <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.4.0 |
Built: | 2025-02-21 05:00:33 UTC |
Source: | https://github.com/denismollison/pref |
Votes are in a ballot-format matrix
c99
c99
A list with 10 variables, largest the vote matrix (343 x 10)
q()
number of seats
number of candidates
...
Votes are in a ballot-format matrix
cnc17
cnc17
A list with 10 variables, largest the vote matrix (930 x 8)
number of seats
number of candidates
...
https://www.macs.hw.ac.uk/~denis/stv_elections/SC2017/
Votes are in a ballot-format matrix
hc12
hc12
A list with 10 variables, largest the vote matrix (629 x 6)
number of seats
number of candidates
...
https://www.macs.hw.ac.uk/~denis/stv_elections/SC2012/
Votes are in a ballot-format matrix
j02
j02
A list with 10 variables, largest the vote matrix (1168 x 10)
q()
number of seats
number of candidates
...
https://www.macs.hw.ac.uk/~denis/stv_elections/jmt2002.blt
Votes are in a ballot-format matrix
nws17
nws17
A list with 10 variables, largest the vote matrix (629 x 6)
number of seats
number of candidates
...
https://www.macs.hw.ac.uk/~denis/stv_elections/SC2017/
Votes are in a ballot-format matrix
p17
p17
A list with 10 variables, largest the vote matrix (1456 x 8)
number of seats
number of candidates
...
https://www.macs.hw.ac.uk/~denis/stv_elections/SC2017/
put election data in an R file (.rda)
pref.data( datafile, mult = FALSE, details = TRUE, parties = FALSE, ballot = FALSE, friendly = FALSE, header = FALSE )
pref.data( datafile, mult = FALSE, details = TRUE, parties = FALSE, ballot = FALSE, friendly = FALSE, header = FALSE )
datafile |
File with election data |
mult |
Whether includes aggregated votes (default FALSE) |
details |
Whether full election detail (default) or just vote matrix |
parties |
File with party details (default FALSE, i.e. omit) |
ballot |
Default FALSE (meaning pref format) |
friendly |
Default FALSE (meaning most details after votes) |
header |
Whether a vote matrix has a header |
A standardised list of election info to save in a .rda file; for details see manual pref_pkg_manual.pdf (section 4)
datafile=system.file("extdata","yale.dat",package="pref") yale=pref.data(datafile,details=FALSE) datafile=system.file("extdata","Jedburgh2012.blt",package="pref") parties12=system.file("extdata","parties_SC2012.txt",package="pref") jed12=pref.data(datafile,mult=TRUE,parties=parties12) datafile=system.file("extdata","jmt2002.blt",package="pref") j02=pref.data(datafile,friendly=TRUE)
datafile=system.file("extdata","yale.dat",package="pref") yale=pref.data(datafile,details=FALSE) datafile=system.file("extdata","Jedburgh2012.blt",package="pref") parties12=system.file("extdata","parties_SC2012.txt",package="pref") jed12=pref.data(datafile,mult=TRUE,parties=parties12) datafile=system.file("extdata","jmt2002.blt",package="pref") j02=pref.data(datafile,friendly=TRUE)
STV election count - uses Meek STV, allows equal preferences
stv( votedata, outdirec = tempdir(), plot = TRUE, webdisplay = FALSE, interactive = FALSE, messages = TRUE, timing = FALSE, map = FALSE )
stv( votedata, outdirec = tempdir(), plot = TRUE, webdisplay = FALSE, interactive = FALSE, messages = TRUE, timing = FALSE, map = FALSE )
votedata |
File with vote data |
outdirec |
Needs to be set for permanent record of results |
plot |
If =TRUE (default) produces plots of count and webpages in outdirec |
webdisplay |
If =TRUE displays plots and statistics as web pages |
interactive |
If =TRUE reports and pauses at each stage of the count (press return to continue to next stage) |
messages |
If=TRUE prints 1-line initial and final reports |
timing |
Whether to report computing time at each stage |
map |
Link to a map or other URL associated with election |
A list containing vote and count data, + optional web pages; for details see manual pref_pkg_manual.pdf (section 3)
cnc17meek=stv(cnc17,plot=FALSE) c99result=stv(c99,plot=FALSE) y12meek=stv(y12,plot=FALSE)
cnc17meek=stv(cnc17,plot=FALSE) c99result=stv(c99,plot=FALSE) y12meek=stv(y12,plot=FALSE)
Makes webpage plots of result of an STV election
stv.plots(elecdata, outdirec = tempdir(), webdisplay = FALSE, map = FALSE)
stv.plots(elecdata, outdirec = tempdir(), webdisplay = FALSE, map = FALSE)
elecdata |
An R list of results from stv or stv.wig |
outdirec |
A directory for web page output |
webdisplay |
If TRUE displays the main output web page |
map |
A possible extra showing map of election location |
Webpages with plots of election count and results
c99result=stv(c99) c99plots=stv.plots(c99result) nws17wig=stv.wig(nws17) nws17plots=stv.plots(nws17wig)
c99result=stv(c99) c99plots=stv.plots(c99result) nws17wig=stv.wig(nws17) nws17plots=stv.plots(nws17wig)
STV election count using WIG as for Scottish Council elections calculated to 5 places of decimals as used for those elections
stv.wig( votedata, outdirec = tempdir(), plot = TRUE, webdisplay = FALSE, interactive = FALSE, messages = TRUE, timing = FALSE, map = FALSE )
stv.wig( votedata, outdirec = tempdir(), plot = TRUE, webdisplay = FALSE, interactive = FALSE, messages = TRUE, timing = FALSE, map = FALSE )
votedata |
File with vote data |
outdirec |
Needs to be set for permanent record of results (press return to continue to next stage) |
plot |
If =TRUE (default) produces plots of count and webpages in outdirec |
webdisplay |
If =TRUE displays plots and statistics as web pages |
interactive |
If =TRUE reports and pauses at each stage of the count |
messages |
If=TRUE prints 1-line initial and final reports |
timing |
Whether to report computing time at each stage |
map |
Link to a map or other URL associated with election |
A list containing votes at each stage, + optional web pages; for details see manual pref_pkg_manual.pdf (section 3)
hc12wig=stv.wig(hc12,plot=FALSE,messages=FALSE) nws17wig=stv.wig(nws17,plot=FALSE) p17wig=stv.wig(p17,plot=FALSE) cnc17wig=stv.wig(cnc17,plot=FALSE,timing=TRUE)
hc12wig=stv.wig(hc12,plot=FALSE,messages=FALSE) nws17wig=stv.wig(nws17,plot=FALSE) p17wig=stv.wig(p17,plot=FALSE) cnc17wig=stv.wig(cnc17,plot=FALSE,timing=TRUE)
Votes are in a ballot-format matrix
y12
y12
A list with 10 variables, largest the vote matrix (424 x 44)
number of seats
number of candidates
...
https://cran.r-project.org/package=STV