What value do you want d to take on if it is outside that interval? Here is an example where if d is outside the interval, it is assigned to be one of the interval endpoints. minx <- 0 for(i in 2:T) { x <- alpha * d[i-1] + e[i] maxx <- a*(T-i) if(x < minx) { d[i] <- minx } else { if(x > maxx) { d[i] <- maxx } else d[i] <- x } }
Jean On Thu, Dec 5, 2013 at 10:19 PM, gncl dzgn <guncelduz...@hotmail.com> wrote: > Hello everyone, > > I'm trying to generate a sequence that consists of random numbers and the > following algorithm works well > > ### > > a <- 0.08 > b <- 0.01 > T <- 90 > t <- 0:T > alpha <- 1 > e <- rnorm(T, mean = 0, sd = 0.1) > d <- c( runif(1,0, a*T), rep(0, T-1) ) > for (i in 2:T) > { > d[i] <- alpha * d[i-1] + e[i] > } > plot(d, type="l") > > ## > > But I have to add this restriction " each d on > day t must satisfy to belong to the time-dependent interval [0, a*(T-t)] > ". For > example, d on day 50 can be minimal 0 and maximal a*40. > > I hope, somebody helps me. > > Best regards > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.