#First build a toy dataset with:
#The sampling times of the time series
timesToy <- 0:30
#The duration of the cycles (i.e. the periodicity of the time series)
cycleDurationToy <- 10
#The sites sampled (only one named "A")
sitesToy <- rep(c("A"),length(timesToy))
#And prepare a trend term
trend <- 0.05
#Build cyclical data (note that we apply the trend only to x):
x <- sin((timesToy*2*pi)/cycleDurationToy)+trend*timesToy
y <- cos((timesToy*2*pi)/cycleDurationToy)
matToy <- cbind(x,y)
#And express it as distances:
dToy <- dist(matToy)
#Make it an object of class trajectory:
cyclicalTrajToy <- defineTrajectories(d = dToy,
sites = sitesToy,
times = timesToy)
#At this stage, cycles and / or fixed date trajectories are not isolated.
#This done with the two CETA "extract" functions:
cyclesToy <- extractCycles(x = cyclicalTrajToy,
cycleDuration = cycleDurationToy)
fdTrajToy <- extractFixedDateTrajectories(x = cyclicalTrajToy,
cycleDuration = cycleDurationToy)
#The output of these functions can be used as input
#for other ETA functions to get metrics of interest
#such as trajectory length:
trajectoryLengths(x = cyclesToy)
trajectoryLengths(x = fdTrajToy)
#or distances between trajectories:
trajectoryDistances(x = cyclesToy)
trajectoryDistances(x = fdTrajToy)
#In addition CETA adds two additional specific metrics.
#that require the same inputs as function extractCycles():
cycleConvexity(x = cyclicalTrajToy,
cycleDuration = cycleDurationToy)
#The NA with the first cycle, is expected:
#Cycle convexity cannot be computed right at the boundary of the time series
cycleShifts(x = cyclicalTrajToy,
cycleDuration = cycleDurationToy)
#Note that because our cycles are perfectly regular here, the cyclicalShift
#computed are all 0 (or close because of R's computing approximations)
#Subsetting cycles and fixed date trajectories:
subsetTrajectories(cyclesToy,
subtrajectory_selection = "A_C1")
subsetTrajectories(fdTrajToy,
subtrajectory_selection = c("A_fdT_2","A_fdT_4"))
#General metrics describing the geometry of cycles:
cycleMetrics(x = cyclicalTrajToy,
cycleDuration = cycleDurationToy)
Run the code above in your browser using DataLab