Description Usage Arguments Value Author(s) References See Also Examples
Set of functions for trajectory analysis
Given a distance matrix between community states, functions segmentDistances
and trajectoryDistances
calculate the distance between pairs of directed segments and community trajectories, respectively.
Function trajectoryLengths
calculates lengths of directed segments and complete trajectories.
Function trajectoryAngles
calculates the angle between consecutive pairs of directed segments.
Function trajectoryPCoA
performs principal coordinates analysis (cmdscale
) and draws trajectories in the ordination scatterplot.
Function trajectoryPlot
Draws trajectories in a scatterplot corresponding to the input coordinates.
Function trajectoryProjection
projects a set of target points onto a specified trajectory and returns the distance to the trajectory (i.e. rejection) and the relative position of the projection point within the trajectory.
Function trajectoryConvergence
performs the MannKendall trend test on the distances between trajectories (symmetric test) or the distance between points of one trajectory to the other.
Function trajectoryDirectionality
returns (for each trajectory) a statistic that measures directionality of the whole trajectory.
Function centerTrajectories
shifts all trajectories to the center of the compositional space and returns a modified distance matrix.
These functions consider community dynamics as trajectories in a chosen space of community resemblance and takes trajectories as objects to be compared. By adapting concepts and procedures used for the analysis of trajectories in space (i.e. movement data) (Besse et al. 2016), the functions allow assessing the resemblance between trajectories. Details of calculations are given in De Cáceres et al (submitted)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24  segmentDistances(d, sites, surveys = NULL,
distance.type = "directedsegment", verbose = FALSE)
trajectoryDistances(d, sites, surveys = NULL, distance.type = "DSPD",
symmetrization = "mean", verbose = FALSE)
trajectoryLengths(d, sites, surveys = NULL, verbose = FALSE)
trajectoryAngles(d, sites, surveys = NULL, all = FALSE, verbose = FALSE)
trajectoryPCoA(d, sites, surveys = NULL, selection = NULL,
traj.colors = NULL, axes = c(1, 2), ...)
trajectoryPlot(x, sites, surveys = NULL, selection = NULL,
traj.colors = NULL, axes = c(1, 2), ...)
trajectoryProjection(d, target, trajectory, tol = 1e06)
trajectoryConvergence(d, sites, surveys = NULL, symmetric = FALSE,
verbose = FALSE)
trajectoryDirectionality(d, sites, surveys = NULL, verbose = FALSE)
centerTrajectories(d, sites, surveys = NULL, verbose = FALSE)

d 
A symmetric 
sites 
A vector indicating the site corresponding to each community state. 
surveys 
A vector indicating the survey corresponding to each community state (only necessary when surveys are not in order). 
distance.type 
The type of distance index to be calculated (Besse et al. 2016; De Cáceres et al. submitted). For
whereas for

verbose 
Provides console output informing about process (useful for large dataset). 
symmetrization 
Function used to obtain a symmetric distance, so that DSPD(T1,T2) = DSPD(T2,T1) (e.g., 
all 
A flag to indicate that angles are desired for all triangles in the trajectory 
selection 
A numeric or logical vector of the same length as 
traj.colors 
A vector of colors (one per site). If 
axes 
The pair of principal coordinates to be plotted. 
... 
Additional parameters for function 
x 
A data.frame or matrix where rows are community states and columns are coordinates in an arbitrary space 
target 
An integer vector of the community states to be projected. 
trajectory 
An integer vector of the trajectory onto which target states are to be projected. 
tol 
Numerical tolerance value to determine that projection of a point lies within the trajectory. 
symmetric 
A logical flag to indicate a symmetric convergence comparison of trajectories. 
Function trajectoryDistances
returns an object of class dist
containing the distances between trajectories. Function trajectorySegments
returns a list with the following elements:
Dseg
: Distance matrix between segments.
Dini
: Distance matrix between initial points of segments.
Dfin
: Distance matrix between final points of segments.
Dinifin
: Distance matrix between initial points of one segment and the final point of the other.
Dfinini
: Distance matrix between final points of one segment and the initial point of the other.
Function trajectoryLengths
returns a data frame with the length of each segment on each trajectory and the total length of all trajectories. Function trajectoryPCoA
returns the result of calling cmdscale
.
Function trajectoryAngles
returns a data frame with the angle between each pair of segments on each trajectory and the mean and standard deviation of those angles across each trajectory.
Function trajectoryPCoA
returns the result of calling cmdscale
.
Function trajectoryProjection
returns a data frame with the following columns:
distanceToTrajectory
: Distances to the trajectory, i.e. rejection (NA
for target points whose projection is outside the trajectory).
segment
: Segment that includes the projected point (NA
for target points whose projection is outside the trajectory).
relativePosition
: Relative position of the projected point within the trajectory, i.e. values from 0 to 1 with 0 representing the start of the trajectory and 1 representing the end (NA
for target points whose projection is outside the trajectory).
Function trajectoryConvergence
returns a list with two elements:
tau
: A matrix with the statistic (MannKendall's tau) of the convergence/divergence test between trajectories. If symmetric=TRUE
then the matrix is square. Otherwise the statistic of the test of the row trajectory approaching the column trajectory.
p.value
: A matrix with the pvalue of the convergence/divergence test between trajectories. If symmetric=TRUE
then the matrix is square. Otherwise the pvalue indicates the test of the row trajectory approaching the column trajectory.
Function trajectoryDirectionality
returns a vector with directionality values (one per trajectory).
Function centerTrajectory
returns an object of class dist
.
Miquel De Cáceres, Forest Sciences Center of Catalonia
Besse, P., Guillouet, B., Loubes, J.M. & François, R. (2016). Review and perspective for distance based trajectory clustering. IEEE Trans. Intell. Transp. Syst., 17, 3306–3317.
De Cáceres M, Coll L, Legendre P, Allen RB, Wiser SK, Fortin MJ, Condit R & Hubbell S. (submitted). Trajectory analysis in community ecology.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38  #Description of sites and surveys
sites = c(1,1,1,2,2,2)
surveys=c(1,2,3,1,2,3)
#Raw data table
xy<matrix(0, nrow=6, ncol=2)
xy[2,2]<1
xy[3,2]<2
xy[4:6,1] < 0.5
xy[4:6,2] < xy[1:3,2]
xy[6,1]<1
#Distance matrix
d = dist(xy)
d
trajectoryLengths(d, sites, surveys)
trajectoryAngles(d, sites, surveys)
segmentDistances(d, sites, surveys)$Dseg
trajectoryDistances(d, sites, surveys, distance.type = "Hausdorff")
trajectoryDistances(d, sites, surveys, distance.type = "DSPD")
#Draw trajectories
trajectoryPCoA(d, sites, traj.colors = c("black","red"), lwd = 2)
#Should give the same results if surveys are not in order
#(here we switch surveys for site 2)
temp = xy[5,]
xy[5,] = xy[6,]
xy[6,] = temp
surveys[5] = 3
surveys[6] = 2
trajectoryLengths(dist(xy), sites, surveys)
segmentDistances(dist(xy), sites, surveys)$Dseg
trajectoryDistances(dist(xy), sites, surveys, distance.type = "Hausdorff")
trajectoryDistances(dist(xy), sites, surveys, distance.type = "DSPD")

Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.