# lme4: random effects

I have a simulated data set of 4 repeated measurements (measure) for 5 subjects (subj), 20 trials (trl) each. I am trying to fit a model with random slopes for age category with subject and trials within subject as random effects and age category as fixed effect.

Here is the reproducible example:

set.seed(1)
# 20 trials 5 subjects 4 rep meas
age <- runif(400, min = 18, max = 60)
measure <- runif(400, min = 8, max = 14)
cat <- seq(1,4,1)
trl <- rep(seq(1,20,1),5)
sub <- c(rep(1,20),rep(2,20),rep(3,20),rep(4,20),rep(5,20))

data <- as.data.frame(cbind(measure, age, cat = rep(cat,100), trl = (rep(trl,4)),
sub = rep(sub,4)))
data[, 'cat'] <- as.factor(data[, 'cat'])
data[, 'sub'] <- as.factor(data[, 'sub'])
data[, 'trl'] <- as.factor(data[, 'trl'])

library(lme4)
model <- lmer(measure ~ cat-1 + (0+cat|sub) + (0+cat|sub/trl),data)

I get an error message as:

Error: number of observations (=400) <= number of random effects (=400)
for term (0 + cat | sub); the random-effects parameters and the residual
variance (or scale parameter) are probably unidentifiable

I expect to get 100 groups for subj/trl and 5 for subj and 400 observations. So I am confused regarding the error. I am trying to ascertain what went wrong with the model specification. Please help.

• I am not sure why this is off-topic. Can I not ask R questions in this forum?
– kaym
Mar 2, 2015 at 22:09
• I get your point about R v statistical question. However - if I add a reproducible example (I am assuming it means a simulated data and the associated code) it still remains the same question. Please clarify, how then will it be a valid question? I am trying to understand if I also need to change the question.
– kaym
Mar 2, 2015 at 23:09
– kaym
Mar 3, 2015 at 0:19
• Thanks, @kaym. I think this is answerable now. We should be able to migrate it for you. Mar 3, 2015 at 0:31
• That's one of the benefits of constructing a reproducible example ;-). Mar 3, 2015 at 1:15

What happens is that as we define the random slope due to cat| to have 4 measurements, we multiply our total number of (random) factors by 4, ie. the random structure we have now has 420 levels. Therefore the random effects design matrix $Z$ is of dimensions $400 \times 420$ and we are having an under-determined system. If one did not use trial (trl) information in the random effects structure (so he had a structure similar to (cat|sub)) the $Z$ matrix would be of dimensions $400 \times 20$ and the estimation procedure would be fine. :)
One can check this later statement by simply defining the associated model and checking the dimensions of $Z$ directly: