4
$\begingroup$

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.

$\endgroup$
6
  • $\begingroup$ I am not sure why this is off-topic. Can I not ask R questions in this forum? $\endgroup$
    – kaym
    Commented Mar 2, 2015 at 22:09
  • $\begingroup$ 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. $\endgroup$
    – kaym
    Commented Mar 2, 2015 at 23:09
  • 1
    $\begingroup$ thanks for your comments. I have added a simulated example. Hope that explains the question adequately. $\endgroup$
    – kaym
    Commented Mar 3, 2015 at 0:19
  • $\begingroup$ Thanks, @kaym. I think this is answerable now. We should be able to migrate it for you. $\endgroup$ Commented Mar 3, 2015 at 0:31
  • 3
    $\begingroup$ That's one of the benefits of constructing a reproducible example ;-). $\endgroup$ Commented Mar 3, 2015 at 1:15

1 Answer 1

4
$\begingroup$

While the question appears solved by the OP, I will post the answer for future reference.

The answer is (as suspected) in the error message but the error message itself points to the wrong random structure. The root cause of this message is the number of random factors defined by the structure (cat|sub/trl).

If we simply had the structure (1|sub/trl) we would use the 20 trials and 5 subjects. We would then expect 100 levels due to the interaction sub:trl plus 5 levels due to sub for a total of 105 factors (random intercepts actually). This would be almost fine given one has 400 sample points.

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:

  model <-  model <- lmer(measure ~ 1 + (cat|sub),data)
  dim(t(model@pp$Zt)) # [1] 400  20 
$\endgroup$

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.