View source: R/direction_polarization.R
direction_polarization | R Documentation |
direction_polarization
calculates the polarization of individual
directions in each spatiotemporal group identified by group_pts
. The
function expects a data.table
with relocation data appended with a
direction
column from direction_step
and a group
column
from group_pts
.
direction_polarization(DT, direction = "direction", group = "group")
DT |
input data.table with direction column generated by
|
direction |
character string of direction column name, default "direction" |
group |
character string of group column name, default "group" |
The DT
must be a data.table
. If your data is a
data.frame
, you can convert it by reference using
data.table::setDT
or by reassigning using
data.table::data.table
.
The direction
and group
arguments expect the names of columns
in DT
which correspond to the direction and group columns. The
direction column is expected in units of radians and the polarization is
calculated with CircStats::r.test()
.
direction_polarization
returns the input DT
appended
with a polarization
column representing the direction polarization
of all individuals in each spatiotemporal group.
The direction polarization is calculated using CircStats::r.test()
which expects units of radians.
A message is returned when the polarization
columns already
exists in the input DT
, because it will be overwritten.
See examples of using polarization:
direction_step
, group_pts
,
CircStats::r.test()
Other Direction functions:
direction_group()
,
direction_step()
,
direction_to_leader()
,
edge_delay()
# 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')
# Spatial grouping with timegroup
group_pts(DT, threshold = 50, id = 'ID',
coords = c('X', 'Y'), timegroup = 'timegroup')
# Calculate direction at each step
direction_step(
DT = DT,
id = 'ID',
coords = c('X', 'Y'),
projection = 32736
)
# Calculate polarization
direction_polarization(DT)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.