#Description of entities (sites) and surveys
entities <- c("1","1","1","1","2","2","2","2","3","3","3","3")
surveys <- c(1,2,3,4,1,2,3,4,1,2,3,4)
#Raw data table
xy<-matrix(0, nrow=12, ncol=2)
xy[2,2]<-1
xy[3,2]<-2
xy[4,2]<-3
xy[5:6,2] <- xy[1:2,2]
xy[7,2]<-1.5
xy[8,2]<-2.0
xy[5:6,1] <- 0.25
xy[7,1]<-0.5
xy[8,1]<-1.0
xy[9:10,1] <- xy[5:6,1]+0.25
xy[11,1] <- 1.0
xy[12,1] <-1.5
xy[9:10,2] <- xy[5:6,2]
xy[11:12,2]<-c(1.25,1.0)
#Draw trajectories
trajectoryPlot(xy, entities, surveys,
traj.colors = c("black","red", "blue"), lwd = 2)
#Distance matrix
d <- dist(xy)
d
#Trajectory data
x <- defineTrajectories(d, entities, surveys)
#Distances between trajectory segments
segmentDistances(x, distance.type = "Hausdorff")
segmentDistances(x, distance.type = "directed-segment")
#Distances between trajectories
trajectoryDistances(x, distance.type = "Hausdorff")
trajectoryDistances(x, distance.type = "DSPD")
#Trajectory convergence/divergence
trajectoryConvergence(x)
#### Example of trajectory shifts
#Description of entities (sites) and surveys
entities2 <- c("1","1","1","1","2","2","2","2","3","3","3","3")
times2 <- c(1,2,3,4,1,2,3,4,1,2,3,4)
#Raw data table
xy2<-matrix(0, nrow=12, ncol=2)
xy2[2,2]<-1
xy2[3,2]<-2
xy2[4,2]<-3
xy2[5:8,1] <- 0.25
xy2[5:8,2] <- xy2[1:4,2] + 0.5 # States are all shifted with respect to site "1"
xy2[9:12,1] <- 0.5
xy2[9:12,2] <- xy2[1:4,2]*1.25 # 1.25 times faster than site "1"
#Draw trajectories
trajectoryPlot(xy2, entities2,
traj.colors = c("black","red", "blue"), lwd = 2)
#Trajectory data
x2 <- defineTrajectories(dist(xy2), entities2, times = times2)
#Check that the third trajectory is faster
trajectorySpeeds(x2)
#Trajectory shifts
trajectoryShifts(x2)
Run the code above in your browser using DataLab