-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathleader_direction_group.Rd
More file actions
181 lines (158 loc) · 6.84 KB
/
Copy pathleader_direction_group.Rd
File metadata and controls
181 lines (158 loc) · 6.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/leader_direction_group.R
\name{leader_direction_group}
\alias{leader_direction_group}
\title{Leadership along group direction}
\usage{
leader_direction_group(
DT = NULL,
group_direction = "group_direction",
coords = NULL,
group = "group",
crs = NULL,
geometry = "geometry",
return_rank = TRUE,
ties.method = NULL
)
}
\arguments{
\item{DT}{input data.table with group direction columns generated by
\code{direction_group} and centroid columns generated by
\code{centroid_group}}
\item{group_direction}{group_direction column name generated using
\code{direction_group}, default 'group_direction'}
\item{coords}{character vector of X coordinate and Y coordinate column names.
Note: the order is assumed X followed by Y column names}
\item{group}{group column name, generated by \code{group_pts}, default
'group'}
\item{crs}{numeric or character defining the coordinate reference
system to be passed to \link[sf:st_crs]{sf::st_crs}. For example, either
\code{crs = "EPSG:32736"} or \code{crs = 32736}. Used only if coords are provided,
see details under Interface}
\item{geometry}{simple feature geometry list column name, generated by
\code{\link[=get_geometry]{get_geometry()}}. Default 'geometry', see details under Interface}
\item{return_rank}{logical if rank distance should also be returned, default
TRUE}
\item{ties.method}{see \code{\link[data.table:frank]{?data.table::frank()}}}
}
\value{
\code{leader_direction_group} returns the input \code{DT} appended with a
\code{position_group_direction} column indicating the position along the group
direction in the units of the crs and, optionally when \code{return_rank = TRUE}, a \code{rank_position_group_direction} column indicating the ranked
position along the group direction.
A message is returned when \code{position_group_direction} or
\code{rank_position_group_direction} columns already exist in the input \code{DT},
because they will be overwritten.
See details for appending outputs using modify-by-reference in the
\href{https://docs.ropensci.org/spatsoc/articles/faq.html}{FAQ}.
}
\description{
Given the mean direction of a group of individuals, \code{leader_direction_group}
shifts the coordinate system to a new origin at the group centroid and
rotates the coordinate system by the mean direction to return each
individual's position along the mean direction, representing leadership in
terms of the front-back position in each group's mean direction. Relocation
data should be in two columns representing the X and Y coordinates, or in a
geometry column prepared by the helper function \code{\link[=get_geometry]{get_geometry()}}.
}
\details{
The function expects a \code{data.table} with relocation data appended with a
\code{group_direction} column from \code{\link[=direction_group]{direction_group()}} and group centroid columns
from \code{\link[=centroid_group]{centroid_group()}}.
The \code{DT} must be a \code{data.table}. If your data is a \code{data.frame}, you can
convert it by reference using \code{\link[data.table:setDT]{data.table::setDT()}} or by reassigning using
\code{\link[data.table:data.table]{data.table::data.table()}}.
The \code{group_direction} argument expects the names of columns in \code{DT} which
correspond to the mean group direction generated by \code{\link[=direction_group]{direction_group()}}. The
mean group direction column is expected in units of radians. The
\code{return_rank} argument controls if the rank of each individual's distance to
the group centroid is also returned. If \code{return_rank} is TRUE, the \code{group}
argument is required to specify the group column generated by \code{\link[=group_pts]{group_pts()}}.
The \code{ties.method} argument is passed to \code{\link[data.table:frank]{data.table::frank()}}, see details at
\code{\link[data.table:frank]{?data.table::frank()}}.
See below under "Interface" for details on providing coordinates.
}
\section{Interface}{
Two interfaces are available for providing coordinates:
\enumerate{
\item Provide \code{coords} and \code{crs}. The \code{coords} argument expects the names of
the X and Y coordinate columns. The \code{crs} argument expects a character
string or numeric defining the coordinate reference system to be passed to
\link[sf:st_crs]{sf::st_crs}. For example, for UTM zone 36S (EPSG 32736), the crs argument
is \code{crs = "EPSG:32736"} or \code{crs = 32736}. See \url{https://spatialreference.org}
for a list of EPSG codes.
\item (New!) Provide \code{geometry}. The \code{geometry} argument allows the user to
supply a \code{geometry} column that represents the coordinates as a simple
feature geometry list column. This interface expects the user to prepare
their input DT with \code{\link[=get_geometry]{get_geometry()}}. To use this interface, leave the
\code{coords} and \code{crs} arguments \code{NULL}, and the default argument for \code{geometry}
('geometry') will be used directly.
}
}
\examples{
# Load data.table
library(data.table)
\dontshow{data.table::setDTthreads(1)}
# 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')]
\dontshow{
# (Subset example data to reduce runtime on CRAN)
if (isFALSE(rlang::is_interactive())) {
DT <- DT[as.Date(datetime) == '2017-01-17']
}
}
# 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'),
crs = 32736
)
# Calculate group centroid
centroid_group(DT, coords = c('X', 'Y'))
# Calculate group direction
direction_group(DT)
# Calculate leader in terms of position along group direction
leader_direction_group(DT, coords = c('X', 'Y'), crs = 32736)
# Or, using the new geometry interface
get_geometry(DT, coords = c('X', 'Y'), crs = 32736)
direction_step(DT = DT, id = 'ID')
centroid_group(DT)
direction_group(DT)
leader_direction_group(DT)
}
\references{
See examples of measuring leadership along group direction (also called
forefront index):
\itemize{
\item \doi{doi:10.1371/journal.pone.0036567}
\item \doi{doi:10.1111/jfb.15315}
\item \doi{doi:10.1098/rspb.2021.0839}
}
}
\seealso{
\code{direction_group}, \code{centroid_group}
Other Leadership functions:
\code{\link{direction_to_leader}()},
\code{\link{leader_edge_delay}()}
Other Direction functions:
\code{\link{direction_group}()},
\code{\link{direction_polarization}()},
\code{\link{direction_step}()},
\code{\link{direction_to_centroid}()},
\code{\link{direction_to_leader}()},
\code{\link{edge_alignment}()},
\code{\link{edge_delay}()},
\code{\link{edge_direction}()},
\code{\link{edge_zones}()},
\code{\link{leader_edge_delay}()}
}
\concept{Direction functions}
\concept{Leadership functions}