R/RcppExports.R

Defines functions makeSigma makeMu smooth_rcpp sample_path_mr2 sample_path_mr kalman_rcpp getQ

Documented in kalman_rcpp makeMu makeSigma sample_path_mr sample_path_mr2 smooth_rcpp

# Generated by using Rcpp::compileAttributes() -> do not edit by hand
# Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393

getQ <- function(nbStates, rateparam, time, lng, lat, group, model) {
    .Call('_MSctmm_getQ', PACKAGE = 'MSctmm', nbStates, rateparam, time, lng, lat, group, model)
}

#' Kalman filter
#'
#' This code is adapted from the packages ctmm (Calabrese et al., 2016) crawl (Johnson et al., 2008),
#' and MScrawl (Michelot and Blackwell, 2019).
#'
#' @name kalman_rcpp
#' @param data Matrix of data, including columns `x`, `y`, `time`, `ID` and `state` (in that order).
#' @param nbStates Integer number of states.
#' @param param Vector of movement parameters (`tau_vel`, `tau_pos`, and `sigma`)
#' @param fixmu Vector of mean locations for the OUF process (`x`, `y`)
#' @param Hmat Matrix of observation error variance (four columns, and one row for each row of data)
#'
#' @return Log-likelihood
#'
#' @references
#' Calabrese, J.M., Fleming, C.H. and Gurarie, E. (2016).
#' ctmm: an r package for analyzing animal relocation data as a continuous‐time stochastic process.
#' Methods Ecol Evol, 7: 1124-1132. doi:10.1111/2041-210X.12559
#'
#' Fleming, C.H., Sheldon, D., Gurarie, E., Fagan, W.F., LaPoint, S., Calabrese, J.M. (2017).
#' Kálmán filters for continuous-time movement models.
#' Ecol Inform, 40: 8-21. doi:10.1016/j.ecoinf.2017.04.008
#'
#' Johnson, D.S., London, J.M., Lea, M.A., and Durban, J.W. (2008).
#' Continuous-time correlated random walk model for animal telemetry data.
#' Ecology, 89: 1208-1215. doi:10.1890/07-1032.1
#'
#' Michelot, T., Blackwell, P.G. (2019).
#' State‐switching continuous‐time correlated random walks.
#' Methods Ecol Evol, 10: 637-649. doi:10.1111/2041-210X.13154
#'
#' @export
kalman_rcpp <- function(data, nbStates, param, fixmu, Hmat) {
    .Call('_MSctmm_kalman_rcpp', PACKAGE = 'MSctmm', data, nbStates, param, fixmu, Hmat)
}

#' Simulate a sample path from an endpoint conditioned CTMC by modified
#' rejection sampling.
#'
#' @param a,b States at the interval endpoints, provided as integers
#'    corresponding to rows of the CTMC rate matrix.
#' @param t0,t1 times of the interval endpoints
#' @param Q CTMC rate matrix
#'
#' @return matrix whose first column is the sequence of transition times
#' bookended by interval endpoints, and whose second column is the sequence of
#' states
#'
#' Modified from sample_path_mr in ECctmc (Fintzi, 2018)
sample_path_mr <- function(a, b, t0, t1, Q, k) {
    .Call('_MSctmm_sample_path_mr', PACKAGE = 'MSctmm', a, b, t0, t1, Q, k)
}

#' Simulate a sample path from an endpoint conditioned CTMC by modified
#' rejection sampling.
#'
#' @param a,b States at the interval endpoints, provided as integers
#'    corresponding to rows of the CTMC rate matrix.
#' @param t0,t1 times of the interval endpoints
#'
#' @return matrix whose first column is the sequence of transition times
#' bookended by interval endpoints, and whose second column is the sequence of
#' states
#'
#' Modified from sample_path_mr in ECctmc (Fintzi, 2018)
sample_path_mr2 <- function(a, b, t0, t1, lng0, lat0, lng1, lat1, group, k, nbStates, param, mu, Hmat, rateparam, model) {
    .Call('_MSctmm_sample_path_mr2', PACKAGE = 'MSctmm', a, b, t0, t1, lng0, lat0, lng1, lat1, group, k, nbStates, param, mu, Hmat, rateparam, model)
}

#' Kalman smoother
#'
#' This code is adapted from the package ctmm (Calabrese et al., 2016) crawl (Johnson et al., 2008),
#' and MScrawl (Michelot and Blackwell, 2019).
#'
#' @name smooth_rcpp
#' @param data Matrix of data, including columns `x`, `y`, `time`, `ID` and `state` (in that order).
#' @param param Vector of movement parameters (`tau_vel`, `tau_pos`, and `sigma`)
#' @param fixmu Vector of mean locations for the OUF process (`x`, `y`)
#' @param Hmat Matrix of observation error variance (four columns, and one row
#' for each row of data)
#'
#' @return a named List containing the predicted locations and velocities, and variance of these estimates.
#'
#' @references
#' Calabrese, J.M., Fleming, C.H. and Gurarie, E. (2016).
#' ctmm: an r package for analyzing animal relocation data as a continuous‐time stochastic process.
#' Methods Ecol Evol, 7: 1124-1132. doi:10.1111/2041-210X.12559
#'
#' Fleming, C.H., Sheldon, D., Gurarie, E., Fagan, W.F., LaPoint, S., Calabrese, J.M. (2017).
#' Kálmán filters for continuous-time movement models.
#' Ecol Inform, 40: 8-21. doi:10.1016/j.ecoinf.2017.04.008
#'
#' Johnson, D.S., London, J.M., Lea, M.A., and Durban, J.W. (2008).
#' Continuous-time correlated random walk model for animal telemetry data.
#' Ecology, 89: 1208-1215. doi:10.1890/07-1032.1
#'
#' Michelot, T., Blackwell, P.G. (2019).
#' State‐switching continuous‐time correlated random walks.
#' Methods Ecol Evol, 10: 637-649. doi:10.1111/2041-210X.13154
#'
#' @export
smooth_rcpp <- function(data, nbStates, param, fixmu, Hmat) {
    .Call('_MSctmm_smooth_rcpp', PACKAGE = 'MSctmm', data, nbStates, param, fixmu, Hmat)
}

#' Make mu matrix
#'
#' This code is adapted from the langevin function in the R package ctmm (Calabrese et al., 2016).
#' It is an R wrapper for the internal makeT function
#'
#' @name makeMu
#' @param tau_pos Parameter \eqn{tau[pos]} of the movement process
#' @param tau_vel Parameter \eqn{tau[vel]} of the movement process
#' @param dt Time interval
#'
#' @return Green's Function matrix
#'
#' @references
#' Calabrese, J.M., Fleming, C.H. and Gurarie, E. (2016).
#' ctmm: an r package for analyzing animal relocation data as a continuous‐time stochastic process.
#' Methods Ecol Evol, 7: 1124-1132. doi:10.1111/2041-210X.12559
#'
#' @export
makeMu <- function(tau_pos, tau_vel, dt) {
    .Call('_MSctmm_makeMu', PACKAGE = 'MSctmm', tau_pos, tau_vel, dt)
}

#' Make covariance matrix
#'
#' This code is adapted from the langevin function in the R package ctmm (Calabrese et al., 2016).
#' It is an R wrapper for the internal makeQ function
#'
#' @name makeSigma
#' @param tau_pos Parameter \eqn{tau[pos]} of the movement process
#' @param tau_vel Parameter \eqn{tau[vel]} of the movement process
#' @param sigma Parameter \eqn{sigma} of the movement process
#' @param dt Time interval
#'
#' @return Covariance Matrix
#'
#' @references
#' Calabrese, J.M., Fleming, C.H. and Gurarie, E. (2016).
#' ctmm: an r package for analyzing animal relocation data as a continuous‐time stochastic process.
#' Methods Ecol Evol, 7: 1124-1132. doi:10.1111/2041-210X.12559
#'
#' This code is adapted from the langevin function in the R package ctmm (Calabrese et al., 2016).
#' @export
makeSigma <- function(tau_pos, tau_vel, sigma, dt) {
    .Call('_MSctmm_makeSigma', PACKAGE = 'MSctmm', tau_pos, tau_vel, sigma, dt)
}

# Register entry points for exported C++ functions
methods::setLoadAction(function(ns) {
    .Call('_MSctmm_RcppExport_registerCCallable', PACKAGE = 'MSctmm')
})
dylanirion/MSctmm documentation built on Sept. 27, 2024, 3:41 a.m.