Pages

Thursday, December 10, 2015

Random Walk in R

M = 150
N = 360

m = matrix(0,nrow=M,ncol=N)
m1 = apply(m, c(1,2), function(x) rnorm(1)) #runif, rnorm
m2 = apply(m1, 1, cumsum)
m2 = t(m2)

hist(m2[,N], 30)

a = mean(m2[,N])
s = sd(m2[,N])^2

sd2 = apply(m2, 1, sd)
matplot(t(m2), type="l")



No comments:

Post a Comment