Skip to contents

The function computes the variance matrix of the random effects, the correlations, or the measurement error.

Usage

createVarianceMatrix(model, which, times1, times2, nmes)

Arguments

model

an object inheriting from class hlme, lcmm, Jointlcmm or multlcmm representing a general latent class mixed model.

which

either "random", "cor", "randomY", or "error".

times1

for which = "cor", numeric vector containing the times at which the correlation should be computed

times2

for which = "cor", numeric vector containing the times at which the correlation should be computed

nmes

for which = "randomY" and which = "error", the number of measures (ie, the dimension of the returned variance matrix)

Value

a matrix

Author

Viviane Philipps

Examples

if (FALSE) { # \dontrun{
 ## The model
 m <- hlme(fixed = Y ~ Time, mixture = ~1, random = ~1, subject = "ID",
  ng = 2, cor = BM(Time), data = data_hlme, B = c(0,20,30,-1,5,2,0.1))

## The random effects' variance matrix (the variance of the random intercept )
B <- createVarianceMatrix(m, which = "random")

## The variance of the Brownian motion at time c(1, 2, 3, 4) 
W <- createVarianceMatrix(m, which = "cor", times1 = c(1, 2, 3, 4), times2 = c(1, 2, 3, 4))

## The variance of the measurement error at 4 visit times
S <- createVarianceMatrix(m, which = "error", nmes = 4)

## In model "m", the variance matrix of the outcome at times c(1, 2, 3, 4) is:
matrix(1, nrow = 4) %*% B %*% t(matrix(1, nrow = 4)) + W + S
} # }