来自混合模型的新数据 simulate.merMod 出错

Errors with simulate.merMod with new data from mixed model

我正在尝试从 lme4 中的 glmer 模型 simulate。我正在尝试通过 newdata,但遇到各种格式的不同错误。可能只是不理解函数需要什么格式,但包示例也会产生错误。

包数据示例:

# Mixed model
gm1 <- glmer(cbind(incidence, size - incidence) ~ period + (1 | herd),
              data = cbpp, family = binomial)

# Generate new data as per example
newdata <- with(cbpp, expand.grid(period=unique(period), herd=unique(herd)))

# Predict works as expected
predict(gm1, newdata=newdata)                # works
predict(gm1, newdata=newdata[1,])            # works

# Simulate generates different errors
simulate(gm1, newdata=newdata)               # works with error, but probably fine.
# Warning message:
#   In wts - Y :
#   longer object length is not a multiple of shorter object length


simulate(gm1, newdata=newdata[1,])           # doesn't work
# Error in data.frame(sim_1 = c(" 4", "10"), check.names = FALSE, row.names = "1") : 
# 'row.names' should specify one of the variables
# In addition: Warning message:
#   In format.data.frame(x, digits = digits, na.encode = FALSE) :
#   corrupt data frame: columns will be truncated or padded with NAs

newdata2 = data.frame(
  herd=c("1"),
  period=c("1")
)
simulate(gm1, newdata=newdata2)              # same error

simulate(gm1, newdata=newdata[1:2,])         # works but with error
# Warning message:
#   In format.data.frame(x, digits = digits, na.encode = FALSE) :
#   corrupt data frame: columns will be truncated or padded with NAs

R version 3.2.1 (2015-06-18)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 14.04.1 LTS

other attached packages:
 [1] ggplot2_1.0.0   Zelig_3.5.4     boot_1.3-9      MASS_7.3-29     Hmisc_3.14-5   
 [6] Formula_1.1-2   survival_2.37-7 lattice_0.20-29 plyr_1.8.1      RCurl_1.95-4.3 
[11] bitops_1.0-6    lme4_1.1-10     Matrix_1.1-2   

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.1         cluster_1.14.4      munsell_0.4.2       colorspace_1.2-4   
 [5] minqa_1.2.4         stringr_0.6.2       tools_3.2.1         nnet_7.3-7         
 [9] MatchIt_2.4-21      gtable_0.1.2        nlme_3.1-113        latticeExtra_0.6-26
[13] digest_0.6.4        reshape2_1.4        RColorBrewer_1.0-5  nloptr_1.0.4       
[17] acepack_1.3-3.3     rpart_4.1-5         labeling_0.3        scales_0.2.4       
[21] foreign_0.8-59      proto_0.3-10    

现在是 fixed 开发版本 lme4。非常感谢本博尔克。

devtools::install_github("lme4/lme4")