I was working in R packages nlme and lme4, trying to specify the models with multiple random effects. I found, that only nlme allows to specify the heterogeneous structure of the variance. Therefore, I got a model, where temperature (Y) depends on time (in hours), intercept varies by date and year, and variance also varies by year:

fit1 <- lme(Y ~ time, random=~1|year/date, data=X, weights=varIdent(form=~1|year))

However, if I need to add another random term (time varying by date), and specify the model like this:

fit2 <- lme(Y ~ time, random=list(~1|year, ~time-1|date,  ~1|date), data=X, 

the random effects become nested in each other: date in year; and then date in date and in year.

I also tried

one  <- rep(1, length(Y))
fit3 <- lme(Y ~ time, random=list(one=pdBlocked(list(pdSymm(~1|year/date), 
            pdSymm(~time-1|year)))), data=X, weights=varIdent(form=~1|year))

but it gives an error:

Error in pdConstruct.pdBlocked(object, form = form, nam = nam, data = data,  :
  cannot have duplicated column names in a "pdMat" object

I understand that there have been already many questions related to the similar problem, but I really did not find the answer for my case. Could you help me with the right specification of the model?


1 Answer 1


After many struggles I found a solution for my problem, which I am posting here in case somebody will have similar questions:

fit <- lme(Y ~ time, random=list(year=~1, date=~time), data=X, weights=varIdent(form=~1|year))
  • $\begingroup$ You saved my day. Thanks, Slava. $\endgroup$ Commented May 12, 2021 at 23:17

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