Skip to content

simm.levy in adehabitat

2 messages · Tim Sippel, Clément Calenge

#
Hi Tim,
First note that the "burst" and "id" are stored as attributes of each 
element of the list of class ltraj, and not as elements of the list 
themselves. It means that p.sett$burst and p.sett$id do not exist. To 
get the burst or the id of the trajectories of the list, you can simply type

burst(p.sett)
id(p.sett)

See the help page of as.ltraj() for trajectory management with 
adehabitat. Now, it seems that you want to simulate a levy walk at the 
same times as your actual trajectory, beginning at the same point. In 
this case, you should use the following code:

res <- lapply(1:length(p.sett), function(i) {   
           simm.levy(date = p.sett[[i]]$date, id = id(p.sett)[i],
                            x0 = c(p.sett[[i]]$x[1], p.sett[[i]]$y[1]),
                            burst = burst(p.sett)[i], typeII = T, mu=2)
})
result <- do.call("c", res)
plot(result)

But note that you may have to change the parameter mu, depending on what 
you want to do. See the help page of simm.levy.
BTW, there is a bug in the function concerning the parameter x0. If you 
want to use parameter x0 (required only if you want to match the 
trajectory with maps), you should use the following fixed function, 
which will be included in the next version of adehabitat:

simm.levy <- function (date = 1:500, mu = 2, l0 = 1, x0 = c(0, 0), id = 
"A1",
    burst = id, typeII = TRUE)
{
    if (typeII)
        class(date) <- c("POSIX", "POSIXct")
    n <- length(date)
    dt <- c(diff(unclass(date)))
    if (all(dt - dt[1] > 1e-07))
        stop("the time lag between relocations should be constant")
    ang <- runif(n - 2, -pi, pi)
    v = dt * (l0 * (runif(n - 1)^(1/(1 - mu))))
    ang = cumsum(c(runif(1, 0, 2 * pi), ang))
    si = c(x0[2], x0[2]+cumsum(v * sin(ang)))
    co = c(x0[1], x0[1]+cumsum(v * cos(ang)))
    res <- as.ltraj(data.frame(co, si), date, id, burst, typeII = typeII)
    return(res)
}


Hope this helps,


Cl?ment.