Goals

Simulating covariates

by hand

set.seed(101)
dd <- data.frame(x = rnorm(100), f = factor(rep(1:10, 10)))
X <- model.matrix(~x, data = dd)
beta <- c(1,2)
b <- rnorm(10)
mu <- X %*% beta + b[dd$f]
dd$y <- rnorm(nrow(dd), mean = mu, sd = 1)

simulate functions

de novo specification

parameters for lme4::simulate

parameters for glmmTMB::simulate_new

parameterization of “unstructured” covariance matrices

lme4 parameterization

corrsd <- matrix(c(2.0, 0.4, 0.1,
                   0.4, 1.0, 0.3,
                   0.1, 0.3, 3.0),
                 3, 3)
get_lower_tri <- function(x) x[lower.tri(x, diag = TRUE)]
corrsd |> lme4:::sdcor2cov() |> chol() |> t() |> get_lower_tri()
## [1] 2.0000000 0.4000000 0.3000000 0.9165151 0.8510498 2.8610687

glmmTMB parameterization

GLMM family parameterizations

Example

1.
Pinheiro, J. C. & Bates, D. M. Unconstrained parametrizations for variance-covariance matrices. Statistics and Computing 6, 289–296 (1996).