# RUSSIAN ROULETTE # (changeable parameters) n.bullets=1; n.chambers=6; n.occasions=7; # theoretically.. prob.survive.n.occasions = (1-n.bullets/n.chambers)^n.occasions; prob.survive.n.occasions # by simulation.. 100 persons [0=survived, 1=dead] n.persons = 100; lifeline=matrix(rep("",n.persons),nrow=n.persons); outcome=c("L","D"); for (person in 1:n.persons) { alive=1; for (occasion in 1:n.occasions) { if (alive==1) { result=rbinom(1,1,1/n.bullets/n.chambers); lifeline[person,1]=paste( lifeline[person,1],outcome[result+1] ); alive=(result==0) } } } lifeline; # sorted, so can count more easily.. lifeline=matrix( c(sort(lifeline),seq(n.persons,1,-1)) ,nrow=n.persons); lifeline; # (repeat for another random set of individuals) ###### # CUMULATIVE INCIDENCE OF BLADDER CANCER (miettinen paper -- cf example 31 / 31 ) id=c(8,27,110,60,90,150)/100000; id prob.avoid.for.next.5years=(1-id/365)^(365*5) ; prob.avoid.for.next.5years # product of these 6 conditional proabilities prob.avoid.for.next.30.years = prod(prob.avoid.for.next.5years); prob.avoid.for.next.30.years # cumulative incidence # proportion.. 1 - prob.avoid.for.next.30.years # percent.. 100*(1 - prob.avoid.for.next.30.years) # try using smaller or larger subunits ... eg hours, so 365*24*5 hours