Voter Transition Rates - Instructions

We suppose that the election results are known for a district and the precincts from which the district is consisted off.Suppose that political parties 1, 2, …,r run for the fist election, (e1) and collected f=(f1,f2, … ,fr ) of the votes correspondingly and parties 1, 2,…,c run for the second election (e2) and collected s=(s1,s2, … ,sc ) of the votes correspondingly. In Table 1 the basic notation of the problem is presented. In this table f1,f2,… ,fr and s1,s2, … ,sc are known and we wish to estimate the values of pij for i=1,2, …,r and j=1, 2, …,c where pij is the voter transition rate from political party i to political party j. For the scope of this paper, the phrase voter transition rate should include both defection rates from one party to another part and loyalty rates, i.e. the voter transition rate from political party i to political party j is the loyalty rate if party i of the first election is the same with party j of the second election. We should also note that fi, sj may be available as absolute or relative values. In case they are available as absolute values we can transform them to their corresponding relative values.The rest of this paper will consider fi, sj as relative values so that

Table 1 Notation for voter transition rates for the district

s1 s2 sc
f1 p11 p12 p1c
f2 p21 p22 p2c
fr pr1 pr2 prc

In addition, if the district consists of mprecincts we wish to estimate the values of pijk for i=1,2, …,r, j=1, 2, …, c k=1, 2, …, m where pijk is the voter transition rate from political party i to political party j in precinct k . The notation for precinct k is presented inTable 2 where fik is the fraction of people who voted for party i in the first election in precinct k andsjk is the fraction of people who voted for partyj in the second election in precinct k.

Table 2 Notation for voter transitionrates for precinctk

s1k

s2k

sck

f1k

p11k

p12k

p1ck

f2k

p21k

p22k

p2ck

frk

pr1k

pr2k

prck

Download file VTR.R and save it to your working directory.

To run the program you will need two matrices X,T and one vector N. We denote X the rxm matrix that consists of the elements fik i.e. the relative power of party i in precinct k in e1.T is the cxm matrix that consists of the elements sjk i.e. the relative power of party j in precinct k in e2. Vector N=(n1,n2,…,nm) consists of the number of voters in each precinct.

If you are not familiar with R the best approach is to prepare your data in a CSV file (CSV files can be prepared with Microsoft Excel using the "Save as" command and selecting the CSV file type) Save the CSV file in your working directory (the same directory you have used to store the file VTR.R) As an example, you can download the file br9701.csv which includes constituency results for the 1997 and 2001 general elections(England, Scotland, and Wales)

1. Start R

2. File - changedir and select your working directory

3. File - source Rcode (VTR.R)

4 . Type the following commands

mydata <- read.csv2("br9701.csv")

With this command you read your data into R read.csv and read.csv2 are almost identical. They are intended for reading “comma separated value” files (‘ .csv ’). The variant (read.csv2) is used in countries that use a comma as decimal point and a semicolon as field separator. If you use comma as field separator you should use read.csv instead of read.csv2 and write.csv instead of write.csv2 (see below).

myN<-mydata[1]

myT<-mydata[2:11]

myX<-mydata[12:19]

With these commands you define the initial N as the first column of your data, T as the table stored in columns 2-11 and X as the table stored in columns from 12-19. Of course if your file is structured in a different way you should adjust for it by changing the corresponding columns.

5.Now you are ready to run the code and store the results to an R object, i.e. z

z<-multirate(myN,myX,myT,0.01)

The arithmetic parameter defines the fraction of the populations that will remain unexplained. In practice, typical fraction values we could use are the values 0.05, 0.01. These values mean that the method would estimate 95% and 99% of the voter transitions correspondingly. In case we need more accurate estimates we could use smaller values i.e. 0.001 but this would require longer time for the execution of the code.

After the execution of the code we can print the general voter transition matrix withthe command:

z$Bb

or we can save the matrix to a CSV file with the command (or write.csv)

write.csv2(z$Bb, file="brVTR.csv")

We can print the whole array of constituency voter transitions with the command

z$bb

It is more useful to print constituency voter transition rates for a pair ofparties with the commands

as.matrix(z$bb[,"CON97","CON01"])

(using the column names)

as.matrix(z$bb[,2,2])

(using the column numbers)

or we can save them to a CSV file with the command (or write.csv)

write.csv2(as.matrix(z$bb[,"CON97","CON01"]),file="CON9701.csv", row.names=F)

If you use the algorithm, please cite with the following text:

Andreadis, I. and Chadjipadelis, T. (2009). A method for the estimation of voter transition rates. Journal of Elections, Public Opinion and Parties 19(2):203-218 http://doi.org/10.1080/17457280902799089