0
R version 3.1.0 (2014-04-10)
lmer package version 1.1-6
lmerTest package version 2.0-6

I am currently working with lmer and lmerTest for my analysis. Every time I add an effect to the random structure, I get the following error when running summary():

#Fitting a mixed model: 
TRT5ToVerb.lmer3 = lmer(TRT5ToVerb ~ Group + Condition + (1+Condition|Participant) + (1|Trial), data=AllData, REML=FALSE, na.action=na.omit)
summary(TRT5ToVerb.lmer3)
 Error in `colnames<-`(`*tmp*`, value = c("Estimate", "Std. Error", "df",  : length of 'dimnames' [2] not equal to array extent

If I leave the structure like this:

TRT5ToVerb.lmer2 = lmer(TRT5ToVerb ~ Group + Condition + (1|Participant) + (1|Trial),  data=AllData, REML=FALSE, na.action=na.omit)

there is no error run summary(TRT5ToVerb.lmer2), returning AIC, BIC, logLik deviance, estimates of the random effects, estimates of the fixed effects and their corresponding p-values, etc., etc.

So, apparently something happens when I run lmerTest, despite the fact that the object TRT5ToVerb.lmer3 is there. The only difference between both is the random structure: (1+Condition|Participant) vs. (1|Participant)

Some characteristics of my data:

  1. Both Condition and Group are categorical variables: Condition comprises 3 levels, and Group 2
  2. The dependent variable (TRT5ToVerb) is continuous: it corresponds to reading time in terms of ms
  3. This a repeated measures experiment, with 48 observations per participant (participants=28)

I read this threat, but I cannot see a clear solution. Will it be that I have to transform my dataframe to long format? And if so, then how do I work with that in lmer? I hope it is not that.

Thanks!

Disclaimer: I am neither an expert in R, nor in statistics, so please, have some patience.

Community
  • 1
  • 1
Nalerive
  • 113
  • 6
  • Please consider including a *small* [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) so we can better understand and more easily answer your question. – Ben Bolker Jul 14 '14 at 14:54
  • It would be easier to help if you could edit your question to be a self-contained [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). Include some same data so that we can run the same model and get the same error. That link has tips on how to do just that. – MrFlick Jul 14 '14 at 14:56
  • I have a data frame with only those variables, but I'm afraid I cannot create a small reproducible example because, I think, there will be no enough data, and other problems will show up. – Nalerive Jul 14 '14 at 16:13

1 Answers1

0

(Should be a comment, but too long/code formatting etc.)

This fake example seems to work fine with lmerTest 2.0-6 and a development version of lme4 (1.1-8; but I wouldn't expect there to be any relevant differences from 1.1-6 for this example ...)

AllData <- expand.grid(Condition=factor(1:3),Group=factor(1:2),
                  Participant=1:28,Trial=1:8)
form <- TRT5ToVerb ~ Group + Condition + (1+Condition|Participant) + (1|Trial)
library(lme4)
set.seed(101)
AllData$TRT5ToVerb <- simulate(form[-2],
               newdata=AllData,
               family=gaussian,
               newparam=list(theta=rep(1,7),sigma=1,beta=rep(0,4)))[[1]]
library(lmerTest)
lmer3 <- lmer(form,data=AllData,REML=FALSE)
summary(lmer3)

Produces:

Linear mixed model fit by maximum likelihood  ['merModLmerTest']
Formula: TRT5ToVerb ~ Group + Condition + (1 + Condition | Participant) +  
    (1 | Trial)
   Data: AllData

     AIC      BIC   logLik deviance df.resid 
  4073.6   4136.0  -2024.8   4049.6     1332 

Scaled residuals: 
     Min       1Q   Median       3Q      Max 
-2.97773 -0.65923  0.02319  0.66454  2.98854 

Random effects:
 Groups      Name        Variance Std.Dev. Corr     
 Participant (Intercept) 0.8546   0.9245            
             Condition2  1.3596   1.1660   0.58     
             Condition3  3.3558   1.8319   0.44 0.82
 Trial       (Intercept) 0.9978   0.9989            
 Residual                0.9662   0.9829            
Number of obs: 1344, groups:  Participant, 28; Trial, 8

Fixed effects:
              Estimate Std. Error         df t value Pr(>|t|)
(Intercept)    0.49867    0.39764   12.40000   1.254    0.233
Group2         0.03002    0.05362 1252.90000   0.560    0.576
Condition2    -0.03777    0.22994   28.00000  -0.164    0.871
Condition3    -0.27796    0.35237   28.00000  -0.789    0.437

Correlation of Fixed Effects:
           (Intr) Group2 Cndtn2
Group2     -0.067              
Condition2  0.220  0.000       
Condition3  0.172  0.000  0.794
Ben Bolker
  • 211,554
  • 25
  • 370
  • 453
  • update: I updated lme4 1.1-6 to 1.1-7 (I don't get the option to update to 1.1-8). It didn't work. – Nalerive Jul 15 '14 at 08:38
  • Hi Ben: I noticed you set Trial as Trial=1:8, and it should be 1 to 48. Would that make a difference? (I don't think so, but...) I run it, but then I checked the dataframe that your code created, and it's not similar to what I have: participants only can be in one group at the time (I should have clarified that), so 13 in one group, and 15 in the other. – Nalerive Jul 15 '14 at 08:54
  • can you start from my example and figure out enough about how it works to construct a version that does match your data more closely? If you can, and it works, then you've established that there's something more particular about your data, and you'll probably have to post it somewhere in order to get useful feedback. – Ben Bolker Jul 16 '14 at 18:07