get_cor: translate vector of correlation parameters to correlation...

View source: R/utils.R

get_corR Documentation

translate vector of correlation parameters to correlation values

Description

translate vector of correlation parameters to correlation values

Usage

get_cor(theta, return_val = c("vec", "mat"))

put_cor(C, input_val = c("mat", "vec"))

Arguments

theta

vector of internal correlation parameters (elements of scaled Cholesky factor, in row-major order)

return_val

return a vector of correlation values from the lower triangle ("vec"), or the full correlation matrix ("mat")?

C

a correlation matrix

input_val

input a vector of correlation values from the lower triangle ("vec"), or the full correlation matrix ("mat")?

Details

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.

Value

a vector of correlation values (get_cor) or glmmTMB scaled-correlation parameters (put_cor)

Examples

th0 <- 0.5
stopifnot(all.equal(get_cor(th0),th0/sqrt(1+th0^2)))
set.seed(101)
C <- get_cor(rnorm(21), return_val = "mat")
## test: round-trip
stopifnot(all.equal(get_cor(put_cor(C), return_val = "mat"), C))

glmmTMB documentation built on Sept. 30, 2024, 9:34 a.m.