rtmvn: Truncated Multivariate Normal Distribution

Description Usage Arguments Value References Examples

View source: R/rtmvn.R

Description

Random vector generation for the truncated multivariate normal distribution using a Gibbs sampler.

Usage

1
rtmvn(n, Mean, Sigma = NULL, D, lower, upper, init, Sigma_chol = NULL)

Arguments

n

number of samples to be generated

Mean

mean vector

Sigma

covariance matrix

D

matrix of linear constraints

lower

vector of lower bounds

upper

vector of upper bounds

init

vector of initial values for the Gibbs sampler. Must satisfy the linear constraints.

Sigma_chol

the lower triangular cholesky of the covariance matrix. Only one of Sigma and Sigma_chol can be NULL.

Value

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.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
Mean = rep(0,2)
rho = 0.5
Sigma = matrix(c(10,rho,rho,0.1),2,2)
D = matrix(c(1,1,1,-1),2,2)
varp = Sigma[1,1]+Sigma[2,2]+2*Sigma[1,2] # var of the sum
varm = Sigma[1,1]+Sigma[2,2]-2*Sigma[1,2] # var of the diff
sd = c(sqrt(varp),sqrt(varm))
lower = -1.5*sd; upper = 1.5*sd; init = rep(0,2)
n = 20
rtmvn(n,Mean,Sigma,D,lower,upper,init)

suchitm/tmvn documentation built on Dec. 10, 2020, 10:25 a.m.