translate vector of correlation parameters to correlation values
get_cor(theta)
put_cor(C)
vector of internal correlation parameters (elements of scaled Cholesky factor, in row-major order)
a correlation matrix
a vector of correlation values (get_cor
) or glmmTMB scaled-correlation parameters (put_cor
)
These functions follow the definition at http://kaskr.github.io/adcomp/classdensity_1_1UNSTRUCTURED__CORR__t.html:
if \(L\) is the lower-triangular matrix with 1 on the diagonal and the correlation parameters in the lower triangle, then the correlation matrix is defined as \(\Sigma = D^{-1/2} L L^\top D^{-1/2}\), where \(D = \textrm{diag}(L L^\top)\). For a single correlation parameter \(\theta_0\), this works out to \(\rho = \theta_0/\sqrt{1+\theta_0^2}\). The get_cor
function returns the elements of the lower triangle of the correlation matrix, in column-major order.
th0 <- 0.5
stopifnot(all.equal(get_cor(th0),th0/sqrt(1+th0^2)))
get_cor(c(0.5,0.2,0.5))
#> [1] 0.4472136 0.1760902 0.4724995
C <- matrix(c(1, 0.2, 0.1,
0.2, 1, -0.2,
0.1,-0.2, 1),
3, 3)
## test: round-trip (almostl results in lower triangle only)
stopifnot(all.equal(get_cor(put_cor(C)),
C[lower.tri(C)]))