**long time ago...**, and kindly contributed to R-bloggers)

*eMotion*function in order implement this kind of movement models:

*from*

**eWalk**(*evolutiveWalk…*).

*eWalk*is similar to other movement-simulation functions in

*adehabitatLT*package (Calenge, 2006). However, you can use

*eWalk*to simulate a variety of processes as Brownian motion, OU processes or Lèvy flights (see below).

` `

eWalk <- function(sigma,lon,lat, generations,alpha_x,theta_x,alpha_y,theta_y, color,levy=FALSE, plot=TRUE) {

route=data.frame(1:generations,1:generations) # a data.frame to store the route

names(route)<-c("lon","lat")

generation= generations # generation counter

while (generation > 0){ # stops the simulation when generation counter is 0

if (levy == TRUE){ # only if levy=TRUE: Levy Flight!

rndm=abs(rcauchy(1)) # process to select if I should jump or not

if (rndm > 15){ # Levy jump probability threshold

l=15 # length of the jump

x= lon + (l * (sigma * rnorm(1))) + (alpha_x * ( theta_x - lon)) # Brownian or OU process for longitude

y= lat + (l * (sigma * rnorm(1))) + (alpha_y * ( theta_y - lat)) # Brownian or OU process for latitude

loc=cbind(x,y)

route[generation,]<- loc # store new location

generation= generation - 1 # advance to next generation

lon<- x # go to the new position!

lat<- y

}

else{ # if Levy jump is not selected, l=1 i.e. proceed with

l=1 #normal Brownian motion or OU process

x= lon + (l * (sigma * rnorm(1))) + (alpha_x * ( theta_x - lon))

y= lat + (l * (sigma * rnorm(1))) + (alpha_y * ( theta_y - lat))

loc=cbind(x,y)

route[generation,]<- loc

generation= generation - 1

lon<- x

lat<- y

}

}

else{ # if levy=FALSE, l=1, only Brownian motion or OU

l=1

x= lon + (l * (sigma * rnorm(1))) + (alpha_x * ( theta_x - lon))

y= lat + (l * (sigma * rnorm(1))) + (alpha_y * ( theta_y - lat))

loc=cbind(x,y)

route[generation,]<- loc

generation= generation - 1

lon<- x

lat<- y

}

}

if (plot == TRUE) { # if plot=TRUE, plto the route!

lines(route, col= color, lwd=3)

}

return(route) # print the data.frame with each location during the walk!

}

>

*eMotion*, but taking into account that now you have two variables (latitude/longitude, for example) at the same time.

In addition, I have added a complement to simulate Lèvy flights, a non-gaussian process similar to Brownian motion but allowing for jumps during the motion. Lévy flights pattern has been found in searchingmovements of predators (Bartumeus et al., 2005), or have been used to simulatepunctuated equilibrium in traitsevolution (Gould and Eldredge, 1977; Landis et al., 2013). To perform Lèvy flight, eWalk selects a random number from Cauchy distribution and if it is higher than a threshold (15 by default), Brownian motion term is multiplied by a constant representing a jump (also 15 by default). Although this is not the formal expression of a Lèvy process, this is a simple way to simulate a negative exponential rate in for the length of each step.

` `

par(mfrow=c(2,2))

a=eWalk(0.15,0,0,1000, 0, 0, 0, 0, color="blue", levy=FALSE, plot=FALSE)

plot(a,type="n", main="Brownian motion")

lines(a,lwd=3, col="blue")

points(a, cex=.3, col="black", pch=21)

a=eWalk(0.15,0,0,1000, 0, 0, 0, 0, color="red", levy=TRUE, plot=FALSE)

plot(a,type="n", main="Lêvy flight")

lines(a,lwd=3, col="red")

points(a, cex=.3, col="black", pch=21)

a=eWalk(0.15,0,0,1000, 0.01, 20, 0, 0, color="orange", levy=FALSE, plot=FALSE)

plot(a,type="n", main="OU one optimum")

lines(a,lwd=3, col="orange")

abline(v=20, col="red", lwd="2")

points(a, cex=.3, col="black", pch=21)

a=eWalk(0.15,0,0,1000, 0.01, 20, 0.01, 20, color="green", levy=FALSE, plot=FALSE)

plot(a,type="n", main="OU two optimum")

lines(a,lwd=3, col="green")

points(a, cex=.3, col="black", pch=21)

abline(v=20, col="red", lwd="2")

abline(h=20, col="red", lwd="2")

**References**

*Ecology*,

*86*(11), 3078-3087.

*Ecological modelling*,

*197*(3), 516-519.

*Paleobiology*,

*3*(02), 115-151.

*Systematic biology*,

*62*(2), 193-204.

**leave a comment**for the author, please follow the link and comment on their blog:

**long time ago...**.

R-bloggers.com offers

**daily e-mail updates**about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...