prepData {momentuHMM} | R Documentation |
Preprocessing of the data streams and covariates
Description
Preprocessing of the data streams, including calculation of step length, turning angle, and covariates from location data to be suitable for
analysis using fitHMM
.
Usage
prepData(data, ...)
## Default S3 method:
prepData(
data,
type = c("UTM", "LL"),
coordNames = c("x", "y"),
covNames = NULL,
spatialCovs = NULL,
centers = NULL,
centroids = NULL,
angleCovs = NULL,
altCoordNames = NULL,
...
)
## S3 method for class 'hierarchical'
prepData(
data,
type = c("UTM", "LL"),
coordNames = c("x", "y"),
covNames = NULL,
spatialCovs = NULL,
centers = NULL,
centroids = NULL,
angleCovs = NULL,
altCoordNames = NULL,
hierLevels,
coordLevel,
...
)
Arguments
data |
Either a data frame of data streams or a |
... |
further arguments passed to or from other methods |
type |
|
coordNames |
Names of the columns of coordinates in the |
covNames |
Character vector indicating the names of any covariates in |
spatialCovs |
List of |
centers |
2-column matrix providing the x-coordinates (column 1) and y-coordinates (column 2) for any activity centers (e.g., potential
centers of attraction or repulsion) from which distance and angle covariates will be calculated based on the location data. If no row names are provided, then generic names are generated
for the distance and angle covariates (e.g., 'center1.dist', 'center1.angle', 'center2.dist', 'center2.angle'); otherwise the covariate names are derived from the row names
of |
centroids |
List where each element is a data frame containing the x-coordinates ('x'), y-coordinates ('y'), and times (with user-specified name, e.g., ‘time’) for centroids (i.e., dynamic activity centers where the coordinates can change over time)
from which distance and angle covariates will be calculated based on the location data. If any centroids are specified, then |
angleCovs |
Character vector indicating the names of any circular-circular regression angular covariates in |
altCoordNames |
Character string indicating an alternative name for the returned location data. If provided, then |
hierLevels |
Character vector indicating the levels of the hierarchy and their order, from top (coarsest scale) to bottom (finest scale), that are included in |
coordLevel |
Character string indicating the level of the hierarchy for the location data. If specified, then |
Details
If
data
is acrwData
(orcrwHierData
) object, themomentuHMMData
(ormomentuHierHMMData
) object created byprepData
includes step lengths and turning angles calculated from the best predicted locations (i.e.,crwData$crwPredict$mu.x
andcrwData$crwPredict$mu.y
). Prior to usingprepData
, additional data streams or covariates unrelated to location (including z-values associated withspatialCovs
raster stacks or bricks) can be merged with thecrwData
(orcrwHierData
) object usingcrawlMerge
.For hierarchical data,
data
must include a 'level' field indicating the level of the hierarchy for each observation, and, for location data identified bycoordNames
, thecoordLevel
argument must indicate the level of the hierarchy at which the location data are obtained.
Value
An object momentuHMMData
or momentuHierHMMData
, i.e., a dataframe of:
ID |
The ID(s) of the observed animal(s) |
... |
Data streams (e.g., 'step', 'angle', etc.) |
x |
Either easting or longitude (if |
y |
Either norting or latitude (if |
... |
Covariates (if any) |
See Also
crawlMerge
, crawlWrap
, crwData
Examples
coord1 <- c(1,2,3,4,5,6,7,8,9,10)
coord2 <- c(1,1,1,2,2,2,1,1,1,2)
cov1 <- rnorm(10)
data <- data.frame(coord1=coord1,coord2=coord2,cov1=cov1)
d <- prepData(data,coordNames=c("coord1","coord2"),covNames="cov1")
# include additional data stream named 'omega'
omega <- rbeta(10,1,1)
data <- data.frame(coord1=coord1,coord2=coord2,omega=omega,cov1=cov1)
d <- prepData(data,coordNames=c("coord1","coord2"),covNames="cov1")
# include 'forest' example raster layer as covariate
data <- data.frame(coord1=coord1*1000,coord2=coord2*1000)
spatialCov <- list(forest=forest)
d <- prepData(data,coordNames=c("coord1","coord2"),spatialCovs=spatialCov)
# include 2 activity centers
data <- data.frame(coord1=coord1,coord2=coord2,cov1=cov1)
d <- prepData(data,coordNames=c("coord1","coord2"),covNames="cov1",
centers=matrix(c(0,10,0,10),2,2,dimnames=list(c("c1","c2"),NULL)))
# include centroid
data <- data.frame(coord1=coord1,coord2=coord2,cov1=cov1,time=1:10)
d <- prepData(data,coordNames=c("coord1","coord2"),covNames="cov1",
centroid=list(centroid=data.frame(x=coord1+rnorm(10),
y=coord2+rnorm(10),
time=1:10)))
# Include angle covariate that needs conversion to
# turning angle relative to previous movement direction
u <- rnorm(10) # horizontal component
v <- rnorm(10) # vertical component
cov2 <- atan2(v,u)
data <- data.frame(coord1=coord1,coord2=coord2,cov1=cov1,cov2=cov2)
d <- prepData(data,coordNames=c("coord1","coord2"),covNames="cov1",
angleCovs="cov2")