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

时间:2015-05-26 12:48:19

标签: r lme4 lmer

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

>summary(fit0)

如果我使用save.image()保存对象,请关闭会话并再次重新打开,摘要告诉我:

>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()

重新启动并添加库lme4后:

> 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    
> 

0 个答案:

没有答案