search for: stochastic_prost

Displaying 1 result from an estimated 1 matches for "stochastic_prost".

2009 Nov 16
2
Conditional statement
...wrote a function that simulates a stochastic model in discrete time. The problem is that the stochastic parameters should not be negative and sometimes they happen to be. How can I conditionate it to when it draws a negative number, it transforms into zero in that time step? Here is the function: stochastic_prost <- function(Fmean, Fsd, Smean, Ssd, f, s, n, time, out=FALSE, plot=TRUE) { nt <- rep(0, time) nt[1] <- n for(n in 2:time) { nt[n] <- 0.5*rnorm(1, Fmean, Fsd)*rnorm(1, Smean, Ssd)*exp(1)^(-(f+s)*nt[n-1])*nt[n-1]} if(out==TRUE) {print(data.frame(nt))} if(plot==TRUE) {plot(1:time, nt, type...