rm(list = ls(all = TRUE)) Con <- 28 Lab <- 33 LD <- 14 UKIP <- 14 Green <- 5 Other <- 6 SD <- 3/1.96 count.trial <- 0 Con.Vic <- 0 Lab.Vic <- 0 while(count.trial<10000){ m.o.e <- abs(rnorm(1,0,SD)) if(runif(1)> 0.5){Con.Act<-Con+m.o.e}else{Con.Act<-Con-m.o.e} if(runif(1)> 0.5){Lab.Act<-Lab+m.o.e}else{Lab.Act<-Lab-m.o.e} if(runif(1)> 0.5){LD.Act<-LD+m.o.e}else{LD.Act <-LD-m.o.e} if(runif(1)> 0.5){UKIP.Act<-UKIP+m.o.e}else{UKIP.Act<-UKIP-m.o.e} if(runif(1)> 0.5){Green.Act<-Green+m.o.e}else{Green.Act<-Green-m.o.e} if(runif(1)> 0.5){Other.Act<-Other+m.o.e}else{Other.Act<-Other-m.o.e} if(Con.Act+Lab.Act+LD.Act+UKIP.Act+Green.Act+Other.Act == 100){ count.trial <- count.trial + 1 if(Con.Act > Lab.Act){ Con.Vic <- Con.Vic + 1 } if(Lab.Act > Con.Act){ Lab.Vic <- Lab.Vic + 1 } } }