R/RcppExports.R

Defines functions toUnitScale fromUnitScale model_trajectory_cpp model_func_group_cpp obs_error norm_error obs_likelihood posterior_func_group_cpp posterior_func_group_cpp_matrix

Documented in fromUnitScale model_func_group_cpp model_trajectory_cpp norm_error obs_error obs_likelihood posterior_func_group_cpp toUnitScale

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

#' Converts to unit scale
#'
#' @param x the double to be converted
#' @param min the minimum value on the linear scale
#' @param max the maximum value on the linear scale
#' @return the value converted to a unit scale
#' @export
toUnitScale <- function(x, min, max) {
    .Call('_antibodyKinetics_toUnitScale', PACKAGE = 'antibodyKinetics', x, min, max)
}

#' Converts to linear scale
#'
#' @param x the double to be converted back to linear scale
#' @param min the minimum value on the linear scale
#' @param max the maximum value on the linear scale
#' @return the value converted to a linear scale
#' @export
fromUnitScale <- function(x, min, max) {
    .Call('_antibodyKinetics_fromUnitScale', PACKAGE = 'antibodyKinetics', x, min, max)
}

#' Model trajectory calc cpp
#'
#' Calculates the ferret model trajectory for a single infection event.
#' Uses a Cpp implementation for speed. Need to obey order of parameters as in the
#' example. Run \code{\link{parameter_descriptions}} for documentation of the model parameter vector
#' @param pars the vector of model parameters
#' @param times the vector of time in days to solve over
#' @return a vector of antibody titres
#' @export
#' @family model functions
#' @useDynLib antibodyKinetics
#' @examples
#' pars <- c("lower_bound"=0,"S"=1,"EA"=0,"MAX_TITRE"=13,
#'           "mu"=8,"tp"=12,"dp"=0.5,"ts"=10,"m"=0.003,"beta"=0.6, "c"=4,
#'           "sigma"=1,"y0_mod"=-20,"boost_limit"=-1,"tau"=0.05,
#'           "order"=1, "primed"=0,"mod"=1,
#'           "x"=0,"t_i"=10,"y0"=0,"eff_y0"=0)
#' times <- seq(0,100,by=1)
#' y <- model_trajectory_cpp(pars,times)
#' @export
model_trajectory_cpp <- function(pars, times) {
    .Call('_antibodyKinetics_model_trajectory_cpp', PACKAGE = 'antibodyKinetics', pars, times)
}

#' Model calculation cpp implementation
#'
#' Solves the antibody kinetics model for given parameters. This is a complex function, 
#' so should only really be called through \code{\link{create_model_group_func_cpp}}. 
#' Look at this code to really understand what's going on! The key confusing thing is 
#' that the length of the vectors has to match the number of rows from the overall 
#' parameter table
#' @param pars the vector of model parameters as in parTab
#' @param times the vector of times to solve the model over
#' @param groups IntegerVector of the exposure groups (starting at group 1)
#' @param strains IntegerVector of strains involved in exposures (ie. observed and exposed), starting at 1
#' @param exposure_indices IntegerVector of indices from the exposure table
#' @param exposure_i_lengths IntegerVector of lengths describing the size of blocks in the exposure_indices vector that relate to each exposure group
#' @param strain_indices IntegerVector of indices relating to the exposure table, with contiguous indices for each group and then each strain
#' @param strain_i_lengths IntegerVector of lengths describing the size of blocks in the strain_indices vector that relate to each strain and group
#' @param exposure_times NumericVector infection time of each exposure
#' @param exposure_strains IntegerVector of exposure strains for each exposure
#' @param exposure_next NumericVector specifying the time of the exposure after the current one (for subsetting times)
#' @param exposure_measured IntegerVector of measured strain for each exposure
#' @param exposure_orders IntegerVector of order of exposures
#' @param exposure_primes IntegerVector of whether each exposure was primed or not (for priming modifier)
#' @param cr_inds IntegerVector of indices describing which parTab rows relate to cross reactivity parameters
#' @param par_inds IntegerVector of indices describing which parTab rows relate to model parameters
#' @param par_names CharacterVector names from parTab
#' @param order_inds IntegerVector of indices describing which parTab rows relate to order modifer parameters
#' @param exposure_i_lengths IntegerVector of lengths describing the size of blocks in the exposure_indices vector that relate to each exposure group
#' @param par_lengths IntegerVector of lengths describing the size of blocks in the par_type_ind vector that relate to each exposure type
#' @param cr_lengths IntegerVector of lengths describing the size of blocks in the cr_ind vector that relate to each strain
#' @param version integer indicating which version of the model will be solve. 0 solves the isolated form, and 1 solves the competitive exposure form.
#' @return a matrix of antibody kinetic trajectories, with rows for group and then strain
#' @export
#' @useDynLib antibodyKinetics
model_func_group_cpp <- function(pars, times, groups, strains, exposure_indices, exposure_i_lengths, strain_indices, strain_i_lengths, exposure_times, exposure_strains, exposure_next, exposure_measured, exposure_orders, exposure_primes, cr_inds, par_inds, par_names, order_inds, par_lengths, cr_lengths, version) {
    .Call('_antibodyKinetics_model_func_group_cpp', PACKAGE = 'antibodyKinetics', pars, times, groups, strains, exposure_indices, exposure_i_lengths, strain_indices, strain_i_lengths, exposure_times, exposure_strains, exposure_next, exposure_measured, exposure_orders, exposure_primes, cr_inds, par_inds, par_names, order_inds, par_lengths, cr_lengths, version)
}

#' Observation error matrix solver
#' 
#' Calculates a single likelihood for an observed titre given the true titre and observation error parameters
#' @param actual integer for the believed true titre
#' @param obs integer for the observed titre
#' @param S probability of observing the true titre
#' @param EA probability of a + or - 1 observation
#' @param MAX_TITRE integer for the maximum observable titre
#' @return a single probability value
#' @export
#' @useDynLib antibodyKinetics
obs_error <- function(actual, obs, S, EA, MAX_TITRE) {
    .Call('_antibodyKinetics_obs_error', PACKAGE = 'antibodyKinetics', actual, obs, S, EA, MAX_TITRE)
}

#' Discretised normal error
#'
#' Gives the probability of a titre observation given a true titre.
#' @param actual the assumed true titre
#' @param obs the observed titre
#' @param sd standard deviation of the observation error function
#' @param MAX_TITRE the maximum observable titre
#' @export
norm_error <- function(actual, obs, sd, MAX_TITRE) {
    .Call('_antibodyKinetics_norm_error', PACKAGE = 'antibodyKinetics', actual, obs, sd, MAX_TITRE)
}

#' Observation error function
#'
#' Given a vector of believed true titres and a vector of observed data, 
#' calculates a likelihood based on a given observation error matrix
#' @param y NumericVector of believed true titres
#' @param data NumericVector of observed data, matching y
#' @param params observation error matrix paramters in order S, EA, MAX_TITRE
#' @export
obs_likelihood <- function(y, data, params) {
    .Call('_antibodyKinetics_obs_likelihood', PACKAGE = 'antibodyKinetics', y, data, params)
}

#' Posterior calculation cpp implementation
#'
#' Solves the antibody kinetics model for given parameters, and then calculates a likelihood
#' for the given data set. This is a complex function, so should only really be called through
#' \code{\link{create_model_group_func_cpp}}. Lookx at this code to really understand what's
#' going on! The key confusing thing is that the length of the vectors has to match the number
#' of rows from the overall parameter table
#' @param pars the vector of model parameters as in parTab
#' @param times the vector of times to solve the model over
#' @param groups IntegerVector of the exposure groups (starting at group 1)
#' @param strains IntegerVector of strains involved in exposures (ie. observed and exposed), starting at 1
#' @param exposure_indices IntegerVector of indices from the exposure table
#' @param exposure_i_lengths IntegerVector of lengths describing the size of blocks in the exposure_indices vector that relate to each exposure group
#' @param strain_indices IntegerVector of indices relating to the exposure table, with contiguous indices for each group and then each strain
#' @param strain_i_lengths IntegerVector of lengths describing the size of blocks in the strain_indices vector that relate to each strain and group
#' @param exposure_times NumericVector infection time of each exposure
#' @param exposure_strains IntegerVector of exposure strains for each exposure
#' @param exposure_next NumericVector specifying the time of the exposure after the current one (for subsetting times)
#' @param exposure_measured IntegerVector of measured strain for each exposure
#' @param exposure_orders IntegerVector of order of exposures
#' @param exposure_primes IntegerVector of whether each exposure was primed or not (for priming modifier)
#' @param cr_inds IntegerVector of indices describing which parTab rows relate to cross reactivity parameters
#' @param par_inds IntegerVector of indices describing which parTab rows relate to model parameters
#' @param par_names CharacterVector names from parTab
#' @param order_inds IntegerVector of indices describing which parTab rows relate to order modifer parameters
#' @param exposure_i_lengths IntegerVector of lengths describing the size of blocks in the exposure_indices vector that relate to each exposure group
#' @param par_lengths IntegerVector of lengths describing the size of blocks in the par_type_ind vector that relate to each exposure type
#' @param cr_lengths IntegerVector of lengths describing the size of blocks in the cr_ind vector that relate to each strain
#' @param version integer indicating which version of the model will be solve. 0 solves the isolated form, and 1 solves the competitive exposure form.
#' @param individuals IntegerVector indicating how many individuals there are in each group
#' @param data NumericMatrix of antibody titre data. Each row should be complete observations of titres against a given strain for a given group. If we have 5 strains measured and 5 groups, rows 1:5 should be titres in group 1, rows 6:10 titres in group 3 etc. If more than 1 individual in each group, multiply these criteria by number of inidividuals in that group (ie., rows 1:15 for group 1)
#' @return a single likelihood of observing the data given the model parameters
#' @export
posterior_func_group_cpp <- function(pars, times, groups, strains, exposure_indices, exposure_i_lengths, strain_indices, strain_i_lengths, exposure_times, exposure_strains, exposure_next, exposure_measured, exposure_orders, exposure_primes, cr_inds, par_inds, par_names, order_inds, par_lengths, cr_lengths, version, individuals, data) {
    .Call('_antibodyKinetics_posterior_func_group_cpp', PACKAGE = 'antibodyKinetics', pars, times, groups, strains, exposure_indices, exposure_i_lengths, strain_indices, strain_i_lengths, exposure_times, exposure_strains, exposure_next, exposure_measured, exposure_orders, exposure_primes, cr_inds, par_inds, par_names, order_inds, par_lengths, cr_lengths, version, individuals, data)
}

posterior_func_group_cpp_matrix <- function(pars, times, groups, strains, exposure_indices, exposure_i_lengths, strain_indices, strain_i_lengths, exposure_times, exposure_strains, exposure_next, exposure_measured, exposure_orders, exposure_primes, cr_inds, par_inds, par_names, order_inds, par_lengths, cr_lengths, version, individuals, data) {
    .Call('_antibodyKinetics_posterior_func_group_cpp_matrix', PACKAGE = 'antibodyKinetics', pars, times, groups, strains, exposure_indices, exposure_i_lengths, strain_indices, strain_i_lengths, exposure_times, exposure_strains, exposure_next, exposure_measured, exposure_orders, exposure_primes, cr_inds, par_inds, par_names, order_inds, par_lengths, cr_lengths, version, individuals, data)
}
jameshay218/antibodyKinetics documentation built on Nov. 8, 2019, 11 a.m.