Package 'iccTraj'

Title: Estimates the Intraclass Correlation Coefficient for Trajectory Data
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>.
Authors: Josep L. Carrasco [aut, cre]
Maintainer: Josep L. Carrasco <[email protected]>
License: GPL (>= 2)
Version: 1.0.4
Built: 2025-01-26 04:10:23 UTC
Source: https://github.com/cran/iccTraj

Help Index


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


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)

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 coeffcient 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).


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
)

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 "bootCI" is FALSE. Default value is 100.

q

Quantile for the extended Hausdorff distance. Default value q=0.5 leads to median Hausdorff distance.

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("EB", "AN", "ZT"))

Arguments

x

An object of class "iccTraj"

conf

Numeric. Level of confidence. Default is set to 0.95.

method

String. Method used to estimate the confidence interval. Accepted values are **EB** for Empirical Bootstrap, **AN** for asymptotic Normal, and **ZT** for asymptotic Normal using the Z-transformation.

Details

Let θ^\hat{\theta} denote the ICC sample estimate and θiB\theta_i^{B} denote the ICC bootstrap estimates with i=1,,Bi=1,\ldots,B. Let δα/2B\delta_{\alpha/2}^{B} and δ1α/2B\delta_{1-\alpha/2}^{B} be the α2\frac{\alpha}{2} and 1α21-\frac{\alpha}{2} percentiles of δiB=θiBθ^\delta_{i}^{B}=\theta_i^{B}-\hat{\theta}. The empirical bootstrap confidence interval is then estimated as θ^+δα/2B,θ^+δ1α/2B\hat{\theta}+\delta_{\alpha/2}^{B},\hat{\theta}+\delta_{1-\alpha/2}^{B}.

Asymptotic Normal (AN) interval is obtained as θ^±Z1α/2SEB\hat{\theta} \pm Z_{1-\alpha/2}*SE_B where SEBSE_B denotes the standard deviation of θiB\theta_i^{B}, and Z1α/2Z_{1-\alpha/2} stands for the 1α/21-\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)