# distance: Compute distance statistics In moveBB: Analysis of Trajectory Data using Linear or Brownian Motion Model

## Description

Density, distribution function, quantile function for the distances between entities at the given time(s), using the Brownian bridge movement model. Distance between entities and whether encounters occur in the linear movement model.

## Usage

 ```1 2 3 4 5 6 7 8``` ```distance(tr, time) ddistance(d, tr, time) pdistance(d, tr, time) qdistance(p, tr, time) encounter(d, tr, time) encounterIntervals(d, tr) ```

## Arguments

 `d` Vector of distances `p` Vector of probabilities `tr` The trajectory object `time` Vector of times

## Details

`encounterIntervals` accepts only a single distance.

## Value

`distance` returns a three dimensional array indexed by two IDs and the time, each value representing the distance in the linear movement model between these two IDs at that time.

`encounter` returns whether an encounter occurs for each value of `d` and for each of the requested times. The value is computed between each pair of IDs in the trajectory. This means that the result is a 4 dimensional array, indexed by the IDs involved, the value of `d` and the time.

`encounterIntervals` computes the time intervals in which there is an encounter between each pair of IDs. In the linear model this can be solved analytically, which is often faster than requesting whether an encounter occurs for many different times.

`ddistance` computes the density, `pdistance` the distribution function and `qdistance` evaluates the quantile function for the requested parameters. `pdistance` is equivalent to the probability that an encounter occurs, given a threshold distance.

The functions return the requested values for each value of the first parameter (`d` or `p`) and for each of the requested times. The value is computed between each pair of IDs in the trajectory.

This means that the result is a 4 dimensional array, indexed by the IDs involved, the value of `d` or `p` and the time.

`bbtraj`
 ``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14``` ```data("vervet_monkeys", package="moveBB") ## Compute the distance at two distinct times #distance(monkey.tr, as.POSIXct(c("2011-01-18 15:15:15", "2011-01-19 16:30:00"))) ## See whether an encounter occurs at the 50m or 100m thesholds #encounter(c(10, 100), monkey.tr, as.POSIXct(c("2011-01-18 15:15:15", "2011-01-19 16:30:00"))) ## Compute when there are encounters #ei <- encounterIntervals(100, monkey.tr) #ei[["BD","NH"]] ## Compute the 5th and 95th percentile of the distance at two distinct times #qdistance(c(0.05, 0.95), monkey.tr, as.POSIXct(c("2011-01-18 15:15:15", "2011-01-19 16:30:00"))) ```