我在那里。我在使用lmer函数时遇到了一些问题。我正在尝试在简单数据上进行测试,但没有得到我所期望的,但警告和错误。 这是示例
library(lme4)
library(lme4)
library(data.table)
library(ggplot2)
set.seed(115)
Nid = 20
Nx = 15
b <- 0
a <- 0.5
test <- data.table(ID = rep(LETTERS[1:Nid],each = Nx), X = rep(1:Nx,Nid))
test[,Y := rnorm(1,mean = b,sd = 1) + rnorm(1,mean = a,sd = 1*a)*X, by = ID]
这是一组Y的个体,它们具有随机的截距和X的斜率
fitnonmixte <- lm(Y~X,data = test)
summary(fitnonmixte)
fitmixte <- lmer(Y~X + (1 + X |ID),data = test,REML = T)
summary(fitmixte)
与lmer配合使用会给我一些我不明白的警告:
Warning messages:
1: In optwrap(optimizer, devfun, getStart(start, rho$lower, rho$pp), :
convergence code 3 from bobyqa: bobyqa -- a trust region step failed to reduce q
2: In checkConv(attr(opt, "derivs"), opt$par, ctrl = control$checkConv, :
unable to evaluate scaled gradient
3: In checkConv(attr(opt, "derivs"), opt$par, ctrl = control$checkConv, :
Model failed to converge: degenerate Hessian with 2 negative eigenvalues
并没有给出比简单回归更好的结果。增加个人人数似乎并没有改变行为。 当我想做的时候:
test <- data.table(ID = rep(LETTERS[1:Nid],each = Nx), X = rep(1:Nx,Nid))
test[,Y := rnorm(1,mean = b,sd = 2) + rnorm(1,mean = a,sd = 2*a)*X, by = ID]
fitmixte <- lmer(Y~X + (1 + X |ID),data = test,REML = T)
我得到:
Error in fn(x, ...) : Downdated VtV is not positive definite
我不明白... 后来我意识到,如果我向数据添加噪音
test <- data.table(ID = rep(LETTERS[1:Nid],each = Nx), X = rep(1:Nx,Nid))
test[,Y := rnorm(1,mean = b,sd = 2) + rnorm(1,mean = a,sd = 2*a)*X + rnorm(.N,mean = 0,sd = 1), by = ID]
一切正常。那么为什么lmer不能在没有噪音的数据上给出正确的结果呢?有办法避免这种行为吗?错误的含义是什么?
谢谢您的帮助!