Advertisement
NadaBupkis

mortality ex

Nov 7th, 2014
301
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
R 0.59 KB | None | 0 0
  1. N <- 250
  2. # this i value will represent the grim reaper. If it comes up, adios compadre
  3. i <- round(runif(1,1,N))
  4. j <- 0
  5. mort = vector("numeric") # make a length 0 vector to store results
  6. p <- 6
  7.  
  8. for(l in 1:3000) {
  9.     while(p > 3) {
  10.         j <- j + 1
  11.         y <- sample.int(N,p,replace=TRUE) # roll the grim reaper die
  12.         y <- y[y==i]
  13.         p = p + length(y)*(-1)            # take his due
  14.  
  15.         if(p <= 3) {
  16.             mort <- append(mort,j)
  17.             j <- 0
  18.             p <- 6
  19.             break
  20.         }
  21.     }
  22. }
  23. m <- median(mort)
  24. cat("median value: ",m,"\n")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement