Search code examples
rcovariancenormal-distributiontruncated

Wrong answer in rtmvnorm() in R while sampling truncated normal


I am unable to find why I am not getting the right correlation structure after sampling.

I am using the rtmvnorm in R from tmvtnorm package. I am using example 1 provided in the pdf for the section of this function.

sigma <- matrix(c(4,2,2,3), ncol=2)
x <- rtmvnorm(n=500, mean=c(1,2), sigma=sigma, upper=c(1,0))

when I am using the above to find the cor(x) and cov2cor(sigma) my results appear very different.

> cor(x)
#          [,1]      [,2]
#[1,] 1.0000000 0.2126776
#[2,] 0.2126776 1.0000000

> cov2cor(sigma)
#          [,1]      [,2]
#[1,] 1.0000000 0.5773503
#[2,] 0.5773503 1.0000000

My objective is to generate truncated normal samples with a covariance structure.

     [,1] [,2]
[1,]  9.0  3.6
[2,]  3.6 16.0

Maybe I am missing something here. Can someone explain it to me in a better way?


Solution

  • Why are you surprised? cov2cor(sigma) is the correlation matrix for non-truncated normal, while cor(x) is the correlation matrix for truncated normal. Of course they are not the same. Similarly, cov(x) is different from sigma.

    Do you want to compare cov2cor(cov(x)) and cor(x)? That will be the same.