My goal is to specify two different covariance matrices for two different random intercepts.

Briefly, this is my dataset.

Outcome is continuous (school test scores)

13 Schools in my study. Random students selected for testing. All students who were selected were tested. Students nested within Schools.

I am interested in estimating the random intercept for each School and each Student.

So this is my model.

lme( y ~ SchoolName + Age + Sex, random = ~1 | SchoolName/StudentID, data= df)

I am interested in

  • Schools following unstructured covariance matrix
  • Students , ar1.

I have another variable time, which is a discreate variable that takes values either 10,11,12,13 . So I specified the model like this

`lme( y ~ SchoolName + Age + Sex, 
     random = ~1 | SchoolName/StudentID, 
     correlation = corAR1(form = ~1 | time/StudentID,
 data= df)`

I am seeing an error, "Incompatible formulas in random and correlation", How to resolve this error. Please help.

  • $\begingroup$ Do you have two or more measurements of each student? $\endgroup$
    – BenP
    Commented Apr 5 at 6:03
  • $\begingroup$ In my understanding, in lme you can only specify correlation structures for the exact random effects that are in the model. So you could only specify a correlation structure to the ~1|SchoolName/StudentID term. $\endgroup$
    – Sointu
    Commented Apr 5 at 7:34
  • $\begingroup$ @BenP, Yes, 40% of the students have more than one observation. $\endgroup$
    – Science11
    Commented Apr 5 at 14:53

1 Answer 1


Sointu is right. But it seems that it is possible to use something like this, where I use an example of my own:

HAR <- lme(read ~ 1+occf, data=da, random= ~1|school, 
           correlation=corAR1(form = ~ occasion |school/id),
           weights = varIdent(form = ~1|occasion))

This way you get a random intercept across schools, and a heterogeneous AR1 structure across time points (occasion) within student id.

But you say you'd like an unstructured covariance matrix across schools. The above would give a compound symmetry structure. I cannot easily understand why you would like an unstructured pattern for schools. Suppose you have maximally 20 students in a school. Then the unstructured pattern would try to estimate 1/22021=210 (co)variances. That would be very hard to estimate. Also, there is no logical order for the students in a school, they are exchangeable I guess, and thus the compound symmetry structure seems more plausible.

  • $\begingroup$ Ben I followed this approach and I get an error that says Error in Initialize.corAR1(X[[i]],...) : covariate must have unique values within groups for "corAR1" objects $\endgroup$
    – Science11
    Commented Apr 5 at 15:56
  • $\begingroup$ I'm not sure. Sounds as if for one or more "id" the "occasion" variable is not unique, like having observed a person twice at the same time point. Did you check that? $\endgroup$
    – BenP
    Commented Apr 5 at 16:06
  • $\begingroup$ good point Ben, that is a possibility. Some students are tested more than once, twice, during age 10 for example $\endgroup$
    – Science11
    Commented Apr 5 at 19:51
  • 1
    $\begingroup$ Maybe you can combine the two values somehow into one new value. $\endgroup$
    – BenP
    Commented Apr 5 at 20:20
  • 1
    $\begingroup$ That is the compound symmetry structure e.g. for "random = ~1 | school". $\endgroup$
    – BenP
    Commented Apr 6 at 7:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.