th0 <- 0.5
stopifnot(all.equal(get_cor(th0), th0/sqrt(1+th0^2)))
set.seed(101)
## pick 6 values for a random 4x4 correlation matrix
print(C <- get_cor(rnorm(6), return_val = "mat"), digits = 3)
## transform a correlation matrix to a theta vector
cor_mat <- matrix(c(1,0.3,0.1,
0.3,1,0.2,
0.1,0.2,1), ncol = 3)
put_cor(cor_mat, "mat")
put_cor(cor_mat[lower.tri(cor_mat)], "vec")
## test: round-trip
stopifnot(all.equal(get_cor(put_cor(C), return_val = "mat"), C))
Run the code above in your browser using DataLab