simil_DTW_metric {QuAnTeTrack} | R Documentation |
Similarity metric using Dynamic Time Warping (DTW)
Description
simil_DTW_metric()
computes similarity metrics between two or more trajectories using
Dynamic Time Warping (DTW). It allows for different superposition methods
to align trajectories before calculating the DTW metric. The function also supports
testing with simulations to calculate p-values for the DTW distance metrics.
Usage
simil_DTW_metric(data, test = NULL, sim = NULL, superposition = NULL)
Arguments
data |
A
|
test |
Logical; if |
sim |
A |
superposition |
A character string indicating the method used to align trajectories.
Options are |
Details
The simil_DTW_metric()
function calculates the similarity between trajectories using
the Dynamic Time Warping (DTW) algorithm from the dtw package. The dtw()
function
is used with the dist.method
argument set to "Euclidean"
for computing the local distances
between points in the trajectories.
DTW aligns two time series by minimizing the cumulative distance between their points, creating an optimal alignment despite variations in length or temporal distortions. The algorithm constructs a distance matrix where each element represents the cost of aligning points between the two series and finds a warping path through this matrix that minimizes the total distance. The warping path is contiguous and monotonic, starting from the bottom-left corner and ending at the top-right corner (Cleasby et al., 2019).
DTW measures are non-negative and unbounded, with larger values indicating greater dissimilarity between the time series. This method has been used in various contexts, including ecological studies to analyze and cluster trajectory data (Cleasby et al., 2019).
Potential limitations and biases of DTW include sensitivity to noise and outliers, computational complexity, and the need for appropriate distance metrics. Additionally, DTW may not always account for all structural differences between trajectories and can be biased by the chosen alignment constraints. While DTW can handle trajectories of different lengths due to its elastic nature, having trajectories of similar lengths can improve the accuracy and interpretability of the similarity measure. Similar lengths result in a more meaningful alignment and can make the computation more efficient. When trajectories differ significantly in length, preprocessing or normalization might be necessary, and careful analysis is required to understand the alignment path. The function’s flexibility in handling different lengths allows it to be applied in various contexts. However, large differences in trajectory lengths might introduce potential biases that should be considered when interpreting the results.
The function offers three different superposition methods to align the trajectories
before DTW()
is applied:
-
"None"
: No superposition is applied. -
"Centroid"
: Trajectories are shifted to align based on their centroids. -
"Origin"
: Trajectories are shifted to align based on their starting point.
If test = TRUE
, the function can compute p-values by comparing the observed DTW
distances with those generated from a set of simulated trajectories. The p-values
are calculated for both individual trajectory pairs and for the entire set of trajectories.
Value
A track similarity
R object consisting ofa list containing the following elements:
DTW_distance_metric |
A matrix containing the pairwise DTW distances between trajectories. |
DTW_distance_metric_p_values |
(If |
DTW_metric_p_values_combined |
(If |
DTW_distance_metric_simulations |
(If |
Logo
Author(s)
Humberto G. Ferrón
humberto.ferron@uv.es
Macroevolution and Functional Morphology Research Group (www.macrofun.es)
Cavanilles Institute of Biodiversity and Evolutionary Biology
Calle Catedrático José Beltrán Martínez, nº 2
46980 Paterna - Valencia - Spain
Phone: +34 (9635) 44477
References
Cleasby, I. R., Wakefield, E. D., Morrissey, B. J., Bodey, T. W., Votier, S. C., Bearhop, S., & Hamer, K. C. (2019). Using time-series similarity measures to compare animal movement trajectories in ecology. Behavioral Ecology and Sociobiology, 73, 1-19.
See Also
tps_to_track
, simulate_track
, dtw
Examples
# Example 1: Simulating tracks using the "Directed" model and comparing DTW distance
# in the PaluxyRiver dataset
s1 <- simulate_track(PaluxyRiver, nsim = 3, model = "Directed")
simil_DTW_metric(PaluxyRiver, test = TRUE, sim = s1, superposition = "None")
# Example 2: Simulating tracks using the "Constrained" model and comparing DTW distance
# in the PaluxyRiver dataset
s2 <- simulate_track(PaluxyRiver, nsim = 3, model = "Constrained")
simil_DTW_metric(PaluxyRiver, test = TRUE, sim = s2, superposition = "None")
# Example 3: Simulating tracks using the "Unconstrained" model and comparing DTW distance
# in the PaluxyRiver dataset
s3 <- simulate_track(PaluxyRiver, nsim = 3, model = "Unconstrained")
simil_DTW_metric(PaluxyRiver, test = TRUE, sim = s3, superposition = "None")
# Example 4: Simulating and comparing DTW distance in the MountTom dataset using the
# "Centroid" superposition method
sbMountTom <- subset_track(MountTom, tracks = c(1, 2, 3, 4, 7, 8, 9, 13, 15, 16, 18))
s4 <- simulate_track(sbMountTom, nsim = 3)
simil_DTW_metric(sbMountTom, test = TRUE, sim = s4, superposition = "Centroid")
# Example 5: Simulating and comparing DTW distance in the MountTom dataset using the
# "Origin" superposition method
sbMountTom <- subset_track(MountTom, tracks = c(1, 2, 3, 4, 7, 8, 9, 13, 15, 16, 18))
s5 <- simulate_track(sbMountTom, nsim = 3)
simil_DTW_metric(sbMountTom, test = TRUE, sim = s5, superposition = "Origin")