首页 文章

在混合模型中运行Summary()后出现Colnames错误

提问于
浏览
0
R version 3.1.0 (2014-04-10)
lmer package version 1.1-6
lmerTest package version 2.0-6

我目前正在使用lmer和lmerTest进行分析 . 每次我向随机结构添加效果时,运行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

如果我离开这样的结构:

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

没有错误运行摘要(TRT5ToVerb.lmer2),返回AIC,BIC,logLik偏差,随机效应的估计,固定效应的估计及其相应的p值等等 .

所以,当我运行lmerTest时,显然会发生一些事情,尽管TRT5ToVerb.lmer3对象就在那里 . 两者之间的唯一区别是随机结构:(1条件|参与者)与(1 |参与者)

我的数据的一些特征:

  • 条件和组都是分类变量:条件包含3个级别,第2组

  • 因变量(TRT5ToVerb)是连续的:它对应于以ms为单位的读取时间

  • 这是一项重复测量实验,每位参与者有48次观察(参与者= 28次)

我读了this threat,但我看不出明确的解决方案 . 我必须将我的数据帧转换为长格式吗?如果是这样,那么我如何在lmer中使用它呢?我希望不是那样的 .

谢谢!

免责声明:我既不是R的专家,也不是统计学的专家,所以请耐心等待 .

1 回答

  • 0

    (应该是评论,但是太长/代码格式化等)

    这个假的例子似乎与lmerTest 2.0-6和lme4的开发版本(1.1-8;但我不希望在这个例子中与1.1-6有任何相关的差异......)工作正常

    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)
    

    生产环境 :

    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
    

相关问题