Extract variance and correlation components
Details
For an unstructured variance-covariance matrix, the internal parameters are structured as follows: the first n parameters are the log-standard-deviations, while the remaining n(n-1)/2 parameters are the elements of the Cholesky factor of the correlation matrix, filled in column-wise order (see the TMB documentation for further details).
Examples
## Comparing variance-covariance matrix with manual computation
data("sleepstudy",package="lme4")
fm4 <- glmmTMB(Reaction ~ Days + (Days|Subject), sleepstudy)
VarCorr(fm4)[[c("cond","Subject")]]
#> (Intercept) Days
#> (Intercept) 565.49216 11.05473
#> Days 11.05473 32.68064
#> attr(,"stddev")
#> (Intercept) Days
#> 23.780079 5.716698
#> attr(,"correlation")
#> (Intercept) Days
#> (Intercept) 1.00000000 0.08131856
#> Days 0.08131856 1.00000000
#> attr(,"blockCode")
#> us
#> 1
#> attr(,"class")
#> [1] "vcmat_us" "matrix" "array"
## hand calculation
pars <- getME(fm4,"theta")
## construct cholesky factor
L <- diag(2)
L[lower.tri(L)] <- pars[-(1:2)]
C <- crossprod(L)
diag(C) <- 1
sdvec <- exp(pars[1:2])
(V <- outer(sdvec,sdvec) * C)
#> [,1] [,2]
#> [1,] 565.49216 11.09147
#> [2,] 11.09147 32.68064