[R-sig-Geo] Random Movement Generator
Andy Bunn
Andy.Bunn at wwu.edu
Fri Oct 1 23:30:25 CEST 2010
> -----Original Message-----
> From: r-sig-geo-bounces at stat.math.ethz.ch [mailto:r-sig-geo-
> bounces at stat.math.ethz.ch] On Behalf Of Roberto Badilla Fuentes
> Sent: Friday, October 01, 2010 12:42 PM
> To: r-sig-geo
> Subject: [R-sig-Geo] Random Movement Generator
>
> Hi All,
>
> Is there a functionality in R that allows for the creation of random
> path or
> trajectory? Probably Brownian Motion can help but I'd like to output
> the
> data points and be able to have the points separated, say every 30
> minutes.
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)
>
>
> I also tried BM{sde}. Is there a way plot the points generated?
>
> Thanks in advance
> Roberto
>
> [[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at stat.math.ethz.ch
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
More information about the R-sig-Geo
mailing list