Specifying correlation matrices in various data analysis packages for longitudinal data in R (e.g. geepack, nlme) can be quite confusing, especially if the model converges with its default correlation matrix and therefore subjecting your analysis to certain assumptions. Here are various ways you can specify a correlation matrix, depending on the package.
In geepack, you can use the variable “constr”:
gee.model <- geeglm(response ~ fixed, id = rand, data = yourData, family=gaussian, corstr="unstructured")
In nlme, it can be a little more complicated. You can start by specifying and initializing the matrix:
corMatrix <- corSymm(form = ~1|rand) corMatrix <- Initialize(matrix, data = yourData)
And then, you can assign the initialized matrix to your model. Note that there has to be a match between the formula in your matrix and the random effect structure.
lme.model <- lme(response ~ fixed, random = ~1|rand, data = yourData, correlation = corMatrix)
p.s. The R package “lmer” still, as of the writing of this post, does not support a custom correlation matrix.