0

当我使用 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 version 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    
> 
4

0 回答 0