Skip to content

Random Movement Generator

5 messages · Roberto Badilla Fuentes, Andy Bunn, Michael Sumner +1 more

#
I've used like this before in class to teach about random walks. Maybe this will get you going? HTH, Andy

require(sp)
xinit <- 0
yinit <- 0
d2move <- 1
nsteps <- 99
x <- c(xinit,rep(NA,nsteps))
y <- c(yinit,rep(NA,nsteps))
for(i in 2:(nsteps+1)){
  theta <- runif(1,pi/180,360*pi/180) 
  xi <- d2move * cos(theta)
  yi <- d2move * sin(theta)
  x[i] <- x[i-1] + xi
  y[i] <- y[i-1] + yi
}
plot(x,y,type='b')
xy <- SpatialPoints(cbind(x,y))
str(xy)
#
Hi Roberto,

Did you have a look at the package adehabitat, and especially the simm.* 
functions (Brownian bridge motion, Bivariate Brownian Motion, Correlated 
Random Walk, Levy Walk, Arithmetic Brownian Motion, Bivariate 
Ornstein-Uhlenbeck Process)? This might be particularly helpful.

Hope this helps,
Mathieu.


Le 01/10/2010 15:42, Roberto Badilla Fuentes a ?crit :