R/RcppExports.R

Defines functions exp_rej unif_rej halfnorm_rej norm_rej sample_tuvsn sample_case5 sample_case4 sample_case3 sample_case2 sample_case1 rtuvn rtmvn_gibbs lower_b2 lower_b1 lower_b

Documented in exp_rej halfnorm_rej lower_b lower_b1 lower_b2 norm_rej rtmvn_gibbs rtuvn sample_case1 sample_case2 sample_case3 sample_case4 sample_case5 sample_tuvsn unif_rej

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

#' lower bound for b - normal vs. uniform
#'
#' Calculates the lower bound in Lemma 2.1.1.4 in Li & Ghosh (2015). It is the
#'     bound for b case 2.
#'
#' @param a Lower bound of truncated univariate normal
#'
#' @return value of the bound for b
#'
#' @references Li, Y., & Ghosh, S. K. (2015). Efficient sampling methods for
#'     truncated multivariate normal and student-t distributions subject to
#'     linear inequality constraints. Journal of Statistical Theory and
#'     Practice, 9(4), 712-732.
#' @export
lower_b <- function(a) {
    .Call('_tmvn_lower_b', PACKAGE = 'tmvn', a)
}

#' lower bound for b - half-normal vs uniform
#'
#' Calculates the lower bound in 2.1.1.5 of Li and Ghosh. Called b_1(a) in the
#'     case breakdown
#'
#' @param a Lower bound of truncated univariate normal
#'
#' @return value of the bound for b
#'
#' @references Li, Y., & Ghosh, S. K. (2015). Efficient sampling methods for
#'     truncated multivariate normal and student-t distributions subject to
#'     linear inequality constraints. Journal of Statistical Theory and
#'     Practice, 9(4), 712-732.
#' @export
lower_b1 <- function(a) {
    .Call('_tmvn_lower_b1', PACKAGE = 'tmvn', a)
}

#' bound for b - exponential vs uniform sampling
#'
#' Calculates the bound for b in lemma 2.1.1.6 of Li & Ghosh. Called b_2(a)
#'     in the case breakdown.
#'
#' @param a Lower bound of truncated univariate normal
#'
#' @return value of the bound for b
#'
#' @references Li, Y., & Ghosh, S. K. (2015). Efficient sampling methods for
#'     truncated multivariate normal and student-t distributions subject to
#'     linear inequality constraints. Journal of Statistical Theory and
#'     Practice, 9(4), 712-732.
#' @export
lower_b2 <- function(a) {
    .Call('_tmvn_lower_b2', PACKAGE = 'tmvn', a)
}

#' Gibbs sampler for the Truncated Multivariate Normal Distribution
#'
#' Random vector generation for the truncated multivariate normal distribution
#'     using a Gibbs sampler.
#'
#' @param n number of samples to be generated
#' @param p dimension of the distribution to sample
#' @param R matrix of linear constraints
#' @param a vector of lower bounds
#' @param b vector of upper bounds
#' @param z vector of initial values for the Gibbs sampler.
#'
#' @return a matrix of samples with each column being an idependent sample.
#'
#' @references Li, Y., & Ghosh, S. K. (2015). Efficient sampling methods for
#'     truncated multivariate normal and student-t distributions subject to
#'     linear inequality constraints. Journal of Statistical Theory and
#'     Practice, 9(4), 712-732.
#' @export
rtmvn_gibbs <- function(n, p, Mean, Sigma_chol, R, a, b, z) {
    .Call('_tmvn_rtmvn_gibbs', PACKAGE = 'tmvn', n, p, Mean, Sigma_chol, R, a, b, z)
}

#' Univariate Truncated Normal Distribution
#'
#' Random number generator for the truncated normal distribution. To
#'     calculate the density please use dtuvn.
#'
#' @param n number of samples
#' @param mean mean
#' @param sd standard deviation
#' @param lower lower bound
#' @param upper upper bound
#' @return a vector of generated samples
#'
#' @references Li, Y., & Ghosh, S. K. (2015). Efficient sampling methods for
#'     truncated multivariate normal and student-t distributions subject to
#'     linear inequality constraints. Journal of Statistical Theory and
#'     Practice, 9(4), 712-732.
#'
#' @examples
#' # sample from truncated normal with mean 10, sd 20, and lower = 10, upper = 20
#' rtuvn(n = 1, mean = 10, sd = 20, lower = 10, upper = 20)
#'
#' @export
rtuvn <- function(n, mean, sd, lower, upper) {
    .Call('_tmvn_rtuvn', PACKAGE = 'tmvn', n, mean, sd, lower, upper)
}

#' Sample Case 1
#'
#' generate a sample from case 1 where the bounds are \eqn{[a, \infty)}.
#'    The cases are listed on page 4 of Li & Ghosh (2015).
#'
#' @param a Lower bound of truncation
#' @param b Upper bound of truncattion
#'
#' @return the value of the sample
#'
#' @references Li, Y., & Ghosh, S. K. (2015). Efficient sampling methods for
#'     truncated multivariate normal and student-t distributions subject to
#'     linear inequality constraints. Journal of Statistical Theory and
#'     Practice, 9(4), 712-732.
#' @export
sample_case1 <- function(a, b) {
    .Call('_tmvn_sample_case1', PACKAGE = 'tmvn', a, b)
}

#' Sample Case 2
#'
#' generate a sample from case 2 where the bounds are \eqn{0 \in [a, b]}.
#'    The cases are listed on page 4 of Li & Ghosh (2015).
#'
#' @param a Lower bound of truncation
#' @param b Upper bound of truncattion
#'
#' @return value of the sample
#'
#' @references Li, Y., & Ghosh, S. K. (2015). Efficient sampling methods for
#'     truncated multivariate normal and student-t distributions subject to
#'     linear inequality constraints. Journal of Statistical Theory and
#'     Practice, 9(4), 712-732.
#' @export
sample_case2 <- function(a, b) {
    .Call('_tmvn_sample_case2', PACKAGE = 'tmvn', a, b)
}

#' Sample Case 3
#'
#' generate a sample from case 3 where the bounds are \eqn{[a, b], a > 0}.
#'    The cases are listed on page 4 of Li & Ghosh (2015).
#'
#' @param a Lower bound of truncation
#' @param b Upper bound of truncattion
#'
#' @return value of the sample
#'
#' @references Li, Y., & Ghosh, S. K. (2015). Efficient sampling methods for
#'     truncated multivariate normal and student-t distributions subject to
#'     linear inequality constraints. Journal of Statistical Theory and
#'     Practice, 9(4), 712-732.
#' @export
sample_case3 <- function(a, b) {
    .Call('_tmvn_sample_case3', PACKAGE = 'tmvn', a, b)
}

#' Sample Case 4
#'
#' generate a sample from case 4 where the bounds are \eqn{(-\infty, b]}.
#'    This case is symmetric to case 1 in the function sample_case1.
#'
#' @param a Lower bound of truncation
#' @param b Upper bound of truncattion
#'
#' @return value of the samples
#'
#' @references Li, Y., & Ghosh, S. K. (2015). Efficient sampling methods for
#'     truncated multivariate normal and student-t distributions subject to
#'     linear inequality constraints. Journal of Statistical Theory and
#'     Practice, 9(4), 712-732.
#' @export
sample_case4 <- function(a, b) {
    .Call('_tmvn_sample_case4', PACKAGE = 'tmvn', a, b)
}

#' Sample Case 5
#'
#' generate a sample from case 5 where the bounds are \eqn{[a, b], b < 0}.
#'    This case is symmetric to case 3 in the function sample_case3.
#'
#' @param a Lower bound of truncation
#' @param b Upper bound of truncattion
#'
#' @return value of the sample
#'
#' @references Li, Y., & Ghosh, S. K. (2015). Efficient sampling methods for
#'     truncated multivariate normal and student-t distributions subject to
#'     linear inequality constraints. Journal of Statistical Theory and
#'     Practice, 9(4), 712-732.
#' @export
sample_case5 <- function(a, b) {
    .Call('_tmvn_sample_case5', PACKAGE = 'tmvn', a, b)
}

#' Full Rejection sampling steps
#'
#' Generate a sample from a truncated univariate standard normal distribution,
#'     TN(0, 1; a, b).
#'
#' @param a Lower bound of truncation
#' @param b Upper bound of truncattion
#'
#' @return value of the sample
#'
#' @references Li, Y., & Ghosh, S. K. (2015). Efficient sampling methods for
#'     truncated multivariate normal and student-t distributions subject to
#'     linear inequality constraints. Journal of Statistical Theory and
#'     Practice, 9(4), 712-732.
#' @export
sample_tuvsn <- function(a, b) {
    .Call('_tmvn_sample_tuvsn', PACKAGE = 'tmvn', a, b)
}

#' TUVN normal rejection sampling
#'
#' Normal rejection sampling for the truncated standard normal distribution
#'
#' @param a Lower bound of truncation
#' @param b Upper bound of truncation
#' @return \item{x}{value of the sample} \item{acc}{number of proposals for acceptance}
#'
#' @references Li, Y., & Ghosh, S. K. (2015). Efficient sampling methods for
#'     truncated multivariate normal and student-t distributions subject to
#'     linear inequality constraints. Journal of Statistical Theory and
#'     Practice, 9(4), 712-732.
#' @export
norm_rej <- function(a, b) {
    .Call('_tmvn_norm_rej', PACKAGE = 'tmvn', a, b)
}

#' TUVN Half-normal rejection sampling
#'
#' @param a Lower bound of truncation
#' @param b Upper bound of truncation
#'
#' @return \item{x}{value of the sample} \item{acc}{number of proposals for acceptance}
#'
#' @references Li, Y., & Ghosh, S. K. (2015). Efficient sampling methods for
#'     truncated multivariate normal and student-t distributions subject to
#'     linear inequality constraints. Journal of Statistical Theory and
#'     Practice, 9(4), 712-732.
#' @export
halfnorm_rej <- function(a, b) {
    .Call('_tmvn_halfnorm_rej', PACKAGE = 'tmvn', a, b)
}

#' TUVN uniform rejection sampling
#'
#' @param a Lower bound of truncation
#' @param b Upper bound of truncation
#'
#' @return \item{x}{value of the sample} \item{acc}{number of proposals for acceptance}
#'
#' @references Li, Y., & Ghosh, S. K. (2015). Efficient sampling methods for
#'     truncated multivariate normal and student-t distributions subject to
#'     linear inequality constraints. Journal of Statistical Theory and
#'     Practice, 9(4), 712-732.
#' @export
unif_rej <- function(a, b) {
    .Call('_tmvn_unif_rej', PACKAGE = 'tmvn', a, b)
}

#' TUVN exponential rejection sampling
#'
#' @param a Lower bound of truncation
#' @param b Upper bound of truncation
#' @return value of the sample
#'
#' @references Li, Y., & Ghosh, S. K. (2015). Efficient sampling methods for
#'     truncated multivariate normal and student-t distributions subject to
#'     linear inequality constraints. Journal of Statistical Theory and
#'     Practice, 9(4), 712-732.
#' @export
exp_rej <- function(a, b) {
    .Call('_tmvn_exp_rej', PACKAGE = 'tmvn', a, b)
}
suchitm/tmvn documentation built on Dec. 10, 2020, 10:25 a.m.