[R] Generate arrival of time based on uniform random number

smart hendsome putra_autumn86 at yahoo.com
Thu Feb 4 05:08:06 CET 2016


Hi everyone,
I have problem regarding to generate arrival of time based on uniform random number.
Let day0 = 0.383, lambda = 0.2612

1) Generate uniform random number (already settled) using the code below:
set.seed(1234)
rand.no <- function(n,itr){
  matrix(runif(n*itr, 0, 1), nrow=n, ncol=itr)
} 
x<-rand.no(10,1)
2) For day 1,
   a) if 1st rand.no < day0, then its not rain,  else its rain (i want the rseult in next colum, let say rain)
3) For day 2 and so on ( it depend from next rain when it happened)
4) Next rain,
   to know the next rain i need i need to calculate using the exponential 

  a) 1st rain = - ln (1st rand.no) / lambda
  b) 2nd nextRain = 1st rain - ln (2nd rand.no) / lambda
  c) 3rd nextRain = 2nd next rain - ln (3rd rand.no)/lambda,  and so on
 eg: if nextRain = 2.435, then 2nd day will rain


Hope anyone can help me solve this problems. Thanks so much.
      


  



	[[alternative HTML version deleted]]



More information about the R-help mailing list