[R] rtmvnorm {tmvtnorm} seems broken

Tim Benham timothy.benham at uqconnect.edu.au
Wed Dec 10 06:51:22 CET 2014


General linear constraints don't seem to work. I get an error message if I
have more constraint equations than variables. E.g. executing the following
code

print(R.version)
library('tmvtnorm')
cat('tmvtnorm version ')
print(packageVersion('tmvtnorm'))
## Let's constrain our sample to the dwarfed hypercube of dimension p.
p <- 3  # dimension
mean <- rep(0,p)
sigma <- diag(p)
## a <= Dx <= b
a <- c(rep(0,p),-Inf)
b <- c(rep(1,p),2)
D <- rbind(diag(p),rep(1,p))
cat('mean is\n'); print(mean)
cat('a is\n'); print(a)
cat('b is\n'); print(b)
cat('D is\n'); print(D)
X <- rtmvnorm(n=1000, mean, sigma, D=D, lower=a, upper=b, algorithm="gibbsR")

produces the following output

platform       x86_64-w64-mingw32
arch           x86_64
os             mingw32
system         x86_64, mingw32
status
major          3
minor          1.0
year           2014
month          04
day            10
svn rev        65387
language       R
version.string R version 3.1.0 (2014-04-10)
nickname       Spring Dance
tmvtnorm version [1] '1.4.9'
mean is
[1] 0 0 0
a is
[1]    0    0    0 -Inf
b is
[1] 1 1 1 2
D is
     [,1] [,2] [,3]
[1,]    1    0    0
[2,]    0    1    0
[3,]    0    0    1
[4,]    1    1    1
Error in checkTmvArgs(mean, sigma, lower, upper) (from rtmvnorm-test.R#18) :
  mean, lower and upper must have the same length

That error message is not appropriate when a matrix of linear constraints is
passed in. I emailed the package maintainer on the 3rd but received only an
automatic out-of-office reply.



More information about the R-help mailing list