I am trying to create truncated multivariate normal r.vector with sigma that depends on some random vector z. Since initially sigma (in my code called nn) is not positive definite, i used function make.positive.definite()
and then i got nn to be positive definite (and symmetric).
But in calling rtmvnorm
i get the following error:
"Error in checkSymmetricPositiveDefinite(sigma) -sigma must be positive definite".
Any idea what might be wrong?
library(tmvtnorm)
library(matrixcalc)
library(corpcor)
zmean <- rep(0, 100)
zSigma <- diag(100)
z <- rmvnorm(n=1, mean=zmean, sigma=zSigma)
umean <- rep(0, 100)
usigma <- exp(-0.5 * rep(1, 100) + z)
nn <- t(usigma) %*% usigma
is.positive.definite(nn)
nn <- make.positive.definite(nn)
is.positive.definite(nn)
isSymmetric(nn)
a <- rep(0,100)
b <- rep(+Inf, 100)
U <- rtmvnorm(n=1, mean=umean, sigma=nn, lower=a, upper=b, algorithm="gibbs")
Matrix::nearPD
instead, withensureSymmetry=TRUE
? – Ben Bolker