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.