[R] specify the covariance matrix for random effect
Ben Bolker
bbolker at gmail.com
Fri Sep 3 02:37:44 CEST 2010
Qiu, Weiyu <weiyu <at> ualberta.ca> writes:
>
> Hi,
>
> I'm doing a generalized linear mixed model, and I currently use an
> R function called "glmm". However, in
> this function they use a standard normal distribution for the random
> effect, which doesn't satisfy my
> case, i.e. my random effect also follows a normal distribution,
> but observations over time are somehow
> correlated, so the covariance matrix would be different the
> identity matrix. Besides, it's also
> different from the commonly used AR(1), AR(2) structures, so
> actually I need a way to write down the
> covariance matrix for the random effect in GLMM by myself.
>
If you could get by with an AR or ARMA structure then you could
use lme() with the 'correlation' argument from the nlme package.
If you have enough data/are willing to fit a completely unstructured
correlation matrix, you could use corSymm. See ?corStruct in
the nlme package documentation: it is *in principle* possible to
write functions to implement your own correlation structures, e.g.
see
corSymm
nlme:::corSymm.corMatrix
nlme:::coef.corNatural
However, this will not be easy unless you are already a good
R programmer and familiar with the nlme package. If you really
need to do this I definitely recommend that you buy and study
Pinheiro and Bates's 2000 book.
It might also be worth taking a look at the cor* objects in the
"ape" package, which are coded slightly more transparently.
Followups should probably go to r-sig-mixed-models at r-project.org
good luck
Ben Bolker
More information about the R-help
mailing list