# Example 1 -----------------------------------------------------------------
# Identify representative trajectories from state dissimilarities
# Calculate state dissimilarities (Bray-Curtis) from species abundances
abundance <- data.frame(EDR_data$EDR1$abundance)
d <- vegan::vegdist(abundance[, -c(1:3)], method = "bray")
# Identify the trajectory (or site) and states in d
trajectories <- abundance$traj
states <- as.integer(abundance$state)
# Compute RETRA-EDR
RT1 <- retra_edr(d = d, trajectories = trajectories, states = states,
minSegs = 5)
# Example 2 -----------------------------------------------------------------
# Identify representative trajectories from segment dissimilarities
# Calculate segment dissimilarities using the Hausdorff distance
dSegs <- ecotraj::segmentDistances(ecotraj::defineTrajectories(d = d, sites = trajectories,
surveys = states),
distance.type = "Hausdorff")
dSegs <- dSegs$Dseg
# Identify the trajectory (or site) and states in dSegs:
# Split the labels of dSegs (traj[st1-st2]) into traj, st1, and st2
seg_components <- strsplit(gsub("\\]", "", gsub("\\[", "-", labels(dSegs))), "-")
traj_Segs <- sapply(seg_components, "[", 1)
state1_Segs <- as.integer(sapply(seg_components, "[", 2))
state2_Segs <- as.integer(sapply(seg_components, "[", 3))
# Compute RETRA-EDR
RT2 <- retra_edr(d = d, trajectories = trajectories, states = states, minSegs = 5,
dSegs = dSegs, traj_Segs = traj_Segs,
state1_Segs = state1_Segs, state2_Segs = state2_Segs)
Run the code above in your browser using DataLab