# trmvrnorm_rej_cpp: Sample from truncated multivariate normal distribution with... In anMC: Compute High Dimensional Orthant Probabilities

## Description

Simulates realizations from a truncated multivariate normal with mean mu, covariance matrix sigma in the bounds lower upper.

## Usage

 `1` ```trmvrnorm_rej_cpp(n, mu, sigma, lower, upper, verb) ```

## Arguments

 `n` number of simulations. `mu` mean vector. `sigma` covariance matrix. `lower` vector of lower bounds. `upper` vector of upper bounds. `verb` level of verbosity: if lower than 3 nothing, 3 minimal, 4 extended.

## Value

A matrix of size d x n containing the samples.

## References

Horrace, W. C. (2005). Some results on the multivariate truncated normal distribution. Journal of Multivariate Analysis, 94(1):209–221.

Robert, C. P. (1995). Simulation of truncated normal variables. Statistics and Computing, 5(2):121–125.

## Examples

 ``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18``` ```# Simulate 1000 realizations from a truncated multivariate normal vector mu <- rep(0,10) Sigma <- diag(rep(1,10)) upper <- rep(3,10) lower <- rep(-0.5,10) realizations<-trmvrnorm_rej_cpp(n=1000,mu = mu,sigma=Sigma, lower =lower, upper= upper,verb=3) empMean<-rowMeans(realizations) empCov<-cov(t(realizations)) # check if the sample mean is close to the actual mean maxErrorOnMean<-max(abs(mu-empMean)) # check if we can estimate correctly the covariance matrix maxErrorOnVar<-max(abs(rep(1,200)-diag(empCov))) maxErrorOnCov<-max(abs(empCov[lower.tri(empCov)])) ## Not run: plot(density(realizations[1,])) hist(realizations[1,],breaks="FD") ## End(Not run) ```

### Example output

```Loading required package: mvtnorm
Acceptance rate: 0.0245019

Total samples run 41474
Total samples accepted 1000
Ratio: 0.0241115
Last alpha: 0.0363636
```

anMC documentation built on Oct. 30, 2019, 11:41 a.m.