[R-sig-ME] Incorporating spatial correlation matrix into lmer?

Douglas Bates bates at stat.wisc.edu
Tue Feb 22 17:44:09 CET 2011

```Thank you for your question, Rachel.

As we agreed in a separate email exchange, I am copying the
R-SIG-Mixed-Models email list on my reply.

On Mon, Feb 21, 2011 at 4:44 PM, Rachelle K. Gould <rgould at stanford.edu> wrote:
> Dear Dr. Bates,

> I’m writing with a question about the lmer function in R. I have hesitated
> for weeks, because I sincerely don’t want to bother you – but I’m at my
> wits/Google’s end, and I think you’ll be able to answer this question in
> about sixty seconds – so, I’m writing you!

> I’m interested in running a GLMM, and including, as a random effect, a
> matrix of the spatial correlation structure between my sampling points (very
> simple; based on the lat and long coordinates of each point). It seems that
> this is a reasonable type of data to include in a GLMM; however, it also
> looks like there is no R code developed to do this.

Not directly, no.  I feel that this type of model has to be approached
very carefully, especially in a GLMM.  I'll try to explain why I think
this but I apologize in advance that the explanation may get rather
technical.

In a linear mixed model it is possible to model the
variance-covariance structure of the conditional distribution of the
response, given the random effects, separately from the mean.  This is
because the conditional distribution is Gaussian (or "normal") and you
can manipulate either the mean or the variance of a Gaussian
distribution without affecting the other.

You didn't specify what distribution family you would have in your
GLMM but I'll assume it would be the binomial or the Poisson family.
On both of those cases the conditional variance is determined by the
conditional mean.  Although one can incorporate spatial correlation
into the computational method, which is based on iteratively
reweighted least squares calculations, the spatial correlation cannot
be part of the original model for the conditional distribution.

One approach that can be used is to incorporate random effects, which
do have a Gaussian distribution in the models fit by lmer or glmer,
that have the spatial correlation in their distribution.  At present
this model is not fit directly by glmer but as a one-off calculation
it may be possible to do this in the development version of the lme4
package.  It would depend to some extent on whether you or someone
else with the interest and reasonably good R programing skills would
want to undertake the work.  I could describe how to do it but
probably would not have time to do development myself.

>
>
> Am I wrong? Is there code to do this? I’ve searched around on lmer and
> glmmPQL (which I know isn’t as accurate) websites, and a bit on glmmML
> websites too. Can’t find anything! Any aid you can give will be much, much
> appreciated.
>
>
>
> PS – I’ve heard a rumor that SAS can do this pretty easily. Do you know
>
>
>
> Thank you so much, in advance! Thank you for all of your impressive work on
> R, and I’m sorry to resort to emailing you.
>
>
>
> Rachelle Gould
>
>
>
> Rachelle Gould  |  PhD Candidate
>
> Stanford University | Interdisciplinary Program in Environment and Resources
>
> 805.276.0995
>
>

```