为什么这个简单的混合模型无法收敛?

时间:2019-02-05 21:37:36

标签: r lme4 mixed-models

我拥有以下数据,我想比较第28天和第83天之间value变量的平均值:

library(lme4)
#> Loading required package: Matrix
library(lmerTest)
#> 
#> Attaching package: 'lmerTest'
#> The following object is masked from 'package:lme4':
#> 
#>     lmer
#> The following object is masked from 'package:stats':
#> 
#>     step

df <- structure(list(experience_sep = c(
  "DM", "DA", "DM", "DA", "DM",
  "DA"
), day = c(55, 110, 55, 110, 55, 110), day_factor = c(
  55,
  110, 55, 110, 55, 110
), day_julian = c(
  55, 110, 55, 110, 55,
  110
), day_true = c(28, 83, 28, 83, 28, 83), culture = c(
  1L, 1L,
  2L, 2L, 3L, 3L
), value = c(
  758453.333333333, 575133.333333333,
  684160, 656933.333333333, 816840, 734700
)), row.names = c(
  NA,
  -6L
), class = c("data.frame"))


df  
#>   experience_sep day day_factor day_julian day_true culture    value
#> 1             DM  55         55         55       28       1 758453.3
#> 2             DA 110        110        110       83       1 575133.3
#> 3             DM  55         55         55       28       2 684160.0
#> 4             DA 110        110        110       83       2 656933.3
#> 5             DM  55         55         55       28       3 816840.0
#> 6             DA 110        110        110       83       3 734700.0

由于经验涉及伪复制(culture),因此我考虑使用如下混合模型:

lmerTest::lmer(value ~ factor(day_true) + (1|culture), data = df)
#> Warning in as_lmerModLT(model, devfun): Model may not have converged with 1
#> eigenvalue close to zero: 2.6e-09
#> Linear mixed model fit by REML ['lmerModLmerTest']
#> Formula: value ~ factor(day_true) + (1 | culture)
#>    Data: df
#> REML criterion at convergence: 102.7974
#> Random effects:
#>  Groups   Name        Std.Dev.
#>  culture  (Intercept) 47535   
#>  Residual             55990   
#> Number of obs: 6, groups:  culture, 3
#> Fixed Effects:
#>        (Intercept)  factor(day_true)83  
#>             753151              -97562

但是,我遇到此错误,但找不到该问题。是因为我的积分很少(每组n = 3)吗?

reprex package(v0.2.1)于2019-02-05创建

1 个答案:

答案 0 :(得分:1)

我知道我参加这个聚会有点晚了,但是我在标准化响应变量(值)之后运行了该模型,并且效果很好。当模型中的变量比其他变量大几个数量级时,可能会导致数值问题。这是代码。

df$value.st<-(df$value-mean(df$value))/(sd(df$value))

mod<-lmer(value.st ~ factor(day_true) + (1|culture), data=df)

mod
Linear mixed model fit by REML ['lmerMod']
Formula: value.st ~ factor(day_true) + (1 | culture)
   Data: df
REML criterion at convergence: 12.0241
Random effects:
 Groups   Name        Std.Dev.
 culture  (Intercept) 0.5613  
 Residual             0.6612  
Number of obs: 6, groups:  culture, 3
Fixed Effects:
       (Intercept)  factor(day_true)83  
            0.5761             -1.1521 

祝你好运!