Type: | Package |
Title: | Estimates the Intraclass Correlation Coefficient for Trajectory Data |
Version: | 1.1.0 |
Depends: | R (≥ 4.0) |
Imports: | dplyr, magic, trajectories, sp, spacetime, purrr, utils, furrr, progressr, parallel, parallelly, future |
Description: | Estimates the intraclass correlation coefficient for trajectory data using a matrix of distances between trajectories. The distances implemented are the extended Hausdorff distances (Min et al. 2007) <doi:10.1080/13658810601073315> and the discrete Fréchet distance (Magdy et al. 2015) <doi:10.1109/IntelCIS.2015.7397286>. |
License: | GPL-2 | GPL-3 [expanded from: GPL (≥ 2)] |
Encoding: | UTF-8 |
LazyData: | true |
RoxygenNote: | 7.3.2 |
NeedsCompilation: | no |
Packaged: | 2025-05-07 13:03:04 UTC; hexac |
Author: | Josep L. Carrasco [aut, cre] |
Maintainer: | Josep L. Carrasco <jlcarrasco@ub.edu> |
Repository: | CRAN |
Date/Publication: | 2025-05-08 10:50:01 UTC |
Creates a data frame with the discrete Fréchet distance between two trajectories
Description
Creates a data frame with the discrete Fréchet distance between two trajectories
Usage
FD_data(data, i, j)
Arguments
data |
A list created with |
i |
Position in the data of the first trajectory |
j |
Position in the data of the second trajectory |
Value
A data frame with the subjects and trips identifiers and the discrete Fréchet distance
Computes extended Hausdorff distance between two trajectories.
Description
Computes extended Hausdorff distance between two trajectories.
Usage
HD(pp1, pp2, q = 1)
Arguments
pp1 |
Set of spatial points for the first trajectory. It can be a matrix of 2D points, first column x/longitude, second column y/latitude, or a SpatialPoints or SpatialPointsDataFrame object. |
pp2 |
Set of spatial points for the second trajectory. It can be a matrix of 2D points, first column x/longitude, second column y/latitude, or a SpatialPoints or SpatialPointsDataFrame object. |
q |
Quantile for the extended Hausdorff distance. Default value q=1 uses the maximum that leads to classical Hausdorff distance. |
Value
A numerical value with the distance.
References
Magdy, N., Sakr, M., Abdelkader, T., Elbahnasy, K. (2015). Review on trajectory similarity measures. 10.1109/IntelCIS.2015.7397286.
Min, D., Zhilin, L., Xiaoyong, C. (2007) Extended Hausdorff distance for spatial objects in GIS. International Journal of Geographical Information Science, 21:4, 459–475
Examples
# Take two trajectories
library(dplyr)
library(sp)
sample_data<-gull_data %>% filter(ID %in% c(5107912,5107913), trip %in% c("V02","V01"))
tr1<-gull_data %>% filter((ID == 5107912) & (trip=="V02"))
tr2<-gull_data %>% filter((ID == 5107913) & (trip=="V01"))
pts1 = SpatialPoints(tr1[c("LONG","LAT")], proj4string=CRS("+proj=longlat"))
pts2 = SpatialPoints(tr2[c("LONG","LAT")], proj4string=CRS("+proj=longlat"))
# Hausdorff distance
HD(pts1,pts2,q=1)
# Median Hausdorff distance
HD(pts1,pts2,q=0.5)
Creates a data frame with the Hausdorff distance between two trajectories
Description
Creates a data frame with the Hausdorff distance between two trajectories
Usage
HD_data(data, i, j, q)
Arguments
data |
A list created with |
i |
Position in the data of the first trajectory |
j |
Position in the data of the second trajectory |
q |
Quantile for the extended Hausdorff distance. Default value q=1 uses the maximum that leads to classical Hausdorff distance. |
Value
A data frame with the subjects and trips identifiers and the extended Hausdorff distance
Computes the intraclass correlation coefficient (ICC) using a matrix of distances.
Description
Computes the intraclass correlation coefficient (ICC) using a matrix of distances.
Usage
ICC(X, nt)
Arguments
X |
Matrix with the pairwise distances. |
nt |
Data frame with the number of trips by subject |
Details
The intraclass correlation coefficient is estimated using the distance matrix among trajectories.
Value
Data frame with the estimates of the ICC (r), the subjects' mean sum-of-squares (MSA), the between-subjects variance (sb), the total variance (st), and the within-subjects variance (se).
Generates a bootstrap sample and estimates the ICC
Description
Generates a bootstrap sample and estimates the ICC
Usage
boot_ICC(X, nt, Bmat, indB)
Arguments
X |
Data frame with the pairwise distances |
nt |
Data frame with the number of trips by subject |
Bmat |
Matrix with subjects identifiers in the resamples |
indB |
Column in Bmat that geenrates the resample |
Value
Data frame with the estimates of the ICC (r), the subjects' mean sum-of-squares (MSA), the between-subjects variance (sb), the total variance (st), and the within-subjects variance (se).
Creates a matrix with the pairwise distances
Description
Creates a matrix with the pairwise distances
Usage
dist_mat(dataD, nt)
Arguments
dataD |
Data frame created with |
nt |
Data frame with the number of trips by subject |
Value
A list with two components:
*D*. A matrix with the pairwise distances
*data*. A data frame with the pairwise distances
Generates a data frame with the pairwise distances between trajectories
Description
Generates a data frame with the pairwise distances between trajectories
Usage
genHD(
data_list,
parallel = TRUE,
distance = c("H", "F"),
q = 0.5,
future_seed = 123
)
Arguments
data_list |
A list created with |
parallel |
TRUE/FALSE value. Use parallel computation? Default value is TRUE. |
distance |
Metric used to compute the distances between trajectories. Options are **H** for median Hausforff distance, and **F** for discrete Fréchet distance. |
q |
Quantile for the extended Hausdorff distance. Default value q=0.5 leads to median Hausdorff distance. |
future_seed |
Logical/Integer. The seed to be used for parallellization. Further details in |
Value
A data frame with the subjects and trips identifiers and their distances
Preprocessing of data
Description
Preprocessing of data
Usage
get_data(data, ID, trip, LON, LAT, time)
Arguments
data |
A data frame with the steps of trajectories. It is assumed the time between steps is uniform. It must contain contain at least five columns: subject identifier, trip identifier, latitude, longitude, and time of the reading. |
ID |
Character string indicating the name of the subjects column in the dataset. |
trip |
Character string indicating the trip column in the dataset. |
LON |
Numeric. Longitude readings. |
LAT |
Numeric. Latitude readings. |
time |
Numeric. Time of the readings. |
Value
A data frame
Gull data
Description
A data frame with sample of 90 gull trajectories.
Usage
gull_data
Format
A data frame containing 90 trajectories
- ID
Subject identifier
- trip
Trip identifier
- LONG
Longitude
- LAT
Latitude
- triptime
Time in seconds when the locations were obtained
Estimates the intraclass correlation coefficient (ICC) for trajectory data
Description
Estimates the intraclass correlation coefficient (ICC) for trajectory data
Usage
iccTraj(
data,
ID,
trip,
LON,
LAT,
time,
projection = CRS("+proj=longlat"),
origin = "1970-01-01 UTC",
parallel = TRUE,
individual = TRUE,
distance = c("H", "F"),
bootCI = TRUE,
nBoot = 100,
q = 0.5,
future_seed = 123
)
Arguments
data |
A data frame with the locations and times of trajectories. It is assumed the time between locations is uniform. It must contain at least five columns: subject identifier, trip identifier, latitude, longitude, and time of the reading. |
ID |
Character string indicating the name of the subjects column in the dataset. |
trip |
Character string indicating the trip column in the dataset. |
LON |
Numeric. Longitude readings. |
LAT |
Numeric. Latitude readings. |
time |
Numeric. Time of the readings. |
projection |
Projection string of class CRS-class. |
origin |
Optional. Origin of the date-time. Only needed in the internal process to create an object of type POSIXct. |
parallel |
TRUE/FALSE value. Use parallel computation? Default value is TRUE. |
individual |
TRUE/FALSE value. Compute individual within-subjects variances? Default value is TRUE. |
distance |
Metric used to compute the distances between trajectories. Options are "H" for median Hausforff distance, and "F" for discrete Fréchet distance. |
bootCI |
TRUE/FALSE value. If TRUE it will generate boostrap resamples. Default value is TRUE. |
nBoot |
Numeric. Number of bootstrap resamples. Ignored if |
q |
Quantile for the extended Hausdorff distance. Default value q=0.5 leads to median Hausdorff distance. |
future_seed |
Logical/Integer. The seed to be used for parallellization. Further details in |
Details
The intraclass correlation coefficient is estimated using the distance matrix among trajectories.
Bootstrap resamples are obtained using balanced randomized cluster bootstrap approach (Davison and Hinkley, 1997; Field and Welsh, 2007)
Value
An object of class iccTraj
.The output is a list with the following components:
-
est
. Data frame with the following estimates: the ICC (r), the subjects' mean sum-of-squares (MSA), the between-subjects variance (sb), the total variance (st), and the within-subjects variance (se). -
boot
. If bootCI argument is set to TRUE, data frame with the bootstrap estimates. -
D
. Data frame with the pairwise distances among trajectories. -
indW
. Data frame with the following columns: the subject's identifier (ID), the individual within-subjects variances (w), the individual ICC (r), and the number of trips (n).
References
Davison A.C., Hinkley D.V. (1997). Bootstrap Methods and Their Application. Cambridge: Cambridge University Press.
Field, C.A., Welsh, A.H. (2007). Bootstrapping Clustered Data. Journal of the Royal Statistical Society. Series B (Statistical Methodology). 69(3), 369-390.
Examples
# Using median Hausdorff distance.
Hd<-iccTraj(gull_data,"ID","trip","LONG","LAT","triptime")
Hd$est
# Using discrete Fréchet distance.
Fd<-iccTraj(gull_data,"ID","trip","LONG","LAT","triptime", distance="F")
Fd$est
Computes the confidence interval for the ICC
Description
Computes the confidence interval for the ICC
Usage
interval(x, conf = 0.95, method = c("BCa", "Perc", "EB", "AN", "ZT"))
Arguments
x |
An object of class |
conf |
Numeric. Level of confidence. Default is set to 0.95. |
method |
String. Method used to estimate the confidence interval. Accepted values are: "BCa" for bias-corrected and accelerated bootstrap, "EB" for empirical bootstrap, "Perc" for percentile bootstrap, "AN" for asymptotic Normal, and "ZT" for asymptotic Normal using the Z-transformation. |
Details
Let \hat{\theta}
denote the ICC sample estimate and \theta_i^{B}
denote the ICC bootstrap estimates with i=1,\ldots,B
. Let \delta_{\alpha/2}^{B}
and \delta_{1-\alpha/2}^{B}
be the \frac{\alpha}{2}
and 1-\frac{\alpha}{2}
percentiles of \delta_{i}^{B}=\theta_i^{B}-\hat{\theta}
.
The percentile bootstrap confidence interval is computed as \hat{\theta}+\delta_{\alpha/2}^{B},\hat{\theta}+\delta_{1-\alpha/2}^{B}
.
The empirical bootstrap confidence interval is estimated as \hat{\theta}-\delta_{1-\alpha/2}^{B},\hat{\theta}-\delta_{\alpha/2}^{B}
Asymptotic Normal (AN) interval is obtained as \hat{\theta} \pm Z_{1-\alpha/2}*SE_B
where SE_B
denotes the standard deviation of \theta_i^{B}
, and Z_{1-\alpha/2}
stands for the 1-\alpha/2
quantile of the standard Normal distribution.
In the ZT approach, the ICC is transformed using Fisher's Z-transformation. Then, the AN approach is applied to the transformed ICC.
Value
A vector with the two boundaries of the confidence interval.
Examples
# Using median Hausdorff distance
Hd<-iccTraj(gull_data,"ID","trip","LONG","LAT","triptime", parallel=FALSE, distance="H")
Hd$est
interval(Hd)
Computes the number of trips by subject
Description
Computes the number of trips by subject
Usage
ntrips(data)
Arguments
data |
A data frame with the steps of trajectories. It is assumed the time between steps is uniform. It must contain contain at least five columns: subject identifier, trip identifier, latitude, longitude, and time of the reading. |
Value
A data frame with the number of trips by subject.
Prints the ICC
Description
Prints the ICC
Usage
## S3 method for class 'iccTraj'
print(x, ...)
Arguments
x |
An object of class |
Value
The ICC estimate.
Creates a list containing the trajectories information.
Description
Creates a list containing the trajectories information.
Usage
tr_gen(data, projection = CRS("+proj=longlat"), origin = "1970-01-01 UTC")
Arguments
projection |
Projection string of class CRS-class. |
origin |
Optional. Origin of the date-time. Only needed in the internal process to create an object of type POSIXct. |
Value
Every component of the list has the following subcomponents: #'
An object of class Track.
An object of class SpatialPoints.
Subject identifier
Trip identifier.