edge_nn returns edge lists defined by the nearest neighbour. The
function accepts a
data.table with relocation data, individual
identifiers and a threshold argument. The threshold argument is used to
specify the criteria for distance between points which defines a group.
Relocation data should be in two columns representing the X and Y
1 2 3 4 5 6 7 8 9
Character string of ID column name
Character vector of X coordinate and Y coordinate column names
timegroup field in the DT upon which the grouping will be calculated
(optional) character string or vector of grouping column name(s) upon which the grouping will be calculated
(optional) spatial distance threshold to set maximum distance between an individual and their neighbour.
boolean indicating if the distance between individuals should be returned. If FALSE (default), only ID, NN columns (and timegroup, splitBy columns if provided) are returned. If TRUE, another column "distance" is returned indicating the distance between ID and NN.
DT must be a
data.table. If your data is a
data.frame, you can convert it by reference using
coords (and optional
splitBy) arguments expect the names of a column in
correspond to the individual identifier, X and Y coordinates, timegroup
group_times) and additional grouping columns.
threshold must be provided in the units of the coordinates. The
threshold must be larger than 0. The coordinates must be planar
coordinates (e.g.: UTM). In the case of UTM, a
threshold = 50 would
indicate a 50m distance threshold.
timegroup argument is optional, but recommended to pair with
group_times. The intended framework is to group rows temporally
group_times then spatially with
splitBy argument offers further control over grouping. If within
DT, you have multiple populations, subgroups or other distinct
parts, you can provide the name of the column which identifies them to
edge_nn will only consider rows within each
edge_nn returns a
data.table with three columns:
timegroup, ID and NN. If 'returnDist' is TRUE, column 'distance' is
returned indicating the distance between ID and NN.
The ID and NN columns represent the edges defined by the nearest neighbours
(and temporal thresholds with
If an individual was alone in a timegroup or splitBy, or did not have any neighbours within the threshold distance, they are assigned NA for nearest neighbour.
Other Edge-list generation:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
# Load data.table library(data.table) # Read example data DT <- fread(system.file("extdata", "DT.csv", package = "spatsoc")) # Cast the character column to POSIXct DT[, datetime := as.POSIXct(datetime, tz = 'UTC')] # Temporal grouping group_times(DT, datetime = 'datetime', threshold = '20 minutes') # Edge list generation edges <- edge_nn(DT, id = 'ID', coords = c('X', 'Y'), timegroup = 'timegroup') # Edge list generation using maximum distance threshold edges <- edge_nn(DT, id = 'ID', coords = c('X', 'Y'), timegroup = 'timegroup', threshold = 100) # Edge list generation, returning distance between nearest neighbours edge_nn(DT, id = 'ID', coords = c('X', 'Y'), timegroup = 'timegroup', threshold = 100, returnDist = TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.