Package TruncatedNormal

Similar documents
Truncated Multivariate Normal Toolbox

Package sbgcop. May 29, 2018

Package SimSCRPiecewise

The sbgcop Package. March 9, 2007

Package basad. November 20, 2017

Package elhmc. R topics documented: July 4, Type Package

Package darts. February 19, 2015

Bayesian linear regression

Package ICBayes. September 24, 2017

Package gtheory. October 30, 2016

Package spatial.gev.bma

Package SEMModComp. R topics documented: February 19, Type Package Title Model Comparisons for SEM Version 1.0 Date Author Roy Levy

Package BNN. February 2, 2018

Package factorqr. R topics documented: February 19, 2015

Package rgabriel. February 20, 2015

Package anmc. July 24, 2018

Package LIStest. February 19, 2015

Package effectfusion

Package SimCorMultRes

Gaussians Linear Regression Bias-Variance Tradeoff

Package mar. R topics documented: February 20, Title Multivariate AutoRegressive analysis Version Author S. M. Barbosa

Package TwoStepCLogit

Package ARCensReg. September 11, 2016

Package covtest. R topics documented:

Package depth.plot. December 20, 2015

Package unbalhaar. February 20, 2015

Gaussian Processes. Le Song. Machine Learning II: Advanced Topics CSE 8803ML, Spring 2012

Introduction to Probabilistic Graphical Models: Exercises

Package horseshoe. November 8, 2016

Index. Pagenumbersfollowedbyf indicate figures; pagenumbersfollowedbyt indicate tables.

The Multivariate Normal Distribution 1

1 Data Arrays and Decompositions

The Multivariate Normal Distribution 1

Package reinforcedpred

Package EnergyOnlineCPM

Package lmm. R topics documented: March 19, Version 0.4. Date Title Linear mixed models. Author Joseph L. Schafer

Package covsep. May 6, 2018

Package flexcwm. R topics documented: July 11, Type Package. Title Flexible Cluster-Weighted Modeling. Version 1.0.

Randomized Quasi-Monte Carlo for MCMC

Package RootsExtremaInflections

1. Introduction. Hang Qian 1 Iowa State University

Regression. ECO 312 Fall 2013 Chris Sims. January 12, 2014

Package gk. R topics documented: February 4, Type Package Title g-and-k and g-and-h Distribution Functions Version 0.5.

Package bivariate. December 10, 2018

STA 2201/442 Assignment 2

Package flexcwm. R topics documented: July 2, Type Package. Title Flexible Cluster-Weighted Modeling. Version 1.1.

Package RZigZag. April 30, 2018

Package CausalFX. May 20, 2015

Package milineage. October 20, 2017

Package threg. August 10, 2015

Random Vectors 1. STA442/2101 Fall See last slide for copyright information. 1 / 30

Package bhrcr. November 12, 2018

Package noncompliance

Package goftest. R topics documented: April 3, Type Package

Package zic. August 22, 2017

Package QuantifQuantile

Package leiv. R topics documented: February 20, Version Type Package

Part 6: Multivariate Normal and Linear Models

Package SK. May 16, 2018

Package IGG. R topics documented: April 9, 2018

PROBABILITY DISTRIBUTIONS. J. Elder CSE 6390/PSYC 6225 Computational Modeling of Visual Perception

Package NonpModelCheck

Contents. Preface to Second Edition Preface to First Edition Abbreviations PART I PRINCIPLES OF STATISTICAL THINKING AND ANALYSIS 1

Package ForecastCombinations

Package sscor. January 28, 2016

Package Bhat. R topics documented: February 19, Title General likelihood exploration. Version

Package sodavis. May 13, 2018

Package pfa. July 4, 2016

Basic Sampling Methods

Bivariate Paired Numerical Data

Simulating Random Variables

Package BayesNI. February 19, 2015

Package misctools. November 25, 2016

Package eel. September 1, 2015

Package CopulaRegression

Package beam. May 3, 2018

Package CPE. R topics documented: February 19, 2015

STA 4273H: Statistical Machine Learning

Package ebal. R topics documented: February 19, Type Package

Finite Mixture and Markov Switching Models

Package riv. R topics documented: May 24, Title Robust Instrumental Variables Estimator. Version Date

Package ShrinkCovMat

x. Figure 1: Examples of univariate Gaussian pdfs N (x; µ, σ 2 ).

Package skellam. R topics documented: December 15, Version Date

STA 4273H: Statistical Machine Learning

Package EMVS. April 24, 2018

σ(a) = a N (x; 0, 1 2 ) dx. σ(a) = Φ(a) =

Package mcmcse. July 4, 2017

Nonparametric Bayesian Methods (Gaussian Processes)

ECE521 Tutorial 2. Regression, GPs, Assignment 1. ECE521 Winter Credits to Alireza Makhzani, Alex Schwing, Rich Zemel for the slides.

First steps of multivariate data analysis

Package rnmf. February 20, 2015

Package blme. August 29, 2016

Package RcppSMC. March 18, 2018

HANDBOOK OF APPLICABLE MATHEMATICS

Package Delaporte. August 13, 2017

Package TSF. July 15, 2017

Package dina. April 26, 2017

Dependence. MFM Practitioner Module: Risk & Asset Allocation. John Dodson. September 11, Dependence. John Dodson. Outline.

Package HIMA. November 8, 2017

Transcription:

Package TruncatedNormal November 10, 2015 Type Package Title Truncated Multivariate Normal Version 1.0 Date 2015-11-08 Author Zdravko I. Botev Maintainer Zdravko Botev <botev@unsw.edu.au> A collection of functions to deal with the truncated univariate and multivariate normal distributions. License GPL-3 Depends randtoolbox NeedsCompilation no Repository CRAN Date/Publication 2015-11-10 11:19:19 R topics documented: TruncatedNormal-package................................. 2 lupus............................................. 3 mvncdf........................................... 4 mvnqmc.......................................... 5 mvrandn........................................... 6 norminvp.......................................... 8 trandn............................................ 9 Index 11 1

2 TruncatedNormal-package TruncatedNormal-package Truncated Normal Distribution Toolbox The routines include: generator of independent and identically distributed random vectors from the truncated univariate and multivariate distributions; (Quasi-) Monte Carlo estimator and a deterministic upper bound of the cumulative distribution function of the multivariate normal; algorithm for the accurate computation of the quantile function of the normal distribution in the extremes of its tails. Package: Truncated Normal Type: Package Version: 1.0 Date: 2015-11-08 License: GPL-3 mvncdf(l,u,sig,n) uses a Monte Carlo sample of size n to estimate the cumulative distribution function, P r(l < X < u), of the d-dimensional multivariate normal with zero-mean and covariance Σ, that is, X has N(0, Σ) distribution; mvnqmc(l,u,sig,n) provides a Quasi Monte Carlo algorithm for medium dimensions (say, d < 50), in addition to the faster Monte Carlo algorithm in mvncdf; mvrandn(l,u,sig,n) simulates n identically and independently distributed random vectors X from N(0, Σ), conditional on l < X < u; norminvp(p,l,u) computes the quantile function at 0 p 1 of the univariate N(0, 1) distribution truncated to [l, u], and with high precision in the tails; trandn(l,u) is a fast random number generator from the univariate N(0, 1) distribution truncated to [l, u]. Author(s) Z. I. Botev, email: <botev@unsw.edu.au> and web page: http://web.maths.unsw.edu.au/ ~zdravkobotev/ Z. I. Botev (2015), The Normal Law Under Linear Restrictions: Simulation and Estimation via Minimax Tilting, submitted to JRSS(B)

lupus 3 Z. I. Botev and P. L Ecuyer (2015), Efficient Estimation and Simulation of the Truncated Multivariate Student-t Distribution, Proceedings of the 2015 Winter Simulation Conference, Huntington Beach, CA, USA Gibson G. J., Glasbey C. A., Elston D. A. (1994), Monte Carlo evaluation of multivariate normal integrals and sensitivity to variate ordering, In: Advances in Numerical Methods and Applications, pages 120 126 Matlab toolbox: http://web.maths.unsw.edu.au/~zdravkobotev/ trandn(4,5) # generate a variable from the truncated normal on [4,5] lupus Latent Membranous Lupus Nephritis Dataset Usage Format The data represents two clinical measurements (covariates), which are used to predict the occurrence of latent membranous lupus nephritis. The dataset consists of measurements on 55 patients of which 18 have been diagnosed with latent membranous lupus. data("lupus") The format is: "response" "const" "x1" "x2" The data was transcribed manually into this format from Table 1, page 22, of Dyk and Meng (2001). D. A. van Dyk and X.-L. Meng (2001) The art of data augmentation (with discussion). Journal of Computational and Graphical Statistics, volume 10, pages 1-50. as mvrandn, which uses this dataset. data("lupus")

4 mvncdf mvncdf truncated multivariate normal cumulative distribution computes an estimator and a deterministic upper bound of the probability P r(l < X < u), where X is a zero-mean multivariate normal vector with covariance matrix Σ, that is, X is drawn from N(0, Σ) infinite values for vectors u and l are accepted; Monte Carlo method uses sample size n; Usage mvncdf(l, u, Sig, n) Arguments l u lower truncation limit upper truncation limit Sig covariance matrix of N(0, Σ) n Monte Carlo simulation effort the larger the n, the smaller the relative error of the estimator. Suppose you wish to estimate p = P r(l < AX < u), where A is a full rank matrix and X is drawn from N(µ, Σ), then you simply compute p = P r(l Aµ < AY < u Aµ), where Y is drawn from N(0, AΣA ). Value est with structure $prob estimated value of probability P r(l < X < u) $relerr estimated relative error of estimator $upbnd theoretical upper bound on true P r(l < X < u) Note For small dimensions, say d < 50, better accuracy may be obtained by using the (usually slower) quasi-monte Carlo version mvnqmc of this algorithm. Author(s) Z. I. Botev, email: <botev@unsw.edu.au> and web page: http://web.maths.unsw.edu.au/ ~zdravkobotev/

mvnqmc 5 Z. I. Botev (2015), The Normal Law Under Linear Restrictions: Simulation and Estimation via Minimax Tilting, submitted to JRSS(B) See also: mvnqmc and mvrandn d=15;l=1:d;u=l+inf; Sig=matrix(rnorm(d^2),d,d)*2;Sig=Sig%*%t(Sig) n=10^3 # size of simulation effort x=mvncdf(l,u,sig,10^4) # compute the probability print(x) mvnqmc truncated multivariate normal cumulative distribution (quasi-monte Carlo) computes an estimator and a deterministic upper bound of the probability P r(l < X < u), where X is a zero-mean multivariate normal vector with covariance matrix Σ, that is, X is drawn from N(0, Σ) infinite values for vectors u and l are accepted; Usage mvnqmc(l, u, Sig, n) Arguments l u lower truncation limit upper truncation limit Sig covariance matrix of N(0, Σ) n total randomized quasi-monte Carlo simulation effort; higher values yield more accurate results; Quasi-Monte Carlo version: This version uses a Quasi Monte Carlo (QMC) pointset of size ceiling(n/12) and estimates the relative error using 12 independent randomized QMC estimators; QMC is slower than ordinary Monte Carlo, but is also likely to be more accurate when d < 50. For high dimensions, say d > 50, you may obtain the same accuracy using the (typically faster) mvncdf. The non-zero mean case, that is, N(µ, Σ): Suppose you wish to estimate p = P r(l < AX < u), where A is a full rank matrix and X drawn from N(µ, Σ). Then, you simply compute p = P r(l Aµ < AY < u Aµ), where Y is drawn from N(0, AΣA ).

6 mvrandn Value est with structure $prob estimated value of probability P r(l < X < u) $relerr estimated relative error of estimator $upbnd theoretical upper bound on true P r(l < X < u) Author(s) Z. I. Botev, email: <botev@unsw.edu.au> and web page: http://web.maths.unsw.edu.au/ ~zdravkobotev/ Z. I. Botev (2015), The Normal Law Under Linear Restrictions: Simulation and Estimation via Minimax Tilting, submitted to JRSS(B) See also: mvncdf and mvrandn d=15;l=1:d;u=l+inf; Sig=matrix(rnorm(d^2),d,d)*2;Sig=Sig%*%t(Sig) n=10^3 # size of simulation effort x=mvnqmc(l,u,sig,10^4) print(x) mvrandn truncated multivariate normal generator Usage simulates n identically and independently distributed random vectors from the d-dimensional N(0, Σ) distribution (zero-mean normal with covariance Σ) conditional on l < X < u; infinite values for l and u are accepted; mvrandn(l, u, Sig, n) Arguments l u lower truncation limit upper truncation limit Sig Covariance matrix of N(0, Σ) n number of simulated vectors

mvrandn 7 Value Note Bivariate normal: Suppose we wish to simulate a bivariate X from N(µ, Σ), conditional on X 1 X 2 < 6. We can recast this as the problem of simulation of Y from N(0, AΣA ) (for an appropriate matrix A) conditional on l Aµ < Y < u Aµ and then setting X = µ+a 1 Y. See the example code below. Exact posterior simulation for Probit regression: Consider the Bayesian Probit Regression model applied to the lupus dataset. Let the prior for the regression coefficients β be N(0, ν 2 I). Then, to simulate from the Bayesian posterior exactly, we first simulate Z from N(0, Σ), where Σ = I + ν 2 XX, conditional on Z 0. Then, we simulate the posterior regression coefficients, β, of the Probit regression by drawing (β Z) from N(CX Z, C), where C 1 = I/ν 2 + X X. See the example code below. output is a d by n array storing the random vectors, X, drawn from N(0, Σ), conditional on l < X < u; Algorithm may not work or be very inefficient if Σ is close to being rank deficient. Author(s) Z. I. Botev, email: <botev@unsw.edu.au> and web page: http://web.maths.unsw.edu.au/ ~zdravkobotev/ Z. I. Botev (2015), The Normal Law Under Linear Restrictions: Simulation and Estimation via Minimax Tilting, submitted to JRSS(B) See also: mvnqmc and mvncdf # Bivariate example. Sig=matrix(c(1,0.9,0.9,1),2,2);mu=c(-3,0);l=c(-Inf,-Inf);u=c(-6,Inf);A=matrix(c(1,0,-1,1),2,2); n=10^3; # number of sampled vectors Y=mvrandn(l-A%*%mu,u-A%*%mu,A%*%Sig%*%t(A),n); X=rep(mu,n)+solve(A,diag(2))%*%Y; # now apply the inverse map as explained above plot(x[1,],x[2,]) # provide a scatterplot of exactly simulated points # Exact Bayesian Posterior Simulation Example. data("lupus"); # load lupus data Y = lupus[,1]; # response data X = lupus[,-1] # construct design matrix

8 norminvp m=dim(x)[1]; d=dim(x)[2]; # dimensions of problem X=diag(2*Y-1)%*%X; # incorporate response into design matrix nu=sqrt(10000); # prior scale parameter C=solve(diag(d)/nu^2+t(X)%*%X); L=t(chol(t(C))); # lower Cholesky decomposition Sig=diag(m)+nu^2*X%*%t(X); # this is covariance of Z given beta l=rep(0,m);u=rep(inf,m); est=mvncdf(l,u,sig,10^3); # estimate acceptance probability of Crude Monte Carlo print(est$upbnd/est$prob) # estimate the reciprocal of acceptance probability n=10^4 # number of iid variables z=mvrandn(l,u,sig,n); # sample exactly from auxiliary distribution beta=l%*%matrix(rnorm(d*n),d,n)+c%*%t(x)%*%z; # simulate beta given Z and plot boxplots of marginals boxplot(t(beta)) # plot the boxplots of the marginal distribution of the coefficients in beta print(rowmeans(beta)) # output the posterior means norminvp normal quantile function with precision Usage computes with tail-precision the quantile function of the standard normal distribution at 0 p 1, and truncated to the interval [l, u]; Infinite values for vectors l and u are accepted; norminvp(p, l, u) Arguments p quantile at 0 p 1 l u Value Note lower truncation limit upper truncation limit Suppose we wish to simulate a random variable Z drawn from N(µ, σ 2 ) and conditional on l < Z < u using the inverse transform method. To achieve this, first compute X=norminvp(runif(1),(l-mu)/sig,(u-mu)/sig) and then set Z=mu+sig*X A real number the quantile value of the truncated normal distribution. If you wish to simulate truncated normal variables fast, use trandn. Using norminvp is advisable only when needed, for example, in quasi-monte Carlo or antithetic sampling, where the inverse transform method is unavoidable.

trandn 9 Author(s) Z. I. Botev, email: <botev@unsw.edu.au> and web page: http://web.maths.unsw.edu.au/ ~zdravkobotev/ Z. I. Botev (2015), The Normal Law Under Linear Restrictions: Simulation and Estimation via Minimax Tilting, submitted to JRSS(B) as trandn d=150;l=1:d;u=l+inf; x=norminvp(runif(d),l,u) # simulate via inverse transform method trandn fast truncated normal generator Usage efficient state-of-the-art generator of a vector of length(l)=length(u) from the standard multivariate normal distribution, truncated over the region [l, u]; infinite values for u and l are accepted; trandn(l,u) Arguments l u lower truncation limit upper truncation limit Value Note If you wish to simulate a random variable Z drawn from N(µ, σ 2 ) conditional on l < Z < u, then first simulate X=trandn((l-mu)/sig,(u-mu)/sig) and set Z=mu+sig*X; random variable(s) drawn from the truncated normal distribution Use norminvp for the (slower) inverse transform method of simulating truncated normal variables.

10 trandn Author(s) Z. I. Botev, email: <botev@unsw.edu.au> and web page: http://web.maths.unsw.edu.au/ ~zdravkobotev/ Z. I. Botev (2015), The Normal Law Under Linear Restrictions: Simulation and Estimation via Minimax Tilting, submitted to JRSS(B) See also: norminvp d=150;l=1:d;u=l+inf; x=trandn(l,u) print(x)

Index Topic Gaussian Topic cumulative mvncdf, 4 mvnqmc, 5 Topic datasets lupus, 3 Topic gaussian mvncdf, 4 mvnqmc, 5 mvrandn, 6 norminvp, 8 Topic generation Topic generator mvrandn, 6 Topic lupus lupus, 3 Topic normal mvncdf, 4 mvnqmc, 5 mvrandn, 6 norminvp, 8 trandn, 9 Topic perfect sampling mvrandn, 6 Topic quantile norminvp, 8 Topic quasi-monte Carlo mvnqmc, 5 Topic sampling Topic simulation Topic truncated mvncdf, 4 mvnqmc, 5 mvrandn, 6 norminvp, 8 trandn, 9 Topic univariate trandn, 9 Topic upper bound cases (TruncatedNormal-package), 2 cholperm (TruncatedNormal-package), 2 gradpsi (TruncatedNormal-package), 2 lnnpr (TruncatedNormal-package), 2 lupus, 3, 7 mvncdf, 2, 4, 5 7 mvnpr (TruncatedNormal-package), 2 mvnprqmc (TruncatedNormal-package), 2 mvnqmc, 2, 4, 5, 5, 7 mvnrnd (TruncatedNormal-package), 2 mvrandn, 2, 3, 5, 6, 6 newton (TruncatedNormal-package), 2 nleq (TruncatedNormal-package), 2 norminvp, 2, 8, 9, 10 normq (TruncatedNormal-package), 2 ntail (TruncatedNormal-package), 2 Phinv (TruncatedNormal-package), 2 psy (TruncatedNormal-package), 2 qfun (TruncatedNormal-package), 2 tn (TruncatedNormal-package), 2 trandn, 2, 8, 9, 9 trnd (TruncatedNormal-package), 2 11

12 INDEX TruncatedNormal (TruncatedNormal-package), 2