stv: Single Transferable Vote

Description Usage Arguments Details Value Author(s) References Examples

Description

Count votes using the single transferable voting method.

Usage

1
2
3
4
5
6
7
stv(votes, mcan = NULL, eps = 0.001, fsep = '\t', verbose = FALSE, ...)

## S3 method for class 'vote.stv'
summary(object, ...)

## S3 method for class 'vote.stv'
view(object, ...)

Arguments

votes

Matrix or data frame containing the votes. Rows correspond to the votes, columns correspond to the candidates. If it is a character string it is interpreted as a tab-separated file name from which the votes are to be read. See below for more details.

mcan

Number of candidates to be elected. By default it is half the number of candidates standing.

eps

Value added to the quota. I.e. the STV quota is computed as
number_of_first_preferences/(number_of_seats + 1) + eps.

fsep

If votes is a file name, this argument gives the column separator in the file.

verbose

Logical. If TRUE the progress of the count will be printed.

...

Not used.

object

Object of class vote.stv.

Details

For a description of the single transferable vote system see http://imstat.org/elections/stvprocess.htm.

The input data votes is structured as follows: Row i contains the preferences of voter i numbered 1, 2, …, r, 0,0,0,0, in some order. The columns correspond to the candidates. The dimnames of the columns are the names of the candidates; if these are not supplied then the candidates are lettered A, B, C, .... If the dataset contains missing values (NA), they are replaced by zeros.

Ties are resolved using the forwards tie-breaking method, see Newland and Briton (Section 5.2.5).

Value

Function stv returns an object of class vote.stv which is a list with the following objects:

elected

Vector of names of the elected candidates in the order in which they were elected.

preferences

Matrix of preferences. Columns correspond to the candidates and rows to the counts (i.e. voting rounds).

quotas

Vector of quotas, one for each count.

elect.elim

Matrix of the same shape as preferences. Value 1 means that the corresponding candidate was elected in that round; value -1 means an elimination.

data

Input data with invalid votes removed.

invalid.votes

Matrix of invalid votes that were removed from the original dataset.

Author(s)

Bernard Silverman, Hana Sevcikova, Adrian Raftery

References

R.A. Newland and F.S. Britton (1997). How to conduct an election by the Single Transferable Vote. ERS 3rd Edition. http://www.rosenstiel.co.uk/stvrules/index.html

http://imstat.org/elections/stvprocess.htm

https://en.wikipedia.org/wiki/Single_transferable_vote

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# Reproducing example from Wikipedia
# https://en.wikipedia.org/wiki/Single_transferable_vote#Example
# Uses eps=1
data(food_election)
stv.food <- stv(food_election, mcan = 3, eps = 1)
summary(stv.food)
## Not run: 
view(stv.food)
## End(Not run)

# Example of the IMS Council voting
data(ims_election)
stv.ims <- stv(ims_election, mcan = 5)
## Not run: 
view(stv.ims)

# write election results into a csv file
s <- summary(stv.ims)
write.csv(s, "myfile.csv")
## End(Not run)

# Example of a small committee dataset
# with four candidates (C) and four
# voting committee members (uses tie-breaking)
votes <- data.frame(C1=c(3,2,1,3), C2=c(2,1,2,4),
                    C3=c(4,3,3,1), C4=c(1,4,4,2))
stv(votes, mcan = 2, verbose = TRUE)                    

Example output

Results of Single transferable vote
===================================                           
Number of valid votes:   20
Number of invalid votes:  0
Number of candidates:     5
Number of seats:          3


|             |         1| 2-trans|     2| 3-trans|       3| 4-trans|            4|
|:------------|---------:|-------:|-----:|-------:|-------:|-------:|------------:|
|Quota        |         6|        | 5.667|        |   5.667|        |            5|
|Oranges      |         4|       0|     4|       2|       6|  -0.333|             |
|Pears        |         2|       0|     2|      -2|        |        |             |
|Chocolate    |        12|      -6|      |        |        |        |             |
|Strawberries |         1|       4|     5|       0|       5|       0|            5|
|Sweets       |         1|       2|     3|       0|       3|       0|            3|
|Elected      | Chocolate|        |      |        | Oranges|        | Strawberries|
|Eliminated   |          |        | Pears|        |        |        |             |

Elected: Chocolate, Oranges, Strawberries 


Results of Single transferable vote
===================================                           
Number of valid votes:   20
Number of invalid votes:  0
Number of candidates:     5
Number of seats:          3


|             |         1| 2-trans|     2| 3-trans|       3| 4-trans|            4|
|:------------|---------:|-------:|-----:|-------:|-------:|-------:|------------:|
|Quota        |         6|        | 5.667|        |   5.667|        |            5|
|Oranges      |         4|       0|     4|       2|       6|  -0.333|             |
|Pears        |         2|       0|     2|      -2|        |        |             |
|Chocolate    |        12|      -6|      |        |        |        |             |
|Strawberries |         1|       4|     5|       0|       5|       0|            5|
|Sweets       |         1|       2|     3|       0|       3|       0|            3|
|Elected      | Chocolate|        |      |        | Oranges|        | Strawberries|
|Eliminated   |          |        | Pears|        |        |        |             |

Elected: Chocolate, Oranges, Strawberries 

Detected  29 invalid votes. Number of valid votes is 591 .
Use invalid.votes(...) function to view discarded records.

Results of Single transferable vote
===================================                            
Number of valid votes:   591
Number of invalid votes:  29
Number of candidates:     10
Number of seats:           5


|           |      1| 2-trans|       2| 3-trans|      3| 4-trans|      4| 5-trans|      5| 6-trans|      6| 7-trans|      7| 8-trans|       8| 9-trans|       9|
|:----------|------:|-------:|-------:|-------:|------:|-------:|------:|-------:|------:|-------:|------:|-------:|------:|-------:|-------:|-------:|-------:|
|Quota      | 98.501|        |  97.774|        | 97.438|        | 96.938|        | 95.351|        |  95.06|        | 94.684|        |  85.027|        |  83.542|
|Tilmann    |     73|   0.496|  73.496|   0.793| 74.289|   2.016| 76.305|   4.194|   80.5|   3.097| 83.597|   0.271| 83.868|  13.023|  96.891| -11.864|        |
|Julie      |     40|   1.652|  41.652|   2.137| 43.789|    6.33|  50.12|   2.347| 52.466|       6| 58.466|    3.65| 62.117| -62.117|        |        |        |
|Jasper     |    118| -19.499|        |        |       |        |       |        |       |        |       |        |       |        |        |        |        |
|Li         |    104|   4.296| 108.296| -10.523|       |        |       |        |       |        |       |        |       |        |        |        |        |
|Wang       |     20|   0.661|  20.661|   0.226| 20.887| -20.887|       |        |       |        |       |        |       |        |        |        |        |
|Hillary    |     61|   1.818|  62.818|   1.943| 64.761|       0| 64.761|   3.278| 68.039|   5.097| 73.137|   0.213|  73.35|    8.19|   81.54|   7.205|  88.745|
|Claire     |     53|   2.313|  55.313|   2.202| 57.515|   2.016| 59.531|   3.347| 62.878|   1.097| 63.975|   0.741| 64.716|  11.932|  76.648|    1.69|  78.338|
|Oscar      |     27|   0.165|  27.165|   0.194|  27.36|   1.194| 28.554|       0| 28.554| -28.554|       |        |       |        |        |        |        |
|Declan     |     22|   1.487|  23.487|   0.566| 24.053|       2| 26.053| -26.053|       |        |       |        |       |        |        |        |        |
|Roisin     |     73|   2.974|  75.974|   1.117| 77.091|    5.33| 82.422|   6.541| 88.963|  12.097| 101.06|      -6|       |        |        |        |        |
|Elected    | Jasper|        |      Li|        |       |        |       |        |       |        | Roisin|        |       |        | Tilmann|        | Hillary|
|Eliminated |       |        |        |        |   Wang|        | Declan|        |  Oscar|        |       |        |  Julie|        |        |        |        |

Elected: Jasper, Li, Roisin, Tilmann, Hillary 


Single transferable vote count
==============================
Number of votes cast is 4 

List of 1st preferences in STV counts: 

Count: 1 
  QUOTA C1 C2 C3 C4
1 1.334  1  1  1  1
Candidate C3 eliminated using forwards tie-breaking method

Count: 2 
  QUOTA C1 C2 C4
2 1.334  1  1  2
Candidate C4 elected 

Count: 3 
  QUOTA    C1    C2
3 1.334 1.333 1.333
Candidate C1 eliminated using forwards tie-breaking method

Count: 4 
  QUOTA    C2
4 1.334 2.666
Candidate C2 elected 

Results of Single transferable vote
===================================                          
Number of valid votes:   4
Number of invalid votes: 0
Number of candidates:    4
Number of seats:         2


|           |     1| 2-trans|     2| 3-trans|     3| 4-trans|     4|
|:----------|-----:|-------:|-----:|-------:|-----:|-------:|-----:|
|Quota      | 1.334|        | 1.334|        | 1.334|        | 1.334|
|C1         |     1|       0|     1|   0.333| 1.333|  -1.333|      |
|C2         |     1|       0|     1|   0.333| 1.333|   1.333| 2.666|
|C3         |     1|      -1|      |        |      |        |      |
|C4         |     1|       1|     2|  -0.666|      |        |      |
|Elected    |      |        |    C4|        |      |        |    C2|
|Eliminated |    C3|        |      |        |    C1|        |      |

Elected: C4, C2 

vote documentation built on May 2, 2019, 1:09 p.m.