[R] [FORGED] simulate AR1 process with uniform distribution and different y0 values
r.turner at auckland.ac.nz
Sun Oct 9 01:44:04 CEST 2016
On 09/10/16 09:42, Ashwini Patil wrote:
> I need to plot an ar1 graph for process yk=0.75y (k-1) + ek, for y0=1 and
> another graph for y0=10.
> assume ek is uniformly distributed on interval [-0.5,0.5].
> i have the following code but i am not sure how to control y0.
> y<-arima.sim(model=list(ar=.75), n=100, innov = runif(100, 0, 1))
I don't understand the last three lines; shouldn't "innov" be equal to
runif(100, -0.5, 0.5), and subtracting 0.5 be skipped?
I think that the following does what you want:
Or you could simply do:
e <- runif(100,-0.5,0.5)
yy <- numeric(101)
yy <- 10
for(i in 1:100) yy[i+1] <- 0.75*yy[i] + e[i]
yy <- as.ts(yy[-1])
(Or you could apply filter() to c(10,e) with method="recursive".)
P.S. I am not convinced that what you want to do makes much sense, but
the foregoing shows how to do it if you must.
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276
More information about the R-help