Using R: How to repeat a function I made thousands of times keeping a count of which number it ends on for each repeat -


here's code made far:

z = vector() for(i in 1:20){   alkie = function(t=20, lambda=2.5, k=2, mu=3) {     t = 0     n = 0     = 1     a.t = rexp(1, lambda)     d.t = inf     while(t[i] < t) {       t[i+1] = min(a.t, d.t)       n[i+1] = n[i] + ifelse(a.t < d.t, 1, -1)       if(a.t < d.t) {         a.t = a.t + rexp(1,lambda)         if(n[i+1] == 1) d.t = t[i+1] + rgamma(1, k, mu)         if(n[i+1] == 6) d.t = t[i+1] + rgamma(1, 0, mu)       }       else         d.t = ifelse(n[i+1] == 0, inf, t[i+1] + rgamma(1, k, mu))       = + 1     }     cbind(t=t, n=n)   }  x = alkie(t=20, lambda=2.5, k=2, mu=3) n = nrow(x) plot(c(x[1,1], rep(x[-1,1], each=2), x[n,1]), rep(x[,2], each=2), type="l",  xlab="t(mins)", ylab="n(t)", col="blue") 

how store counts?


Comments

Popular posts from this blog

javascript - Bootstrap Popover: iOS Safari strange behaviour -

Website Login Issue developed in magento -

Can the constants be defined inside a model file of a framework in PHP? -