Skip to content

Commit

Permalink
prep CRAN submission
Browse files Browse the repository at this point in the history
  • Loading branch information
jmsigner committed Feb 7, 2018
1 parent e661ad6 commit 3abe4b4
Show file tree
Hide file tree
Showing 52 changed files with 280 additions and 359 deletions.
10 changes: 3 additions & 7 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
Package: amt
Type: Package
Title: Animal Movement Tools
Version: 0.0.1.9000
Authors@R: c(person("Johannes","Signer", role = c("aut", "cre"), email = "jmsigner@gmail.com"))
Description: A collection of functions to work with animal movement data.
The functionality includes methods to resample movement to regular sampling rates,
calculate track statistics (e.g. step lengths, speed, or turning angles),
prepare data for fitting habitat selection analyses (resource and step selection functions),
and interface other packages.
Version: 0.0.2.0
Authors@R: c(person("Johannes","Signer", role = c("aut", "cre"), email = "jsigner@gwdg.de"))
Description: amt (animal movement tools), provides a collection of functions to work with animal movement data. The functionality includes methods to resample movement to regular sampling rates, calculate track statistics (e.g. step lengths, speed, or turning angles), prepare data for fitting habitat selection analyses (resource and step-selection functions), and simulation of space-use from fitted step-selection functions.
License: GPL-3
Encoding: UTF-8
LazyData: true
Expand Down
12 changes: 6 additions & 6 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ S3method(arrange,steps)
S3method(arrange,track_xy)
S3method(arrange,track_xyt)
S3method(as_bcpa,track_xyt)
S3method(as_ctmm,track_xyt)
S3method(as_ltraj,track_xy)
S3method(as_ltraj,track_xyt)
S3method(as_move,track_xy)
Expand Down Expand Up @@ -119,6 +118,8 @@ S3method(ta_distr,random_steps)
S3method(ta_params,fit_clogit)
S3method(ta_params,random_steps)
S3method(tac,track_xy)
S3method(time_of_day,steps)
S3method(time_of_day,track_xyt)
S3method(to,track_xyt)
S3method(tot_dist,track_xy)
S3method(track_resample,track_xyt)
Expand All @@ -131,7 +132,6 @@ export(adjust_kappa)
export(adjust_scale)
export(adjust_shape)
export(as_bcpa)
export(as_ctmm)
export(as_ltraj)
export(as_move)
export(as_moveHMM)
Expand All @@ -143,7 +143,6 @@ export(centroid)
export(coords)
export(cum_dist)
export(cumulative_ud)
export(day_night)
export(diff_x)
export(diff_y)
export(direction_abs)
Expand All @@ -153,9 +152,12 @@ export(distance_to_centers)
export(extract_covariates)
export(filter_min_n_burst)
export(fit_clogit)
export(fit_issf)
export(fit_logit)
export(fit_rsf)
export(fit_sl_dist)
export(fit_sl_dist_base)
export(fit_ssf)
export(fit_ta_dist)
export(fit_ta_dist_base)
export(from)
Expand All @@ -170,7 +172,6 @@ export(hr_locoh_k)
export(hr_mcp)
export(inspect)
export(intensity_use)
export(issf_to_ud)
export(mk_track)
export(movement_kernel)
export(msd)
Expand All @@ -179,7 +180,6 @@ export(plot_sl)
export(random_points)
export(random_steps)
export(remove_capture_effect)
export(screen_relocations)
export(simulate_ud)
export(sinuosity)
export(sl_distr)
Expand All @@ -196,10 +196,10 @@ export(ta_distr)
export(ta_kappa)
export(ta_params)
export(tac)
export(time_of_day)
export(to)
export(tot_dist)
export(track)
export(track_immobile_base)
export(track_resample)
export(transform_coords)
export(velocity)
Expand Down
16 changes: 6 additions & 10 deletions R/adjust_parameters.R
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
#' Adjust parameters
#'
#' Functions aiding parameter adjustment after fitting an integrated step
#' selection function (iSSF).
#' Functions for parameter adjustment after fitting an integrated step-selection function (iSSF).
#'
#' Currently the shape and scale parameter of a Gamma distribution and the
#' concentration parameter (=kappa) of a von-Mises distribution can be adjusted.
#' When fitting a integrated step selection model, the tentative shape parameter
#' of the Gamma distribution of the step length can be adjusted with the
#' coefficients of the log of step lengths, the scale of the Gamma distribution
#' can be adjusted with the step lengths, and the kappa parameter of the von
#' Mises distribution can be adjusted with the coefficient for the cosine of the
#' turn angle.
#' The shape and scale parameter of a gamma distribution, and the
#' concentration parameter (=kappa) of a von-Mises distribution can be adjusted. The following adjustments are possible:
#' 1. The shape parameter of a gamma distribution fitted to the observed step lengths, can be adjusted with the coefficient for the log of the step lenghts.
#' 2. The scale parameter of a gamma distribution fitted to the observed step lengths, can be adjusted with the coefficient for the step lenghts.
#' 3. The concentration parameter of fa von Mises distribution fitted to the observed turning angle, can be adjusted with the coefficient for the cosine of turning angles.
#'
#' @examples
#' # Using the deer data set
Expand Down
2 changes: 1 addition & 1 deletion R/as_track.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#' Coerce to track.
#' Coerce to track
#'
#' Coerce other classes (currently implemented: `SpatialPoints`) to a `track_xy`.
#' @export
Expand Down
31 changes: 16 additions & 15 deletions R/coercion.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#' Coerce a track to other formats.
#'
#' Several other packages provides methods to analyse movement data, and `amt` provides coercion methods to some packages.
#' Several other packages provides methods to analyse movement data, and `amt` provides coercion methods to some packages
#'
#' @template track_xy_star
#' @param id `[numeric,character,factor]` \cr Animal id(s).
Expand Down Expand Up @@ -129,20 +129,21 @@ as_bcpa.track_xyt <- function(x, ...) {
}

# as_ctmm -----------------------------------------------------------------
#' @export
#' @rdname coercion
#' @examples
#' data(deer)
#' as_ctmm(deer)
as_ctmm <- function(x, ...) {
UseMethod("as_ctmm", x)
}

#' @export
#' @rdname coercion
as_ctmm.track_xyt <- function(x, ...) {
ctmm::as.telemetry(as_move(x, ...))
}
# TODO
# #' @export
# #' @rdname coercion
# #' @examples
# #' data(deer)
# #' as_ctmm(deer)
# as_ctmm <- function(x, ...) {
# UseMethod("as_ctmm", x)
# }
#
# #' @export
# #' @rdname coercion
# as_ctmm.track_xyt <- function(x, ...) {
# ctmm::as.telemetry(as_move(x, ...))
# }


# as_moveHMM --------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion R/data-animal_sim.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#' Simulated movement data of 1 animal.
#'
#' 32400 simulated relocations of an animal.
#' 32400 simulated relocations of an animal
#'
#' @format A `data_frame` with 32400 rows and 3 variables:
#' \describe{
Expand Down
6 changes: 3 additions & 3 deletions R/data-sh.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#' Relocations of 1 red deer.
#' Relocations of 1 red deer
#'
#' 1500 GPS relocations of one red deer from northern Germany.
#'
Expand All @@ -12,7 +12,7 @@
#' @source Verein für Wildtierforschung Dresden und Göttingen e.V.
"sh"

#' Forest cover.
#' Forest cover
#'
#' Forest cover for the home range of one red deer in northern Germany.
#'
Expand All @@ -23,7 +23,7 @@
#' data.
"sh_forest"

#' Relocations of 1 red deer.
#' Relocations of 1 red deer
#'
#' 826 GPS relocations of one red deer from northern Germany. The data is
#' already resampled to a regular time interval of 6 hours and the coordinate
Expand Down
52 changes: 0 additions & 52 deletions R/day_night.R

This file was deleted.

2 changes: 1 addition & 1 deletion R/distance_to_center.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#' Distance to center.
#' Distance to center
#'
#' Distances to frequently used areas. `distance_to_center` calculates the
#' distance to the home-range center (i.e., the centroid of the `x` and `y`
Expand Down
6 changes: 3 additions & 3 deletions R/extract_covariates.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#' Extract covariate values.
#' Extract covariate values
#'
#' Extract the covariate values at relocations, or at the beginning or end of
#' steps.
Expand Down Expand Up @@ -39,9 +39,9 @@ extract_covariates.random_points <- function(x, covariates, ...) {
extract_covariates.steps <- function(x, covariates, where = "end", ...) {
if (class(covariates) %in% paste0("Raster", c("Layer", "Stack", "Brick"))) {
if (where == "both") {
x_start <- raster::extract(covariates, x[, c("x1_", "y1_")], df = TRUE)[, -1]
x_start <- raster::extract(covariates, x[, c("x1_", "y1_")], df = TRUE)[, -1, drop = FALSE]
names(x_start) <- paste0(names(x_start), "_start")
x_end <- raster::extract(covariates, x[, c("x2_", "y2_")], df = TRUE)[, -1]
x_end <- raster::extract(covariates, x[, c("x2_", "y2_")], df = TRUE)[, -1, drop = FALSE]
names(x_end) <- paste0(names(x_end), "_end")
x_all <- cbind(x_start, x_end)
x[names(x_all)] <- x_all
Expand Down
9 changes: 9 additions & 0 deletions R/fit_clogit.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#' @param more `[list]` \cr Optional list that is passed on the output.
#' @param summary_only `[logical(1)=FALSE]` \cr If `TRUE` only a `broom::tidy` summary of the model is returned.
#' @param ... Additional arguments, passed to `survival::clogit`.
#' @name fit_clogit
#' @export

fit_clogit <- function(data, formula, more = NULL, summary_only = FALSE, ...) {
Expand Down Expand Up @@ -39,3 +40,11 @@ summary.fit_clogit <- function(object, ...) {
base::summary(object$model, ...)
}


#' @rdname fit_clogit
#' @export
fit_ssf <- fit_clogit

#' @rdname fit_clogit
#' @export
fit_issf <- fit_clogit
2 changes: 1 addition & 1 deletion R/fit_distr.R
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ plot_sl.fit_clogit <- function(x, n = 1000, ...) {
}

# turning angles ----------------------------------------------------------
#' Fit a statistical distribution to the turn angles of a track.
#' Fit a statistical distribution to the turn angles of a track
#'
#' @param .tbl `[track_xy,track_xyt]` \cr A track.
#' @param x `[expression]` \cr The name of the column containing turn angles, usually `ta_`.
Expand Down
5 changes: 5 additions & 0 deletions R/fit_logit.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#' @param data `[data.frame]` \cr The data used to fit a model.
#' @param formula `[formula]` \cr The model formula.
#' @param ... Further arguments passed to `stats::glm`.
#' @name fit_logit
#' @export
fit_logit <- function(data, formula, ...) {
m <- stats::glm(formula, data = data, family = stats::binomial(link = "logit"), ...)
Expand All @@ -22,3 +23,7 @@ coef.fit_logit <- function(object, ...) {
summary.fit_logit <- function(object, ...) {
base::summary(object$model, ...)
}

#' @rdname fit_logit
#' @export
fit_rsf <- fit_logit
2 changes: 1 addition & 1 deletion R/helper.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#' Converts angles to radians.
#' Converts angles to radians
#'
#' @param x `[numeric]`\cr Angles in degrees.
#' @export
Expand Down
3 changes: 2 additions & 1 deletion R/movement_kernel.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#' @param scale,shape `[numeric](1)\cr` Scale and scale parameter of the gamma distribution of step lengths.
#' @param scale,shape `[numeric](1)`\cr Scale and scale parameter of the gamma distribution of step lengths.
#' @param quant A numeric scalar, quantile of the step-length distribution that is
#' the maximum movement distance.
#' @param template `[RasterLayer,RasterStack]`\cr A raster serving as template for the simulations.
#' @details **`movement_kernel()`:** calculates a movement kernel from a fitted
#' (i)SSF. The method is currently only implemented for the gamma
#' distribution.
Expand Down
6 changes: 5 additions & 1 deletion R/random_steps.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,12 @@ random_steps.steps <- function(x, n_control = 10, sl_distr = "gamma", ta_distr =

sl <- fit_sl_dist_base(x$sl_, distr = sl_distr)
ta <- fit_ta_dist_base(x$ta_, distr = ta_distr)
random_steps_base(x, n_control, sl, ta)
xx <- random_steps_base(x, n_control, sl, ta)
attr(xx, "crs_") <- attr(x, "crs_")
xx
}


random_steps_base <- function(x, n_control, sl, ta) {
# Generate random points
ns <- nrow(x) # number of steps
Expand Down Expand Up @@ -101,6 +104,7 @@ rsteps_transfer_attr <- function(from, to) {
attributes(to)$class <- from$class
attributes(to)$sl_ <- from$sl_
attributes(to)$ta_ <- from$ta_
attributes(to)$crs_ <- from$crs_
to
}

Expand Down
30 changes: 15 additions & 15 deletions R/screen_relocations.R
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
#' Screen relocations
#'
#' Function to screen relocations for possible errors. The algorithm was first described by Bjorneraas et al. 2010.
#'
#' @param x A `track_xyt`
#' @param median_crit `[numeric(1)]{>0}` \cr Threshold for the median (in m).
#' @param mean_crit `[numeric(1)]{>0}` \cr Threshold for the mean (in m).
#' @param spike_speed `[numeric(1)]{>0}` \cr Threshold spike speed in m/s.
#' @param spike_cos `[numeric(1)]{>0}` \cr Threshold for the cosine.
#' @param window `[numeric(1)=10]{>2}` \cr Window width.
#' @export
#'
#' @examples
#' data(deer)
#' screen_relocations(deer, 100, 100, 0.1, 0.3, 10)
# #' Screen relocations
# #'
# #' Function to screen relocations for possible errors. The algorithm was first described by Bjorneraas et al. 2010.
# #'
# #' @param x A `track_xyt`
# #' @param median_crit `[numeric(1)]{>0}` \cr Threshold for the median (in m).
# #' @param mean_crit `[numeric(1)]{>0}` \cr Threshold for the mean (in m).
# #' @param spike_speed `[numeric(1)]{>0}` \cr Threshold spike speed in m/s.
# #' @param spike_cos `[numeric(1)]{>0}` \cr Threshold for the cosine.
# #' @param window `[numeric(1)=10]{>2}` \cr Window width.
# #' @export
# #'
# #' @examples
# #' data(deer)
# #' screen_relocations(deer, 100, 100, 0.1, 0.3, 10)


screen_relocations <- function(x, median_crit, mean_crit, spike_speed, spike_cos, window) {
Expand Down
Loading

0 comments on commit 3abe4b4

Please sign in to comment.