Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/75.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/kotlin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R使用lmer给出:diag中的错误(vcov(对象,use.hessian=use.hessian))_R_Lme4_Lmer - Fatal编程技术网

R使用lmer给出:diag中的错误(vcov(对象,use.hessian=use.hessian))

R使用lmer给出:diag中的错误(vcov(对象,use.hessian=use.hessian)),r,lme4,lmer,R,Lme4,Lmer,当我使用lmer时,有一种奇怪的行为:当我使用lmer将拟合保存到一个对象中时,比如说fit0,使用lmer,我可以查看摘要(输出未显示): 如果我使用save.image()保存对象,请关闭会话并重新打开它,summary将为我提供: >summary(fit0) Error in diag(vcov(object, use.hessian = use.hessian)) error in evaluating the argument 'x' in selecting a meth

当我使用lmer时,有一种奇怪的行为:当我使用lmer将拟合保存到一个对象中时,比如说fit0,使用lmer,我可以查看摘要(输出未显示):

如果我使用save.image()保存对象,请关闭会话并重新打开它,summary将为我提供:

>summary(fit0)
Error in diag(vcov(object, use.hessian = use.hessian))
  error in evaluating the argument 'x' in selecting a method for function 'diag': Error in object@pp$unsc() : object 'merPredDunsc' not found
如果我再次运行该模型,我会得到预期的摘要,但如果我关闭会话,它将丢失。
会发生什么?如何避免这个错误

谢谢你的帮助


环境和版本:
Windows 7
R版本3.1.2(2014-10-31)
GNU Emacs 24.3.1(i386-mingw-nt6.1.7601)/ESS


下面是一个简单的例子:

# j: cluster
# i[j]: i in cluster j
# yi[j] = zi[j] + N(0,1)
# zi[j] = b0j + b1*xi[j]
# b0j = g0 + u0j, u0j ~ N(0,sd0)
# b1 = const

library(lme4)

# Number of clusters (level 2)
N   <- 20
# intercept
g0 <- 1
sd0 <- 2
# slope
b1  <- 3
# Number of observations (level 1) for cluster j
nj <- 10
# Vector of clusters indices 1,1...n1,2,2,2,....n2,...N,N,....nN
j <- c(sapply(1:N, function(x) rep(x, nj)))
# Vector of random variable
uj <- c(sapply(1:N, function(x)rep(rnorm(1,0,sd0), nj)))
# Vector of fixed variable
x1 <- rep(runif(nj),N)
# linear combination
z <- g0 + uj + b1*x1
# add error
y <- z + rnorm(N*nj,0,1)
# Put all together
d0 <- data.frame(j, y=y, z=z,x1=x1, uj=uj)
head(d0)

# mixed model
fit0 <- lmer(y ~ x1 + (1|j), data = d0)
vcov(fit0)
summary(fit0)

save.image()

重新启动R会话后,
sessionInfo()
说了什么?@alexforrence我在问题的末尾添加了会话信息。
# j: cluster
# i[j]: i in cluster j
# yi[j] = zi[j] + N(0,1)
# zi[j] = b0j + b1*xi[j]
# b0j = g0 + u0j, u0j ~ N(0,sd0)
# b1 = const

library(lme4)

# Number of clusters (level 2)
N   <- 20
# intercept
g0 <- 1
sd0 <- 2
# slope
b1  <- 3
# Number of observations (level 1) for cluster j
nj <- 10
# Vector of clusters indices 1,1...n1,2,2,2,....n2,...N,N,....nN
j <- c(sapply(1:N, function(x) rep(x, nj)))
# Vector of random variable
uj <- c(sapply(1:N, function(x)rep(rnorm(1,0,sd0), nj)))
# Vector of fixed variable
x1 <- rep(runif(nj),N)
# linear combination
z <- g0 + uj + b1*x1
# add error
y <- z + rnorm(N*nj,0,1)
# Put all together
d0 <- data.frame(j, y=y, z=z,x1=x1, uj=uj)
head(d0)

# mixed model
fit0 <- lmer(y ~ x1 + (1|j), data = d0)
vcov(fit0)
summary(fit0)

save.image()
> sessionInfo()
R version 3.1.2 (2014-10-31)
Platform: x86_64-w64-mingw32/x64 (64-bit)

locale:
[1] LC_COLLATE=German_Switzerland.1252  LC_CTYPE=German_Switzerland.1252   
[3] LC_MONETARY=German_Switzerland.1252 LC_NUMERIC=C                       
[5] LC_TIME=German_Switzerland.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] lme4_1.1-7     Rcpp_0.11.0    Matrix_1.1-2-2

loaded via a namespace (and not attached):
[1] compiler_3.1.2  grid_3.1.2      lattice_0.20-29 MASS_7.3-35    
[5] minqa_1.2.3     nlme_3.1-118    nloptr_1.0.4    splines_3.1.2  
[9] tools_3.1.2    
>