vivek - 2 months ago 4x

R Question

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

I am using the

`rtmvnorm`

`tmvtnorm`

`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)`

`cov2cor(sigma)`

`> 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?

Answer

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.

Source (Stackoverflow)

Comments