I am trying to include a random slope of time for two random factors in my lmer model. My research design has four experimental groups who attended five tests at five time points. I would like to compare the effects of the different treatment types assigned to the four groups (between-subject independent variable) on subjects' test scores (dependent variable) along the five testing points (within-subject independent variable). Two fixed factors (group and time) which are the independent variables are included in the model. In order to control the random influence of subject and class, I also include these two factors in the random effect structure with random intercepts. Because "time" is a within-subject variable, I tried to include it as a random slope for the two random factors.

However, I got this error message:Error: number of observations (=631) <= number of random effects (=675) for term (0 + Time | subject); the random-effects parameters and the residual variance (or scale parameter) are probably unidentifiable

My R syntax is


Group, time, subject and class are all defined as factors in the model.Time is not coded as a continuous variable because I would like to know the group differences at each time point and "time" is not expected to have linear positive influence on the dependent variable which is the test score.

My questions are:

(1) Is it reasonable to include time as a random slope in the model as long as it is coded as a categorical variable?

(2) Does the error mean I do not have enough observations to run this model?

I searched this question online and found contradictory comments regarding similar issues. While someone said categorical variable cannot be included as a random slope, someone said dummy coding would help. Can someone here give me some suggestions? Your input will be highly appreciated.

  • 1
    $\begingroup$ You have 631 observations but how Many subjects do you have? How many t for Zach subject? $\endgroup$ – user83346 Oct 3 '17 at 4:28
  • $\begingroup$ How many lines do you have per subject/class combination? It must be larger than 1. $\endgroup$ – Michael M Oct 3 '17 at 6:13
  • $\begingroup$ @fcop There are 135 subjects. Each subject has five rows, one for each test point. There are some missing data (observations) in my data set. If there is no missing data, there should be 675 observations (135*5=675). Is it because of the missing data that R cannot run this model? $\endgroup$ – Summer Fu Oct 3 '17 at 20:49
  • $\begingroup$ @MichaelM I have five lines for each subject/class combination, but there are some missing data (observations). I think the lmer() model is fine with missing data but not sure if the missing data caused the problem in my case. $\endgroup$ – Summer Fu Oct 3 '17 at 20:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.