Compute the distance between the trajectories of two animals with varying sampling intervals

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Compute the distance between the trajectories of two animals with varying sampling intervals

André Zehnder
Hi list,

 

I want to compute the distances between two trajectories that consist of a
sequence of point measurements. The trajectories do not have the same length
or sampling interval. So, while for animal A, there is a data point at 15.00
p.m. and another at 15.38 p.m, animal B might have data points at 14.56 p.m.

and 17.02 p.m.

 

A possible approach would be to connect these point series to trajectories
and then calculate the distance between the two trajectories at the sampled
positions of one trajectory (take the sampled position of the second
trajectory that is temporally closest). Are there any packages in R (or
tools outside of R) that allow me to do this? The support of other distances
than the Euclidean one (e.g. Fr chet) would be an advantage.

 

Best regards,

Andre

 


        [[alternative HTML version deleted]]

_______________________________________________
R-sig-ecology mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-ecology
Reply | Threaded
Open this post in threaded view
|

Re: Compute the distance between the trajectories of two animals with varying sampling intervals

Sarah Goslee
Try the adehabitatLT package.

On Wed, Jul 22, 2015 at 9:41 AM, André Zehnder <[hidden email]> wrote:

> Hi list,
>
>
>
> I want to compute the distances between two trajectories that consist of a
> sequence of point measurements. The trajectories do not have the same length
> or sampling interval. So, while for animal A, there is a data point at 15.00
> p.m. and another at 15.38 p.m, animal B might have data points at 14.56 p.m.
>
> and 17.02 p.m.
>
>
>
> A possible approach would be to connect these point series to trajectories
> and then calculate the distance between the two trajectories at the sampled
> positions of one trajectory (take the sampled position of the second
> trajectory that is temporally closest). Are there any packages in R (or
> tools outside of R) that allow me to do this? The support of other distances
> than the Euclidean one (e.g. Fr chet) would be an advantage.
>
>
>
> Best regards,
>
> Andre
>
>
--
Sarah Goslee
http://www.functionaldiversity.org

_______________________________________________
R-sig-ecology mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-ecology
Reply | Threaded
Open this post in threaded view
|

Re: Compute the distance between the trajectories of two animals with varying sampling intervals

Jeremy Chacon
I bet Sarah's right and adehabitatLT has something, but I also know that
the longitudinalData package can compute distances between two trajectories
including the frechet distance.

http://www.inside-r.org/packages/cran/longitudinalData/docs/pathFrechet

However, it does not deal with the timing problem. You will have to roll
your own method of aligning the trajectories in time.

On Wed, Jul 22, 2015 at 9:02 AM, Sarah Goslee <[hidden email]>
wrote:

> Try the adehabitatLT package.
>
> On Wed, Jul 22, 2015 at 9:41 AM, André Zehnder <[hidden email]>
> wrote:
> > Hi list,
> >
> >
> >
> > I want to compute the distances between two trajectories that consist of
> a
> > sequence of point measurements. The trajectories do not have the same
> length
> > or sampling interval. So, while for animal A, there is a data point at
> 15.00
> > p.m. and another at 15.38 p.m, animal B might have data points at 14.56
> p.m.
> >
> > and 17.02 p.m.
> >
> >
> >
> > A possible approach would be to connect these point series to
> trajectories
> > and then calculate the distance between the two trajectories at the
> sampled
> > positions of one trajectory (take the sampled position of the second
> > trajectory that is temporally closest). Are there any packages in R (or
> > tools outside of R) that allow me to do this? The support of other
> distances
> > than the Euclidean one (e.g. Fr chet) would be an advantage.
> >
> >
> >
> > Best regards,
> >
> > Andre
> >
> >
> --
> Sarah Goslee
> http://www.functionaldiversity.org
>
> _______________________________________________
> R-sig-ecology mailing list
> [hidden email]
> https://stat.ethz.ch/mailman/listinfo/r-sig-ecology
>



--

*___________________________________________________________________________Jeremy
M. Chacon, Ph.D.*

*Post-Doctoral Associate, Harcombe Lab*
*University of Minnesota*
*Ecology, Evolution and Behavior*

        [[alternative HTML version deleted]]

_______________________________________________
R-sig-ecology mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-ecology
Reply | Threaded
Open this post in threaded view
|

Re: Compute the distance between the trajectories of two animals with varying sampling intervals

Li Wen
In reply to this post by Sarah Goslee
You may have to make the two trajectories regular with the same interval.  Package adehabitatLT has functions to do this.

Cheers
Li
________________________________________
From: R-sig-ecology [[hidden email]] on behalf of Sarah Goslee [[hidden email]]
Sent: Thursday, 23 July 2015 12:02 AM
To: André Zehnder
Cc: [hidden email]
Subject: Re: [R-sig-eco] Compute the distance between the trajectories of two animals with varying sampling intervals

Try the adehabitatLT package.

On Wed, Jul 22, 2015 at 9:41 AM, André Zehnder <[hidden email]> wrote:

> Hi list,
>
>
>
> I want to compute the distances between two trajectories that consist of a
> sequence of point measurements. The trajectories do not have the same length
> or sampling interval. So, while for animal A, there is a data point at 15.00
> p.m. and another at 15.38 p.m, animal B might have data points at 14.56 p.m.
>
> and 17.02 p.m.
>
>
>
> A possible approach would be to connect these point series to trajectories
> and then calculate the distance between the two trajectories at the sampled
> positions of one trajectory (take the sampled position of the second
> trajectory that is temporally closest). Are there any packages in R (or
> tools outside of R) that allow me to do this? The support of other distances
> than the Euclidean one (e.g. Fr chet) would be an advantage.
>
>
>
> Best regards,
>
> Andre
>
>
--
Sarah Goslee
http://www.functionaldiversity.org

_______________________________________________
R-sig-ecology mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-ecology
----------------------------------------------------------------------------------------------------------------------------------------------------------------------
This email is intended for the addressee(s) named and may contain confidential and/or privileged information.
If you are not the intended recipient, please notify the sender and then delete it immediately.
Any views expressed in this email are those of the individual sender except where the sender expressly and with authority states them to be the views of the NSW Office of Environment and Heritage.

PLEASE CONSIDER THE ENVIRONMENT BEFORE PRINTING THIS EMAIL

_______________________________________________
R-sig-ecology mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-ecology
Reply | Threaded
Open this post in threaded view
|

Re: Compute the distance between the trajectories of two animals with varying sampling intervals

Mathieu Basille-3
In reply to this post by Jeremy Chacon
As far as I can tell, there is no such function in adehabitatLT. However, I
wrote a function 'closest' [1] in the package 'hab' [2], which specifically
does that: find the closest relocations from ltraj objects. It can work
with only one ltraj, in which case it will look in other bursts, or with
two different ltraj, in which case it will in the other ltraj. Most
importantly, you can define a temporal windows to restrict the search,
which may solve your problem of irregular time (the ltraj do not have to be
regular, or on the same time schedule). It's only Euclidean distance
though. Lastly, it works at the location level, i.e. it's not considering
lines (steps). If that's what you're looking for, I would probably suggest
using PostGIS...

Hope this helps,
Mathieu.


[1] https://github.com/basille/hab/blob/master/R/closest.r

[2] https://github.com/basille/hab


Le 22/07/2015 10:09, Jeremy Chacon a écrit :

> I bet Sarah's right and adehabitatLT has something, but I also know that
> the longitudinalData package can compute distances between two trajectories
> including the frechet distance.
>
> http://www.inside-r.org/packages/cran/longitudinalData/docs/pathFrechet
>
> However, it does not deal with the timing problem. You will have to roll
> your own method of aligning the trajectories in time.
>
> On Wed, Jul 22, 2015 at 9:02 AM, Sarah Goslee <[hidden email]>
> wrote:
>
>> Try the adehabitatLT package.
>>
>> On Wed, Jul 22, 2015 at 9:41 AM, André Zehnder <[hidden email]>
>> wrote:
>>> Hi list,
>>>
>>>
>>>
>>> I want to compute the distances between two trajectories that consist of
>> a
>>> sequence of point measurements. The trajectories do not have the same
>> length
>>> or sampling interval. So, while for animal A, there is a data point at
>> 15.00
>>> p.m. and another at 15.38 p.m, animal B might have data points at 14.56
>> p.m.
>>>
>>> and 17.02 p.m.
>>>
>>>
>>>
>>> A possible approach would be to connect these point series to
>> trajectories
>>> and then calculate the distance between the two trajectories at the
>> sampled
>>> positions of one trajectory (take the sampled position of the second
>>> trajectory that is temporally closest). Are there any packages in R (or
>>> tools outside of R) that allow me to do this? The support of other
>> distances
>>> than the Euclidean one (e.g. Fr chet) would be an advantage.
>>>
>>>
>>>
>>> Best regards,
>>>
>>> Andre
>>>
>>>
>> --
>> Sarah Goslee
>> http://www.functionaldiversity.org
>>
>> _______________________________________________
>> R-sig-ecology mailing list
>> [hidden email]
>> https://stat.ethz.ch/mailman/listinfo/r-sig-ecology
>>
>
>
>

--

~$ whoami
Mathieu Basille
http://ase-research.org/basille

~$ locate --details
University of Florida \\
Fort Lauderdale Research and Education Center
(+1) 954-577-6314

~$ fortune
« Le tout est de tout dire, et je manque de mots
Et je manque de temps, et je manque d'audace. »
  -- Paul Éluard

_______________________________________________
R-sig-ecology mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-ecology
Reply | Threaded
Open this post in threaded view
|

Re: Compute the distance between the trajectories of two animals with varying sampling intervals

André Zehnder
Thank you for all your answers!

@ Krzysztof: Yes, I think an approximated method that uses only the nearest points to compute the distance will suffice. When I include a threshold that ensures that only temporal differences smaller than xy minutes are taken into consideration, reasonable results should be achievable.

@ Sarah: I think you are referring to the simulation of a Brownian motion by the function simm.bb()  for an exact solution? I could not find a function that directly computes the distances. Or did I miss something?

@ Jeremy: Thanks for the hint! A also stumbled upon the pathFrechet() / distFrechet() function of longitudinalData but rejected them because they seem not to include the temporal dimension. However, this seems to be only an erroneous information of inside-r. When I looked at the official reference manual I saw that distFrechet() considers the time as well.

@ Mathieu: That is pretty much what I am intending to do for a first (and possibly also final) try, thanks! So I need to input the ltray-object of the first individual  as 'from' and the other one as 'to' in order to check the distances between their closest points, right? I also tried to program something like that but the result is shockingly time inefficient and might still contain some errors. So I will probably try out your function tomorrow :)

Best regards
Andre



-----Ursprüngliche Nachricht-----
Von: Mathieu Basille [mailto:[hidden email]]
Gesendet: Mittwoch, 22. Juli 2015 19:44
An: André Zehnder; R-sig-eco
Cc: Jeremy Chacon; Sarah Goslee
Betreff: Re: [R-sig-eco] Compute the distance between the trajectories of two animals with varying sampling intervals

As far as I can tell, there is no such function in adehabitatLT. However, I wrote a function 'closest' [1] in the package 'hab' [2], which specifically does that: find the closest relocations from ltraj objects. It can work with only one ltraj, in which case it will look in other bursts, or with two different ltraj, in which case it will in the other ltraj. Most importantly, you can define a temporal windows to restrict the search, which may solve your problem of irregular time (the ltraj do not have to be regular, or on the same time schedule). It's only Euclidean distance though. Lastly, it works at the location level, i.e. it's not considering lines (steps). If that's what you're looking for, I would probably suggest using PostGIS...

Hope this helps,
Mathieu.


[1] https://github.com/basille/hab/blob/master/R/closest.r

[2] https://github.com/basille/hab


Le 22/07/2015 10:09, Jeremy Chacon a écrit :

> I bet Sarah's right and adehabitatLT has something, but I also know
> that the longitudinalData package can compute distances between two
> trajectories including the frechet distance.
>
> http://www.inside-r.org/packages/cran/longitudinalData/docs/pathFreche
> t
>
> However, it does not deal with the timing problem. You will have to
> roll your own method of aligning the trajectories in time.
>
> On Wed, Jul 22, 2015 at 9:02 AM, Sarah Goslee <[hidden email]>
> wrote:
>
>> Try the adehabitatLT package.
>>
>> On Wed, Jul 22, 2015 at 9:41 AM, André Zehnder
>> <[hidden email]>
>> wrote:
>>> Hi list,
>>>
>>>
>>>
>>> I want to compute the distances between two trajectories that
>>> consist of
>> a
>>> sequence of point measurements. The trajectories do not have the
>>> same
>> length
>>> or sampling interval. So, while for animal A, there is a data point
>>> at
>> 15.00
>>> p.m. and another at 15.38 p.m, animal B might have data points at
>>> 14.56
>> p.m.
>>>
>>> and 17.02 p.m.
>>>
>>>
>>>
>>> A possible approach would be to connect these point series to
>> trajectories
>>> and then calculate the distance between the two trajectories at the
>> sampled
>>> positions of one trajectory (take the sampled position of the second
>>> trajectory that is temporally closest). Are there any packages in R
>>> (or tools outside of R) that allow me to do this? The support of
>>> other
>> distances
>>> than the Euclidean one (e.g. Fr chet) would be an advantage.
>>>
>>>
>>>
>>> Best regards,
>>>
>>> Andre
>>>
>>>
>> --
>> Sarah Goslee
>> http://www.functionaldiversity.org
>>
>> _______________________________________________
>> R-sig-ecology mailing list
>> [hidden email]
>> https://stat.ethz.ch/mailman/listinfo/r-sig-ecology
>>
>
>
>

--

~$ whoami
Mathieu Basille
http://ase-research.org/basille

~$ locate --details
University of Florida \\
Fort Lauderdale Research and Education Center
(+1) 954-577-6314

~$ fortune
« Le tout est de tout dire, et je manque de mots Et je manque de temps, et je manque d'audace. »
  -- Paul Éluard

_______________________________________________
R-sig-ecology mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-ecology
Reply | Threaded
Open this post in threaded view
|

Re: Compute the distance between the trajectories of two animals with varying sampling intervals

Mathieu Basille-3
Hi André,

Yes, that's one way to do it. If you already have a single ltraj with all
individuals (one individual per burst), you can simply give it the ltraj
alone. With a single ltraj, the function looks for the closest point in
other bursts. Check the example of the function.

Note that I do not guarantee that my function is efficient! This is R:
there is no use of spatial indexes or bounding boxes, so that for each
point, distances are computed to all other points in the temporal window.
Depending on your data, I guess it could be fairly slow...

Again, if you're looking for performance and/or robustness, I would give a
try to PostGIS here.
Mathieu.


Le 22/07/2015 15:31, André Zehnder a écrit :

> Thank you for all your answers!
>
> @ Krzysztof: Yes, I think an approximated method that uses only the nearest points to compute the distance will suffice. When I include a threshold that ensures that only temporal differences smaller than xy minutes are taken into consideration, reasonable results should be achievable.
>
> @ Sarah: I think you are referring to the simulation of a Brownian motion by the function simm.bb()  for an exact solution? I could not find a function that directly computes the distances. Or did I miss something?
>
> @ Jeremy: Thanks for the hint! A also stumbled upon the pathFrechet() / distFrechet() function of longitudinalData but rejected them because they seem not to include the temporal dimension. However, this seems to be only an erroneous information of inside-r. When I looked at the official reference manual I saw that distFrechet() considers the time as well.
>
> @ Mathieu: That is pretty much what I am intending to do for a first (and possibly also final) try, thanks! So I need to input the ltray-object of the first individual  as 'from' and the other one as 'to' in order to check the distances between their closest points, right? I also tried to program something like that but the result is shockingly time inefficient and might still contain some errors. So I will probably try out your function tomorrow :)
>
> Best regards
> Andre
>
>
>
> -----Ursprüngliche Nachricht-----
> Von: Mathieu Basille [mailto:[hidden email]]
> Gesendet: Mittwoch, 22. Juli 2015 19:44
> An: André Zehnder; R-sig-eco
> Cc: Jeremy Chacon; Sarah Goslee
> Betreff: Re: [R-sig-eco] Compute the distance between the trajectories of two animals with varying sampling intervals
>
> As far as I can tell, there is no such function in adehabitatLT. However, I wrote a function 'closest' [1] in the package 'hab' [2], which specifically does that: find the closest relocations from ltraj objects. It can work with only one ltraj, in which case it will look in other bursts, or with two different ltraj, in which case it will in the other ltraj. Most importantly, you can define a temporal windows to restrict the search, which may solve your problem of irregular time (the ltraj do not have to be regular, or on the same time schedule). It's only Euclidean distance though. Lastly, it works at the location level, i.e. it's not considering lines (steps). If that's what you're looking for, I would probably suggest using PostGIS...
>
> Hope this helps,
> Mathieu.
>
>
> [1] https://github.com/basille/hab/blob/master/R/closest.r
>
> [2] https://github.com/basille/hab
>
>
> Le 22/07/2015 10:09, Jeremy Chacon a écrit :
>> I bet Sarah's right and adehabitatLT has something, but I also know
>> that the longitudinalData package can compute distances between two
>> trajectories including the frechet distance.
>>
>> http://www.inside-r.org/packages/cran/longitudinalData/docs/pathFreche
>> t
>>
>> However, it does not deal with the timing problem. You will have to
>> roll your own method of aligning the trajectories in time.
>>
>> On Wed, Jul 22, 2015 at 9:02 AM, Sarah Goslee <[hidden email]>
>> wrote:
>>
>>> Try the adehabitatLT package.
>>>
>>> On Wed, Jul 22, 2015 at 9:41 AM, André Zehnder
>>> <[hidden email]>
>>> wrote:
>>>> Hi list,
>>>>
>>>>
>>>>
>>>> I want to compute the distances between two trajectories that
>>>> consist of
>>> a
>>>> sequence of point measurements. The trajectories do not have the
>>>> same
>>> length
>>>> or sampling interval. So, while for animal A, there is a data point
>>>> at
>>> 15.00
>>>> p.m. and another at 15.38 p.m, animal B might have data points at
>>>> 14.56
>>> p.m.
>>>>
>>>> and 17.02 p.m.
>>>>
>>>>
>>>>
>>>> A possible approach would be to connect these point series to
>>> trajectories
>>>> and then calculate the distance between the two trajectories at the
>>> sampled
>>>> positions of one trajectory (take the sampled position of the second
>>>> trajectory that is temporally closest). Are there any packages in R
>>>> (or tools outside of R) that allow me to do this? The support of
>>>> other
>>> distances
>>>> than the Euclidean one (e.g. Fr chet) would be an advantage.
>>>>
>>>>
>>>>
>>>> Best regards,
>>>>
>>>> Andre
>>>>
>>>>
>>> --
>>> Sarah Goslee
>>> http://www.functionaldiversity.org
>>>
>>> _______________________________________________
>>> R-sig-ecology mailing list
>>> [hidden email]
>>> https://stat.ethz.ch/mailman/listinfo/r-sig-ecology
>>>
>>
>>
>>
>

--

~$ whoami
Mathieu Basille
http://ase-research.org/basille

~$ locate --details
University of Florida \\
Fort Lauderdale Research and Education Center
(+1) 954-577-6314

~$ fortune
« Le tout est de tout dire, et je manque de mots
Et je manque de temps, et je manque d'audace. »
  -- Paul Éluard

_______________________________________________
R-sig-ecology mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-ecology