I'm doing a mixed linear model. And I have subjects who have been select in 20 schools. So I want to take this to account.

For this, I want to put a random intercept for the "SCHOOL" variable and a random intercept and slope for my "SUBJECT". But I want to take into account the nested effect.

Does this code fit the nested model:

 lme(Y ~ T + X, random = list(SCHOOL = ~ 1, SUBJECT = ~ T), method = "ML")

T is the time, and Y the outcome.


2 Answers 2


This code specifies that SUBJECT is nested within SCHOOL, and that for SCHOOL you have random intercepts, and for SUBJECT random intercepts and random slopes.

You could also fit the model with restricted maximum likelihood that provides better estimates for the variance components in small samples.

  • $\begingroup$ Thanks for your answer. I assume it's correct so. Small samples correspond to an effective of less of 100 ? My sample is constituate of about 600 subjects ... $\endgroup$
    – Lemon3
    Apr 11, 2019 at 19:24

I'm not sure how to do it in package NLME, but with LME4 you could do it with:

lmer(y ~ t + x + (1 + T|SUBJECT:SCHOOL), REML = FALSE)

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.