The spatsoc
package provides functionality for analyzing animal relocation data in time and space to identify potential interactions among individuals and build gambit-of-the-group data for constructing social networks.
The package contains grouping functions that are used for identifying spatially and temporally explicit groups from input data. In addition, we provide a function for randomizing individual identifiers within groups, designed to test whether social networks generated from animal relocation data were based on non-random social proximity among individuals.
The functions were developped for application across animal relocation data, for example, proximity based social network analyses and spatial and temporal clustering of points.
Let’s read in spatsoc
’s example data.
library(spatsoc)
DT <- fread(system.file("extdata", "DT.csv", package = "spatsoc"))
DT[, datetime := as.POSIXct(datetime,
tz = 'UTC')]
ID | X | Y | datetime | population |
---|---|---|---|---|
B | 556792.2 | 5400539 | 2018-08-20 19:30:11 | 2 |
A | 557019.1 | 5400046 | 2018-08-30 11:15:01 | 1 |
A | 557069.9 | 5400055 | 2018-08-21 04:31:05 | 1 |
C | 557009.3 | 5400395 | 2018-08-17 09:46:07 | 2 |
A | 557240.8 | 5400174 | 2018-08-31 05:15:50 | 1 |
The data consist of relocations of 3 individuals over 19 days. Using these data, we can compare the various grouping methods available in spatsoc
.
group_times
The group_times
function is used to group relocations temporally. It is flexible to a threshold provided in units of minutes, hours or days. Since GPS fixes taken at regular intervals have some level of variability, we will provide a time threshold (threshold
), to consider all fixes within this threshold taken at the same time. Alternatively, we may want to understand different scales of grouping, perhaps daily movement trajectories or seasonal home range overlap.
ID | X | Y | datetime | timegroup |
---|---|---|---|---|
C | 557058.0 | 5400054 | 2018-08-15 21:45:06 | 1 |
B | 557045.0 | 5400050 | 2018-08-15 21:45:49 | 1 |
A | 557041.0 | 5400088 | 2018-08-15 21:46:06 | 1 |
B | 557056.8 | 5399986 | 2018-08-15 22:30:35 | 2 |
A | 557128.0 | 5400074 | 2018-08-15 22:31:00 | 2 |
C | 557062.8 | 5400088 | 2018-08-15 22:31:11 | 2 |
B | 557078.1 | 5400039 | 2018-08-15 23:15:18 | 3 |
A | 557007.2 | 5400117 | 2018-08-15 23:15:46 | 3 |
C | 557099.3 | 5400079 | 2018-08-15 23:16:09 | 3 |
ID | X | Y | datetime | timegroup |
---|---|---|---|---|
C | 557058.0 | 5400054 | 2018-08-15 21:45:06 | 1 |
B | 557045.0 | 5400050 | 2018-08-15 21:45:49 | 1 |
A | 557041.0 | 5400088 | 2018-08-15 21:46:06 | 1 |
B | 557056.8 | 5399986 | 2018-08-15 22:30:35 | 1 |
A | 557128.0 | 5400074 | 2018-08-15 22:31:00 | 1 |
C | 557062.8 | 5400088 | 2018-08-15 22:31:11 | 1 |
B | 557078.1 | 5400039 | 2018-08-15 23:15:18 | 2 |
A | 557007.2 | 5400117 | 2018-08-15 23:15:46 | 2 |
C | 557099.3 | 5400079 | 2018-08-15 23:16:09 | 2 |
ID | X | Y | datetime | timegroup |
---|---|---|---|---|
A | 557041.0 | 5400088 | 2018-08-15 21:46:06 | 1 |
C | 557180.2 | 5400244 | 2018-08-16 00:46:09 | 1 |
B | 557040.2 | 5400210 | 2018-08-16 10:31:20 | 1 |
A | 556989.9 | 5399860 | 2018-08-20 00:00:20 | 2 |
A | 556963.7 | 5400078 | 2018-08-20 08:16:12 | 2 |
A | 556563.4 | 5400348 | 2018-08-22 21:00:07 | 2 |
A | 557317.9 | 5399603 | 2018-08-25 00:00:38 | 3 |
A | 557147.3 | 5399707 | 2018-08-25 23:15:38 | 3 |
C | 557948.5 | 5401310 | 2018-08-29 09:45:46 | 3 |
group_pts
The group_pts
function compares the relocations of all individuals in each timegroup and groups individuals based on a distance threshold provided by the user.
group_times(DT = DT, datetime = 'datetime', threshold = '15 minutes')
group_pts(DT, threshold = 50, id = 'ID', coords = c('X', 'Y'))
ID | X | Y | timegroup | group |
---|---|---|---|---|
A | 557041.0 | 5400088 | 1 | 1 |
B | 557045.0 | 5400050 | 1 | 1 |
C | 557058.0 | 5400054 | 1 | 1 |
A | 557128.0 | 5400074 | 2 | 2 |
A | 557007.2 | 5400117 | 3 | 3 |
A | 556945.8 | 5400134 | 4 | 4 |
A | 556958.1 | 5400218 | 5 | 5 |
A | 556936.1 | 5400209 | 6 | 6 |
A | 556962.1 | 5400129 | 7 | 7 |
group_lines
The group_lines
function groups individuals whose trajectories intersect in a specified time interval. This represents a coarser grouping method than group_pts
which can help understand shared space at daily, weekly or other temporal resolutions.
utm <- '+proj=utm +zone=21 ellps=WGS84'
group_times(DT = DT, datetime = 'datetime', threshold = '1 day')
group_lines(DT, threshold = 50, projection = utm,
id = 'ID', coords = c('X', 'Y'),
timegroup = 'timegroup')
ID | X | Y | timegroup | group |
---|---|---|---|---|
A | 557041.0 | 5400088 | 1 | 1 |
A | 557128.0 | 5400074 | 1 | 1 |
A | 557007.2 | 5400117 | 1 | 1 |
A | 556945.8 | 5400134 | 2 | 1 |
A | 556958.1 | 5400218 | 2 | 1 |
A | 556936.1 | 5400209 | 2 | 1 |
A | 556962.1 | 5400129 | 2 | 1 |
A | 556981.3 | 5400065 | 2 | 1 |
A | 556892.6 | 5400059 | 2 | 1 |
group_polys
The group_polys
function groups individuals whose home ranges intersect. This represents the coarsest grouping method, to provide a measure of overlap across seasons, years or all available relocations. It can either return the proportion of home range area overlapping between individuals or simple groups. Home ranges are calculated using adehabitatHR::kernelUD
or adehabitatHR::mcp
. Alternatively, a SpatialPolygonsDataFrame
can be input to the spPolys
argument.
utm <- '+proj=utm +zone=21 ellps=WGS84'
group_times(DT = DT, datetime = 'datetime', threshold = '8 days')
group_polys(DT = DT, area = TRUE, hrType = 'mcp',
hrParams = list('percent' = 95),
projection = utm,
coords = c('X', 'Y'), id = 'ID')
ID1 | ID2 | area | proportion |
---|---|---|---|
A | A | 974107.0 | 1.0000000 |
A | B | 282558.6 | 0.2900694 |
A | C | 525583.9 | 0.5395546 |
B | A | 282558.6 | 0.1201201 |
B | B | 2352300.8 | 1.0000000 |
B | C | 190150.7 | 0.0808360 |
C | A | 525583.9 | 0.2401272 |
C | B | 190150.7 | 0.0868755 |
C | C | 2188772.8 | 1.0000000 |
Package dependencies for spatsoc
are sp
, rgeos
, igraph
, adehabitatHR
and data.table
. data.table
provides efficient methods for manipulating large (or small) datasets. As a result, input DT
for all spatsoc
functions must be a data.table
and if it isn’t, you can simply use setDT(df)
to convert it by reference.
In addition, since the rgeos
package is used in most functions (group_lines
and group_polys
) the input DT
’s coordinate system is important. rgeos
expects planar coordinates and this requirement is carried forward for spatsoc
. Since rgeos
is used, system dependencies include GEOS
.