Skip to content

R: lags

6 messages · Allan Clark, Anders Nielsen, ekstrom@dina.kvl.dk +3 more

#
hi all

how does one simulate a random walk process?

i.e

y(0)=0

y(t)=y(t-1)+ e(t)

where e(t) is normal(0,1)  say.

Regards
allan
#
How about:

y<-cumsum(c(0,rnorm(100)))
On Tue, 10 Feb 2004, allan clark wrote:

            
#
cumsum(c(0,rnorm(10000)))

?

Claus
#
On Tue, 10 Feb 2004, allan clark wrote:

            
e<-rnorm(100)
y<-cumsum(e)

	-thomas

Thomas Lumley			Assoc. Professor, Biostatistics
tlumley at u.washington.edu	University of Washington, Seattle
#
Dear Alan,

Perhaps there's a more clever solution, but the following will work and
follows directly from your statement of the problem (e.g., for 100
observations):

e <- rnorm(100)
y <- rep(0, 101)
for (t in 2:101) y[t] <- y[t-1] + e[t]
y <- y[-1]

I hope that this helps,
 John

On Tue, 10 Feb 2004 16:48:22 +0200
allan clark <allan at stats.uct.ac.za> wrote:
#
allan clark <allan at stats.uct.ac.za> writes:
E.g.,

c(0,cumsum(rnorm(1000)))