1

I am wishing to run a linear mixed model on a dependent variable DV that is collected under two different Condition at three different Timepoint. The data is structured as follows:

   ## dput(head(RawData,5))
    structure(list(Participant = structure(c(2L, 2L, 2L, 2L, 4L), 
  .Label = c("Jessie", "James", "Gus", "Hudson", "Flossy", 
 "Bobby", "Thomas", "Alfie", "Charles", "Will", "Mat", "Paul", "Tim", 
  "John", "Toby", "Blair"), class = "factor"), 
 xVarCondition = c(1, 1, 0, 0, 1), 
 Measure = structure(c(1L, 2L, 3L, 4L, 1L), 
.Label = c("1", "2", "3", "4", "5", "6", "7", "8", 
"9", "10", "11", "12"), class = "factor"), 
Sample = structure(c(1L, 2L, 1L, 2L, 1L), 
.Label = c("1", "2"), class = "factor"), 
 Condition = structure(c(2L, 2L, 1L, 1L, 2L),
 .Label = c("AM", "PM"), class = "factor"),
 Timepoint = structure(c(2L, 2L, 2L, 2L, 1L), 
.Label = c("Baseline", "Mid", "Post"), class = "factor"),
 DV = c(83.6381348645853, 86.9813802115179, 69.2691666620429, 
 71.3949807856125, 87.8931998204771)), 
.Names = c("Participant", "xVarCondition", "Measure", 
   "Sample", "Condition", "Timepoint", "DV"), 
 row.names = c(NA, 5L), class = "data.frame")

Each Participant performs two trials per Condition across three Timepoints as depicted by Measure; however, there are missing data so not necessarily 12 levels per participant. The column xVarCondition is simply a dummy variable that includes a 1 for each entry of AM in Condition. The column Sample refers to the 2 trials for each Condition at each Timepoint.

I am an R user but the statistician is a SAS user who believes the code for the model should be:

proc mixed data=RawData covtest cl alpha=α
class Participant Condition Timepoint Measure Sample;
model &dep=Condition Timepoint/s ddfm=sat outp=pred residual noint;
random int xVarCondition xVarCondition*TimePoint*Sample 
          TimePoint/subject=Participant s;

The above SAS code gives sensible answers and is working perfectly. We believe the resulting lme4 syntax for the above model to be:

TestModel = lmer(DV ~ Condition + Timepoint + 
              (1 | Participant/Timepoint) +
              (0 + xVarCondition | Participant) +
              (1 | Participant:xVarCondition:Measure), data = RawData)

However, I get the following error when running this model:

Error: number of levels of each grouping factor must be < number of observations

Are the random effects specified correctly?

user2716568
  • 1,866
  • 3
  • 23
  • 38
  • I'd noticed that both your fixed effects, `Condition` and `Timepoint`, are both factors. Are you sure that a mixed linear model is the best approach in this case? Also, I don't get the difference between `xVarCondition` and `Condition`. – Adam Quek Jun 16 '16 at 02:07
  • I believe a linear mixed model is appropriate as we are interested in within and between participant variation. xVarCondition is simply a dummy variable with a 1 for each time a participant completes the AM condition. – user2716568 Jun 16 '16 at 02:15

1 Answers1

1

I can't quite tell from your description, but most likely your Participant:xVarCondition:Measure term constructs a grouping variable that has no more than one more observation in each level of classification, which will make the (1|Participant:xVarCondition:Measure) term redundant with the residual error term which is always included in an lmer model. You can override the error if you really want to by including

control=lmerControl(check.nobs.vs.nlev = "ignore")

in your function call, but (if I've diagnosed the problem correctly) this will lead to the residual variance and the Participant:xVarCondition:Measure variance being jointly unidentifiable. Such unidentifiability usually doesn't cause any problems with the rest of the model, but I am more comfortable with an identifiable model (there's always the possibility that such unidentifiability will lead to numerical issues).

There's a similar example here.

You can check my conjecture as follows:

ifac <- with(RawData,
   interaction(Participant,xVarCondition,Measure,drop=TRUE))
length(levels(ifac)) == nrow(RawData)
Ben Bolker
  • 211,554
  • 25
  • 370
  • 453
  • Thank you for the similar example however, even when I try to override the error I still receive the error message. Am I able to specify the random effects so it matches the model in SAS? It is running smoothly in SAS with sensible answers. – user2716568 Jun 16 '16 at 06:28
  • you might try r-sig-mixed-models@r-project.org (I may not have time for this today). A [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) would also be helpful – Ben Bolker Jun 16 '16 at 10:24