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, (e_{1}) and collected f=(f_{1},f_{2}, … ,f_{r} ) of the votes correspondingly and parties 1, 2,…,c run for the second election (e_{2}) and collected s=(s_{1},s_{2}, … ,s_{c} ) of the votes correspondingly. In Table 1 the basic notation of the problem is presented. In this table f_{1},f_{2},… ,f_{r} and s_{1},s_{2}, … ,s_{c }are known and we wish to estimate the values of p_{ij} for i=1,2, …,r and j=1, 2, …,c where p_{ij} 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 f_{i}, s_{j} 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 f_{i}, s_{j} as relative values so that
Table 1 Notation for voter transition rates for the district
s_{1}  s_{2}  …  s_{c}  
f_{1}  p_{11}  p_{12}  …  p_{1c} 
f_{2}  p_{21}  p_{22}  …  p_{2c} 
…  …  …  …  … 
f_{r}  p_{r}_{1}  p_{r}_{2}  …  p_{rc} 
In addition, if the district consists of mprecincts we wish to estimate the values of p_{ijk} for i=1,2, …,r, j=1, 2, …, c k=1, 2, …, m where p_{ijk }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 f_{ik} is the fraction of people who voted for party i in the first election in precinct k ands_{jk} is the fraction of people who voted for partyj in the second election in precinct k.
Table 2 Notation for voter transitionrates for precinctk
s_{1k} 
s_{2k} 
… 
s_{ck} 

f_{1k} 
p_{11k} 
p_{12k} 
… 
p_{1ck} 
f_{2k} 
p_{21k} 
p_{22k} 
… 
p_{2ck} 
… 
… 
… 
… 
… 
f_{rk} 
p_{r}_{1k} 
p_{r}_{2k} 
… 
p_{rck} 
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 f_{ik} i.e. the relative power of party i in precinct k in e_{1}.T is the cxm matrix that consists of the elements s_{jk} i.e. the relative power of party j in precinct k in e_{2}. Vector N=(n_{1},n_{2},…,n_{m}) 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 211 and X as the table stored in columns from 1219. 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):203218 http://doi.org/10.1080/17457280902799089